- write tests (see tests' structure);
- implement necessary feature in the library;
- run MyPy, PyLint and test (see about running MyPy, PyLint and tests);
- commit changes;
- push commit.
For example, you are implementing the get_comment
method.
- add file
test_get_answer.py
to directorytests/test_client
; - 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()
- then, there should be the following methods:
test_get_answers_without_ids_url
- tests that methodget_answers
without transmitting identifiers to it applies to the desired URL;test_get_answers_with_ids_url
- tests that methodget_answers
with transmitting some identifiers to it applies to the desired URL;test_get_answers_return_value
- tests that methodget_answers
returns desired list of classItem
's instances (desired is[Item({'id': 1})]
);test_get_answer_url
- tests that methodget_answer
applies to the desired URL;test_get_answer_return_value
- tests that methodget_answer
returns desired instance of classItem
(desired isItem({'id': 1})
);test_get_answer_with_no_data
- tests that methodget_answer
returnsNone
when the'items'
key of response is empty list.
For more details, see file tests/test_client/test_get_answers.py
.
- In first, install requirements of library from file
requirements.txt
:pystackapi$ pip install -r ./requirements.txt
- 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
- Run MyPy:
pystackapi$ python -m mypy ./src/
- Run PyLint:
pystackapi$ python -m pylint ./src/
- 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