Skip to main content

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


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.3.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

worth-0.3.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

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

Hashes for worth-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d214cb09b0679a85c6b57742dda5f10ba0a4ed37752d6d1c4ae3c15cf2b88d17
MD5 623cedd1975592d251f2f2c9c85bd44a
BLAKE2b-256 f53e07e98e668cdf79715b0240412736668cb510af9a9c5b2bef3fe6a56ea5ea

See more details on using hashes here.

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

Hashes for worth-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 841dbd7c8583d41edf0a1cd3d93b44c21e07a90e255a86dfbf04ad2fd8108074
MD5 43e6b7bbe5295ff70e30e72c9642b210
BLAKE2b-256 27786719c0bad57b426dfef006fe09522ffb7fb20f26e86e15531fba9117bfcb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page