-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unittests, linting and code formatting using nox #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've ran nox
(black, flake8, tests and coverage all independent and together) and pre-commit
. All works well. Great work @davidverweij 👍
I've made some minor suggestions below that could improve the codebade, including the addition of the aaa flake8 plugin.
One important change not listed below that we always overlook: you forgot to update the README to explain how to run nox, linting, etc. Maybe we need to write a flake8 plugin for forgetting to update the README? 👍 (or add it to the PR template?)
Thanks @jawrainey! I'll go through the requested changes now and will update the pull request. |
@davidverweij -- could you also solve this? You'll need to:
Remember to delete all |
Done, but no need for the pointer to change, as the init.py is still in the csv2docx folder. |
It is a bit confusing as no init is required in the |
@jawrainey , I've hopefully addressed all requested changes - see my comments to your comments and in the change files. I've also moved the module to Please review and let me know if you'd want any changes! |
I've pulled a clean copy of the repo and ran poetry as usual. The new infrastructure in nox for testing and linting, and pre-commit all work well. Great job on setting this up @davidverweij and writing the CLI unit tests. I especially liked the use of |
Closes #10 .
And works on point 1 and 2 of #23
What Changed (and why)?
I've followed guide 2 (Testing) and 3 (Linting) from Claudio Jolowicz's Hypermodern Python article to implement @jawrainey's suggested code linting, unittesting and pre-commit hooks. More specifically, I've implemented the following:
pytest
andcoverage
click.testing
nox
, ensuring it uses pinned dependencies as declared in thepoetry.lock
to ensure testing amongst collaborates is identical. Note theinstall_with_constraints()
wrapper in thenoxfile.py
as per Claudio Jolowicz's suggestion.Nox
is now set up to test the script in--no-dev
mode to reflect truer use, and not install alldev
dependencies in each virtual environment.nox
to run linting usingflake8
, code formatting usingblack
and basic safety checks usingsafety
. Currently, the setup includesflake8
,flake8-bandit
,flake8-black
,flake8-bugbear
, andflake8-import-order
.black
andflake8
per each commit. This currently only checks changed files.Changed files
pyproject.toml
now includesdev
dependencies for pytest (unit testing), coverage (unit test code coverage), black (auto code formatting), flake8 (linting and code-ordering)noxfile.py
contains the setup for runningnox
tests/test_cli.py
contains test cases for the CLI interface. Test can be expanded on by adding files in the same folder, such as atests/test_module.py
file..flake8
contains settings for linting,.pre-commit-config.yaml
contains setttings for the pre-commit hooks. Changes to this file need to be installed viapre-commit install
in the root folder.csv2docx.py
, albeit none introduced changes to functionality.tests/data/example_missing_column.csv
to test our module catching a missing column in acsv
file.How to test Changes
Before
nox
on your machine globally, e.g.pip install --user --upgrade nox
. If runningnox
results in acommand not found
, ensure the path to the install is available to your console. E.g. I had to addexport PATH=/Users/<username>/.local/bin:$PATH
to my~/.zshrc
file (I am using OhMyZ.pre-commit
on your machine globally, e.g.pip install --user --upgrade pre-commit
pre-commit install
to set up pre-commitpoetry install
andpoetry shell
to update the dependencies (e.g. forpytest
)Functionality
Nothing has changed to the module's functionality, so it should still work with:
poetry run convert -t tests/data/example.docx -c tests/data/example.csv -n NAME
(perhaps run
poetry install
andpoetry shell
beforehand)Test suite
The following commands allow you to use the current setup:
poetry run pytest
to only run tests usingpytest
nox -r
to run linting, safety and the pytestsnox -rs black
to perform code formatting according toblack
(this will also be done for each commit withpre-commit
pre-commit run --all-files
to run thepre-commit
hooked actions without a commit (which will be executed for eachgit commit
)Next Steps
flake8-builtins
,flake8-quotes
,flake8-docstrings
in Add linting and code formatting #10. These can be added still./src/
folder - which we have discussed before. Potentially worth revisiting?Review
Please review @jawrainey. In particular, whether adding the dev dependencies was appropriate (reflected in
poetry.lock
), and if you'd agree with this initials setup and approach.