Elegant assertions library
Project description
expecting
Elegant assertions library.
This is currently a work in progress.
Installation options
pip install expecting
poetry add expecting --group dev
Usage
Expecting consists of a set of assertion objects that can be used with assert
statements in a clear, readable way.
Most common assertion will be covered under a structured set of modules, following an intuitive naming schema:
import expecting
assert '2023-10-11' == expecting.string.datetime.iso8601_day()
Here, the expcting.string.datetime
module introduces a handful of factory methods for asserting that the value is a
string representing a date and time format.
It's specially useful with pytest and its amazing error messages, where an assertion failure message would look something like:
string/test_datetime.py:7 (test_iso8601_full_matches[2023/10/11 13:01:10])
'2023/10/11 13:01:10' != ~= <datetime as "%Y-%m-%dT%H:%M:%S.%f%z">
Expected :~= <datetime as "%Y-%m-%dT%H:%M:%S.%f%z">
Actual :'2023/10/11 13:01:10'
<Click to see difference>
datetime_str = '2023/10/11 13:01:10'
@pytest.mark.parametrize(
'datetime_str',
(
'2023/10/11 13:01:10',
)
)
def test_iso8601_full_matches(datetime_str: str):
> assert datetime_str == expecting.string.datetime.iso8601_full()
E assert '2023/10/11 13:01:10' == ~= <datetime as "%Y-%m-%dT%H:%M:%S.%f%z">
...
The ~=
symbol prefixing the expected value is used denote this value is an "expecting object".
Contributing
Feel free to create issues or merge requests with any improvement or fix you might find useful.
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 expecting-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25bb40a5bd71a1f621d058bfa566e0b88602b853fd8cd70d286d0640ae7af3ac |
|
MD5 | 35980531486f10e19e843bc8fbc40d81 |
|
BLAKE2b-256 | 88eebaf68da5d786f06aeff1a7e77ee0bc0f66e8dffd521244c3c9cc4f7c8cdb |