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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Jestspectation-0.6.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2066e25d69dda70eb0415380c11663534d9b6f5441dadabf22a55864bb3ce5a |
|
MD5 | 11e9ea975e8c06d573d04b995cc45d21 |
|
BLAKE2b-256 | 01eceef67929c2a270b44be9cba562d8e17da1b8da794665e8671e99e619e490 |