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.2.0.tar.gz
(4.7 kB
view details)
Built Distribution
worth-0.2.0-py3-none-any.whl
(5.7 kB
view details)
File details
Details for the file worth-0.2.0.tar.gz
.
File metadata
- Download URL: worth-0.2.0.tar.gz
- Upload date:
- Size: 4.7 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 | da4f5439405efbf9b90645f679414b22d2bf3b83373f256ea5b46c6cab1de35f |
|
MD5 | c8391115f8856e5357d143446dd06d03 |
|
BLAKE2b-256 | b8c7027049943abf6e3cb1f9b2f339a82b7db42b9146a6a7329e4c9197a6614e |
File details
Details for the file worth-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: worth-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.7 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 | 4937562415b5e707a4d0151d396f4be7e3cbfc269b0bcbb886223c2f8b26bf19 |
|
MD5 | 4e2162ed5f93a420199a5479a16676ce |
|
BLAKE2b-256 | 2cc262cc659da771f72b6857cfea94a449d57bc26992bdb73b609cda1793a048 |