Skip to main content

Dynamic fixture creation for your tests

Project description

python-fixturify-project

Build status Python Version Dependencies Status

Code style: black Security: bandit Pre-commit Semantic Versions License Coverage Report

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.

```python
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()

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 uses isort, black and darglint 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

License

This project is licensed under the terms of the MIT license. See LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-fixturify-project-0.1.3.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

python_fixturify_project-0.1.3-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file python-fixturify-project-0.1.3.tar.gz.

File metadata

  • Download URL: python-fixturify-project-0.1.3.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.6 Darwin/21.6.0

File hashes

Hashes for python-fixturify-project-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d1e14b7fd61ad169c1e4c4a9bb02de852f2ee0772fa30035cca5aab9e192c001
MD5 9aa65321c53497d1a97b297bf6014037
BLAKE2b-256 00634ecf65931f2bf75996e1ab6d581725f396947ad9b30ca63c6c17a52481c0

See more details on using hashes here.

File details

Details for the file python_fixturify_project-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for python_fixturify_project-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d6a93fa3dca2a381cc8d9af3a5f2db83286e51a7a139855216fc1957e23a26e
MD5 6728c4d1d7bbca29af3e64badfe28400
BLAKE2b-256 11e9835be0c66b3081467e537fa952fe0199cc381970cb66610518169c7bb0c3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page