Skip to main content

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

Release files for Jestspectation 1.4.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Jestspectation 1.4.5
File Size Uploaded
jestspectation-1.4.5.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Jestspectation 1.4.5
File Interpreter ABI Platform
jestspectation-1.4.5-py3-none-any.whl Python 3 none any Details

Total release size: 37.4 kB

Release files / jestspectation-1.4.5.tar.gz

Download URL jestspectation-1.4.5.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ef709fd51d2e72950fc093c34d1fc5eacec568a8756a4f7f649cd5f6ba949570
BLAKE2b-256 checksum
How to use checksums
85dbec9c86ee59bcd2cd9dc08d43579aad1a2977cfebb16d997d69fde4b1d440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.9.21 Linux/6.8.0-1017-azure

Release files / jestspectation-1.4.5-py3-none-any.whl

Download URL jestspectation-1.4.5-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22f86f6b7b103b4244018510027a9b453f677097d7dfd4580a6d89e782669f0a
BLAKE2b-256 checksum
How to use checksums
31092c856764d7901e00560c444534ee4307e389a3b372d259fe6d0c837b3dcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.9.21 Linux/6.8.0-1017-azure

Release history Release notifications | RSS feed

This release

1.4.5 This release

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page