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.8.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

Jestspectation-0.8.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Jestspectation-0.8.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for Jestspectation-0.8.1.tar.gz
Algorithm Hash digest
SHA256 7bd1e272127baae723bc7a13715d1362d32963475dd3f1b68a5081a6fdd1d019
MD5 71b05d21907df645f2d2cc0a70295ade
BLAKE2b-256 eba2d0a77ffe181c6a51ae31310d708390dc064c2c60bee794139e2865444515

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Jestspectation-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1d65a903b8e9f75fe160d73bf81b3f5a8fff6cc647224643cd6ece3b255855de
MD5 1fb3e2aa7fc31f76ca1c6d44c3698475
BLAKE2b-256 90157a684554ca355b093b5eef12f6b46ed2ff1599e734e81bd5df916c268be1

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