Start with extending API functionality and use it in your CLI commands - IOW do not put too much logic into the CLI commands.
-
you need pylint and flake8 which makes sure you follow coding style
-
you might consider installing GNU/make which is used to simplify developers workflow - there is Makefile including the steps for checking code style and running tests
-
tests are written in python.unittest to avoid unnecessary dependencies and are stored in the directory test/
-
all development dependencies are tracked in the file dev-requirements.txt and can be installed with the following command
pip install -r dev-requirements.txt
-
Do your changes
-
Run linters - either
make lint
or
pylint --rcfile=.pylintrc sap
PYTHONPATH=$(pwd):$PYTHONPATH pylint --rcfile=.pylintrc bin/sapcli
flake8 --config=.flake8 sap
PYTHONPATH=$(pwd):$PYTHONPATH flake8 --config=.flake8 bin/sapcli
- Run tests - either
make test
or
python -m unittest discover -b -v -s test/unit
You can also test subset (or single test case) by providing test case name pattern:
python -m unittest discover -b -v -s test/unit -k test-name-pattern
- Check code coverage - run either
make report-coverage
or
coverage run -m unittest discover -b -v -s test/unit
coverage report bin/sapcli $(find sap -type f -name '*.py')
You can also use html
instead of run
which will create
the report at the path SOURCE_CODE_DIR/htmlcov/index.html
.
(Of course, the convenience make target exists - report-coverage-html
).