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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jestspectation-1.4.4-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file jestspectation-1.4.4.tar.gz.

File metadata

  • Download URL: jestspectation-1.4.4.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.21 Linux/6.8.0-1017-azure

File hashes

Hashes for jestspectation-1.4.4.tar.gz
Algorithm Hash digest
SHA256 2f0c2aae79f8e0c1bb64e2bdbf42f7d1192e9fea542ab4712d860e72cd0a417d
MD5 55ccd09ace93cd44d09db82af3044efe
BLAKE2b-256 21065ee416f6b1b8677e98a6f2cc2aad740c2668458159d8959a9d5d096dcbfe

See more details on using hashes here.

File details

Details for the file jestspectation-1.4.4-py3-none-any.whl.

File metadata

  • Download URL: jestspectation-1.4.4-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.21 Linux/6.8.0-1017-azure

File hashes

Hashes for jestspectation-1.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 574b8b48ef76d1e80f2290f251691e247a1f255ac490597d2c05de4d34127361
MD5 d49bbbae883122c8c9a791a3ee70bb0f
BLAKE2b-256 9d735e362ae295a57175323b141083c6b08fc047a9501c486011698e201923dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page