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()
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
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 worth-0.3.0.tar.gz
.
File metadata
- Download URL: worth-0.3.0.tar.gz
- Upload date:
- Size: 4.8 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 | d214cb09b0679a85c6b57742dda5f10ba0a4ed37752d6d1c4ae3c15cf2b88d17 |
|
MD5 | 623cedd1975592d251f2f2c9c85bd44a |
|
BLAKE2b-256 | f53e07e98e668cdf79715b0240412736668cb510af9a9c5b2bef3fe6a56ea5ea |
File details
Details for the file worth-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: worth-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.8 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 | 841dbd7c8583d41edf0a1cd3d93b44c21e07a90e255a86dfbf04ad2fd8108074 |
|
MD5 | 43e6b7bbe5295ff70e30e72c9642b210 |
|
BLAKE2b-256 | 27786719c0bad57b426dfef006fe09522ffb7fb20f26e86e15531fba9117bfcb |