Skip to main content

Pattern matching helper classes designed to allow for testing of complex data structures in a readable and logical format.

Project description

Jestspectation

Pattern matching helper classes designed to allow for testing of complex data structures in a readable and logical format.

The design is inspired by the expect system from JavaScript's Jest testing framework.

import jestspectation as expect

assert {
    "a": 1,
    "b": 2,
    "c": 3.0,
} == {
    "a": 1,
    "b": expect.Any(int),
    "c": expect.FloatApprox(2.5, magnitude=0.5)
}

Installation

pip install jestspectation

Usage with Pytest

The library can be used as a pytest plugin, which can give access to much more detailed error messages when assertions fail.

You can enable it by adding the following lines to your conftest.py

pytest_plugins = ("jestspectation.pytest",)

This should result in output similar to the following

    def test_goodbye():
>       assert 1 == expect.Any(float)
E       assert Type mismatch
E         Expected any object of type float
E         Received 1 (int)

These advanced completions can also be used for most standard Python objects by wrapping the expected values in an Equals. For example:

    def test_lists():
>       assert expect.Equals([1, 2, 3, 4]) == [1, 2, 3, 5, 6]
E       assert [1, 2, 3, 4] == [1, 2, 3, 5, 6]
E         !! [3] 4 == 5
E            Value mismatch
E            Expected 4
E            Received 5
E         ++ [4] 6

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

Jestspectation-0.6.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

Jestspectation-0.6.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file Jestspectation-0.6.0.tar.gz.

File metadata

  • Download URL: Jestspectation-0.6.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for Jestspectation-0.6.0.tar.gz
Algorithm Hash digest
SHA256 353252bc9c6b7192741a35998582d4a53c22ed3763a37bfad5105aa551f3b906
MD5 cc307b42a74e37feedd2484f15487450
BLAKE2b-256 ee83c215a3befa0b7f1b277aef31f14076d13e95b578a874aa18fafed1ebf728

See more details on using hashes here.

File details

Details for the file Jestspectation-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for Jestspectation-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f23ba1e6a8739779c3f61fbefcedfc059524154c1b10d3690829f7a2db0261d3
MD5 586e806691c689defd3d4b687e399bd9
BLAKE2b-256 04bba1118f2405bd3d0baa61927db48f439b38fdc73d70851d3eecdef72f3647

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