Skip to main content

Pattern matching tools to test complex data structures

Project description

Jestspectation

Pattern matching tools to test complex data structures.

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)
}

Documentation

Documentation can be found on GitHub Pages.

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.

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

To automatically use Jestspectation's diff parsing, you can configure Jestspectation.

import jestspectation

jestspectation.configure().pytest_all_diffs = True

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-1.4.1.tar.gz (14.6 kB view hashes)

Uploaded Source

Built Distribution

jestspectation-1.4.1-py3-none-any.whl (23.1 kB view hashes)

Uploaded Python 3

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