Assert relevant object attributes
Project description
Worth
Worth is a Python library that helps you assert relevant object attributes
For example
from worth import Omit
def test_something_like():
a = Model(id=12345, name="Hoff")
b = Model(id=67890, name="Hoff")
assert a == b | Omit("id")
It implements some helpers
Always
Always()
assertion is always true.
assert "a string" == Always()
assert 42 == Always()
assert False == Always()
Never
Never()
assertion is always false.
assert "a string" == Never()
assert 42 == Never()
assert False == Never()
Things that applies to dataclasses
Omit
Omit()
let you to exclude some properties of you model from the comparison.
a = Model(id=12345, name="Hoff")
b = Model(id=67890, name="Hoff")
assert a == b | Omit("id")
Only
Only()
let you to choose precisely which properties you want to compair.
a = Model(id=12345, name="Hoff")
b = Model(id=67890, name="Hoff")
assert a == b | Only("name")
Things that applies to mappings
contains
contains()
let you to compare some mapping items.
assert {"foo": 42, "bar": True} == contains({"foo": 42})
assert {"foo": 42, "bar": True} != contains({"foo": "wrong"})
TODO
- dataclasses
- attrs
- msgspec
- vanilla
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
worth-0.1.0.tar.gz
(4.4 kB
view details)
Built Distribution
worth-0.1.0-py3-none-any.whl
(5.3 kB
view details)
File details
Details for the file worth-0.1.0.tar.gz
.
File metadata
- Download URL: worth-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.2 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56b38c23488b25279eb244c1369618975a9dc977ca6fc5e9989217c3e9065bf4 |
|
MD5 | 48981f65625568a304f130a2537ddb68 |
|
BLAKE2b-256 | 61fc23d1020d7a17598fe331d7798e91d89cb74544d8b8fabc5c386af86ffb3f |
File details
Details for the file worth-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: worth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.2 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b02ed6144222c9c9a9f1031e491e1139ea7aa4509a0b123e5ccb471997317eb |
|
MD5 | 1d86127def4a8e2c97334cab291df79c |
|
BLAKE2b-256 | 9413939d71ca019eaec654aaed449d6e1114fcf4e2c59ba73ec5a10c10a5c66d |