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
File details
Details for the file Jestspectation-0.5.1.tar.gz
.
File metadata
- Download URL: Jestspectation-0.5.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a8c395a0a660573108e27446f760b9d3117fb91c889cca873d23627f9fefe25 |
|
MD5 | 4392d092d90f5ab2e3da3cee6f90ab45 |
|
BLAKE2b-256 | 274e248c61b7e021e1054d06906fd4432c219c6b5bbc3d32ca5bd2bc7542c158 |
File details
Details for the file Jestspectation-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: Jestspectation-0.5.1-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87667c6c249f37616868e5e15638a5222972e1f44a31875663a5c7bb545c7403 |
|
MD5 | 768fa60b8d1076e15d066e1872d2f7a1 |
|
BLAKE2b-256 | da7887473e6b709f1eda6241815ed81fee2c15ab7d262e3ef2ab8eea39f95841 |