Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

worth

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worth

Assert relevant object attributes

  • 0.3.0
  • PyPI
  • Socket score

Maintainers
1

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

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc