ONSdigital / sml-python-small

Statistical Methods Library for Python Pandas methods used in SPP.
MIT License
10 stars 5 forks source link

SML-PYTHON-SMALL

Statistical Methods Library for Python Pandas methods used in the Statistical Production Platform (SPP).

This library contains pandas statistical methods that are only suitable for use on small datasets which can safely be processed in-memory.

For further information about the methods contained in this module see the method specifications

For user documentation and example data relating to the methods in this module see the supporting information

Automated testing

In order to ensure code quality, there is a manual test script provided run_py_tools.sh which will run linting, code formatting checks, and the pytest suite.

It is often easy to forget to check code formatting before pushing to the remote repository, so there is the option of running the testing script automatically by using the git hook pre-push. This means that when git push is run, the test script will be run first, and will abort the push if any of the tests fail.

Git hooks cannot be pushed to the remote repository so if you would like this script to be run automatically you will need to follow these steps:

git stash clear # in case there is nothing to stash,

then the stash needs to be empty, else previously

stashed changes will be incorrectly restored

git stash testing_script="./run_py_tools.sh"

if "$testing_script"; then echo "${GREEN}./run_py_tools script passes, proceeding with push...${NC}" git add . # commit any changes made by the pytools script git commit -m "run_py_tools auto-formatting" git stash apply echo "${YELLOW}NOTE: If any commits were made by the auto-formatting tool, then they will not be automatically pushed. You will need to run git push again (or git push --no-verify if you don't want to run the test suite again).${NC}"

uncomment the line below if you would like the commits to be pushed automatically.

# git push --no-verify # NOTE: this will cause git to throw an error, but the functionality is correct.
exit 0

else echo "${RED}./run_py_tools script fails, push aborted.${NC}" git checkout . # revert any changes made by the pytools script git stash apply exit 1 fi

- Save the file and __rename it to pre-push__ (i.e. remove the .sample suffix from the filename)
- Run __cd ../..__ to change the current working directory back to the root directory of the sml-python-small repository
- Open a poetry shell and run __git push__ to check if the testing tools work (it doesn't matter if there is nothing to push, the pre-push hook will still run).
- After all of the tests have run, you should see something like this:
```bash
================================================================================= 443 passed in 12.58s ==================================================================================
Test Results:
black --check --diff sml_small tests    : Success
flake8 sml_small tests                  : Success
isort --check-only .                    : Success
bandit -c pyproject.toml -r .           : Success
./run_py_tools script passes, proceeding with push...
Everything up-to-date

Troubleshooting