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 lintor
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 testor
python -m unittest discover -b -v -s test/unitYou 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-patternOr if you see a test failure and you need to quickly run that one test case,
you can make use of the wrapper script test/unit/runtest.sh:
./test/unit/runtest.sh test_sap_cli_gcts.TestgCTSRepoMessagesWhere test_sap_cli_gcts refers to test/unit/test_sap_cli_gcts.py
and TestgCTSRepoMessages is a test class.
- Check code coverage - run either
make report-coverageor
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).