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()
OneOf
OneOf() asserts one of its values.
assert "foo" == OneOf("foo", "bar")
assert "bar" == OneOf("foo", "bar")
assert "qux" != OneOf("foo", "bar")
Things that applies to models (dataclasses, attrs, or msgspec)
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
Metadata
Release files for worth 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| worth-0.3.0.tar.gz | 4.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| worth-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / worth-0.3.0.tar.gz
| Download URL | worth-0.3.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d214cb09b0679a85c6b57742dda5f10ba0a4ed37752d6d1c4ae3c15cf2b88d17
|
|
BLAKE2b-256 checksum How to use checksums |
f53e07e98e668cdf79715b0240412736668cb510af9a9c5b2bef3fe6a56ea5ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.2 Darwin/23.5.0
|
Release files / worth-0.3.0-py3-none-any.whl
| Download URL | worth-0.3.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
841dbd7c8583d41edf0a1cd3d93b44c21e07a90e255a86dfbf04ad2fd8108074
|
|
BLAKE2b-256 checksum How to use checksums |
27786719c0bad57b426dfef006fe09522ffb7fb20f26e86e15531fba9117bfcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.2 Darwin/23.5.0
|