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
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
File details
Details for the file jestspectation-1.4.3.tar.gz
.
File metadata
- Download URL: jestspectation-1.4.3.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1024-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a961ba0279753e76c33080bfe915ba6a63661a969e9aa62fb65b95ac211f32b |
|
MD5 | d83b3e16ee295992766a0d60ae434145 |
|
BLAKE2b-256 | f6f4ec8b1562e64dd1f11168cf08e53c89d40651a9b78bb47114d544ac7e9200 |
File details
Details for the file jestspectation-1.4.3-py3-none-any.whl
.
File metadata
- Download URL: jestspectation-1.4.3-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1024-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7883f81db9dd10199b67220f46067314c5562092ce12fd4e5002b10e2e188635 |
|
MD5 | 284efe153297c90ffa3341b7d5526482 |
|
BLAKE2b-256 | 20cd9d8496fc4eab98431c818d45fe1a05fdaf47ea80a4da60802be56ef453b2 |