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.5.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.5-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jestspectation-1.4.5.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.5.tar.gz
Algorithm Hash digest
SHA256 ef709fd51d2e72950fc093c34d1fc5eacec568a8756a4f7f649cd5f6ba949570
MD5 6f641fcf31fe6f756dca308c8b017e05
BLAKE2b-256 85dbec9c86ee59bcd2cd9dc08d43579aad1a2977cfebb16d997d69fde4b1d440

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jestspectation-1.4.5-py3-none-any.whl
  • Upload date:
  • Size: 23.2 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 22f86f6b7b103b4244018510027a9b453f677097d7dfd4580a6d89e782669f0a
MD5 0edc2564132bef1b8b0bdb8ba37f9cef
BLAKE2b-256 31092c856764d7901e00560c444534ee4307e389a3b372d259fe6d0c837b3dcb

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