Dynamic fixture creation for your tests
Project description
python-fixturify-project
Dynamic fixture creation for your tests
A Python port of node-fixturify-project
Installation
pip install -U python-fixturify-project
or install with Poetry
poetry add python-fixturify-project --dev
Usage
python-fixturify-project
is a Python package that provides a way to create dynamic fixtures for your tests. Fixtures are real directories and files, written to a temporary directory.
from python_fixturify_project import Project
dir_json = {
"valid_file.txt": "some text",
"nested_dir": {
"valid_empty_file.txt": "",
"another_nested_empty_dir": {},
"another_nested_dir": {
"last_nested_empty_dir": {},
"final_text_file.txt": "some text",
},
},
}
# create a new project with the given directory structure
with Project(files=dir_json) as p:
# add new files to the project, merging with the existing directory structure
p.write({
"new_file.txt": "some text"
})
# read the actual contents on disc
actual_dir_json = p.read()
Ignore Files
By default, the read()
function will ignore all .git
directories in your Project file structure. This can be overridden by using the ignore_patterns
function parameter, which
takes a list of glob pattern strings. This may be slightly confusing, as glob patterns are normally used in an inclusive manner when performing file-system searches, however any patterns
provided to the ignore_patterns
parameter will be used in an exclusive manner. For example:
files = {
".git": {
"a_nested_dir": {}
},
".github": {
"ignore_me": {},
"do_not_ignore_me": {
"a_file": "some text"
}
},
"ignore_me": "some text",
"do_not_ignore_me": "some text",
}
with Project(files=files) as p:
dir_json = p.read(ignore_patterns=["**/.git", "**/.git/**", "**/ignore_me"]) # Default is ["**/.git", "**/.git/**"]
assert dir_json == {
'.github': {
'do_not_ignore_me': {
'a_file': 'some text',
},
},
'do_not_ignore_me': 'some text',
}
Usage when writing tests
python-fixutrify-project
becomes even more useful when combining it with something like syrupy
.
from python_fixturify_project import Project
def test_mutating_project(snapshot):
with Project(files=INITIAL_DIR_JSON) as p:
mutate_files_for_some_reason(p.base_dir)
# ensure mutations were as expected
assert project.read() == snapshot
Development
Makefile usage
Makefile
contains a lot of functions for faster development.
1. Download and remove Poetry
To download and install Poetry run:
make poetry-download
To uninstall
make poetry-remove
2. Install all dependencies and pre-commit hooks
Install requirements:
make install
Pre-commit hooks coulb be installed after git init
via
make pre-commit-install
3. Codestyle
Automatic formatting uses pyupgrade
, isort
and black
.
make codestyle
# or use synonym
make formatting
Codestyle checks only, without rewriting files:
make check-codestyle
Note:
check-codestyle
usesisort
,black
anddarglint
library
Update all dev libraries to the latest version using one comand
make update-dev-deps
4. Code security
make check-safety
This command launches Poetry
integrity checks as well as identifies security issues with Safety
and Bandit
.
make check-safety
5. Type checks
Run mypy
static type checker
make mypy
6. Tests with coverage badges
Run pytest
make test
7. All linters
Of course there is a command to rule run all linters in one:
make lint
the same as:
make test && make check-codestyle && make mypy && make check-safety
8. Docker
make docker-build
which is equivalent to:
make docker-build VERSION=latest
Remove docker image with
make docker-remove
More information about docker.
9. Cleanup
Delete pycache files
make pycache-remove
Remove package build
make build-remove
Delete .DS_STORE files
make dsstore-remove
Remove .mypycache
make mypycache-remove
Or to remove all above run:
make cleanup
🛡 License
This project is licensed under the terms of the MIT
license. See LICENSE for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python-fixturify-project-0.1.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 644ac3257da1be282afbab937b4a6fa1fcd8346a6d95598e7889fee5dc193fc7 |
|
MD5 | 48d475417c4fd85fb870528ca7823b30 |
|
BLAKE2b-256 | fa647b161279c38b1a0c314c1c901d83e3a7da4b613ea0db33c3c0c6baabe824 |
Hashes for python_fixturify_project-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7324706f8eb8d57755e24ba141046a1ec700e9720e7ce70ae3f4b49e9bfb64a3 |
|
MD5 | 6379d28d2f11c428a6682add365a8b5e |
|
BLAKE2b-256 | b8e5b9a331066c641312e427c502a57f534fd02794fa527be56c93af1dbf31df |