Skip to content

Latest commit

 

History

History
79 lines (62 loc) · 3.14 KB

CONTRIBUTING.md

File metadata and controls

79 lines (62 loc) · 3.14 KB

PyStackAPI developers' guide

  1. write tests (see tests' structure);
  2. implement necessary feature in the library;
  3. run MyPy, PyLint and test (see about running MyPy, PyLint and tests);
  4. commit changes;
  5. push commit.

For example, you are implementing the get_comment method.

  1. add file test_get_answer.py to directory tests/test_client;
  2. at the beginning of it there should be this code:
    """Tests for `Site.get_answers` and `Site.get_answer`."""
    import lest
    
    from pystackapi import site as site_m
    from pystackapi.item import Item
    
    from . import API_VERSION, requests
    
    site_m.__dict__['requests'] = requests
    site = site_m.Site('stackoverflow')
    
    
    @lest.setup
    def reset_requests() -> None:
        requests.reset()
  3. then, there should be the following methods:
    • test_get_answers_without_ids_url - tests that method get_answers without transmitting identifiers to it applies to the desired URL;
    • test_get_answers_with_ids_url - tests that method get_answers with transmitting some identifiers to it applies to the desired URL;
    • test_get_answers_return_value - tests that method get_answers returns desired list of class Item's instances (desired is [Item({'id': 1})]);
    • test_get_answer_url - tests that method get_answer applies to the desired URL;
    • test_get_answer_return_value - tests that method get_answer returns desired instance of class Item (desired is Item({'id': 1}));
    • test_get_answer_with_no_data - tests that method get_answer returns None when the 'items' key of response is empty list.

For more details, see file tests/test_client/test_get_answers.py.


  1. In first, install requirements of library from file requirements.txt:
    pystackapi$ pip install -r ./requirements.txt
  2. Then, install all developer's requirements:
    pystackapi$ pip install -r ./dev_requirements/mypy_requirements.txt
    pystackapi$ pip install -r ./dev_requirements/pylint_requirements.txt
    pystackapi$ pip install -r ./dev_requirements/tests_requirements.txt
  3. Run MyPy:
    pystackapi$ python -m mypy ./src/
  4. Run PyLint:
    pystackapi$ python -m pylint ./src/
  5. Run tests:
    pystackapi$ cd tests
    pystackapi/tests$ python main.py

Note: if you already installed all requirements, you can run MyPy, PyLint and tests by command

pystackapi$ python -m mypy ./src/; python -m pylint ./src/; cd tests; python main.py