Skip to main content

Pro test fixture generator

Project description

protestr

PyPI - Version PyPI - Python Version


protestr is a pro test fixture generator for Python.

Installation

pip install protestr

Usage

Create a fixture

from protestr import provide
from protestr.specs import between

@provide(
    lat=between(-90.0, 90.0),
    lon=between(-180.0, 180.0),
    alt=float
)
def location(lat, lon, alt):
    return lat, lon, alt

Call it

lat, lon, alt = location() # no args needed

Resolve it

from protestr import resolve

lat, lon, alt = resolve(location)

Provide it

from protestr import provide

@provide(location)
def test_loc(loc):
    lat, lon, alt = loc

More examples

from protestr import provide
from protestr.specs import between, sequence, either, subset
import json


class TestUsage(unittest.TestCase):
    @provide(
        people=sequence(
            each={
                "id": str,
                "name": either("John Smith", "Jane Doe"),
                "hobbies": subset(
                    ("cycling", "swimming", "testing with protestr"),
                    n=2
                ),
                "metadata": {str: str}
            },

            # describe the sequence size
            n=between(1, 5),

            # optionally, cast to some sequence type
            type=list
        )
    )
    def test_foo(people):
        print(f"people={json.dumps(people, indent=4)}")

Output

people=[
    {
        "id": "nFvgELbMptWisGdIDgQ",
        "name": "John Smith",
        "hobbies": [
            "cycling",
            "testing with protestr"
        ],
        "metadata": {
            "EzUnRmbjxngaIz": "sOQZTiGXzXapAwoztrdCKSQwmCaTYaK"
        }
    },
    {
        "id": "qczkMMUzgEshkpMfPkbhmSQTgb",
        "name": "Jane Doe",
        "hobbies": [
            "swimming",
            "testing with protestr"
        ],
        "metadata": {
            "spMfIaRiXOkrXqhpBWMtBui": "MJwtFAnlIRpjJOFKVxDqVL"
        }
    }
]

License

protestr is distributed under the terms of the MIT license.

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

protestr-0.0.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

protestr-0.0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file protestr-0.0.1.tar.gz.

File metadata

  • Download URL: protestr-0.0.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for protestr-0.0.1.tar.gz
Algorithm Hash digest
SHA256 15db207cde6506563545fba35f5464cb239c665bc835343113d1fc97864f50ad
MD5 d425ce1cc1377a68c61a51a7b64a4084
BLAKE2b-256 2ed7a39f03b666f71ee5346246f7bbfce7c236cf1aab22ee09214c8d119b20f9

See more details on using hashes here.

File details

Details for the file protestr-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: protestr-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for protestr-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8111f2f1508ba3c0b84c9eccdb44308b4b4041e079982e48912e359f843cdfca
MD5 566a9163c381f7e7c38994e813b58554
BLAKE2b-256 85f761dde93c31958a5f205982ab3afc6b9d08210114463b8b6bafdb44aa0c53

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