MCPcopy Create free account
hub / github.com/samuelcolvin/dirty-equals

github.com/samuelcolvin/dirty-equals @v0.11.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.11.0 ↗ · + Follow
316 symbols 900 edges 25 files 82 documented · 26% 3 cross-repo links updated 7mo agov0.11.0 · 2025-11-17★ 99716 open issues

Browse by type

Functions 247 Types & classes 64 Endpoints 5
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

dirty-equals

Doing dirty (but extremely useful) things with equals.

CI Coverage pypi versions license


Documentation: dirty-equals.helpmanual.io

Source Code: github.com/samuelcolvin/dirty-equals


dirty-equals is a python library that (mis)uses the __eq__ method to make python code (generally unit tests) more declarative and therefore easier to read and write.

dirty-equals can be used in whatever context you like, but it comes into its own when writing unit tests for applications where you're commonly checking the response to API calls and the contents of a database.

Usage

Here's a trivial example of what dirty-equals can do:

from dirty_equals import IsPositive

assert 1 == IsPositive
assert -2 == IsPositive  # this will fail!

That doesn't look very useful yet!, but consider the following unit test code using dirty-equals:

```py title="More Powerful Usage" from dirty_equals import IsJson, IsNow, IsPositiveInt, IsStr

...

user_data is a dict returned from a database or API which we want to test

assert user_data == { # we want to check that id is a positive int 'id': IsPositiveInt, # we know avatar_file should be a string, but we need a regex as we don't know whole value 'avatar_file': IsStr(regex=r'/[a-z0-9-]{10}/example.png'), # settings_json is JSON, but it's more robust to compare the value it encodes, not strings 'settings_json': IsJson({'theme': 'dark', 'language': 'en'}), # created_ts is datetime, we don't know the exact value, but we know it should be close to now 'created_ts': IsNow(delta=3), }


Without *dirty-equals*, you'd have to compare individual fields and/or modify some fields before comparison -
the test would not be declarative or as clear.

*dirty-equals* can do so much more than that, for example:

* [`IsPartialDict`](https://dirty-equals.helpmanual.io/types/dict/#dirty_equals.IsPartialDict)
  lets you compare a subset of a dictionary
* [`IsStrictDict`](https://dirty-equals.helpmanual.io/types/dict/#dirty_equals.IsStrictDict)
  lets you confirm order in a dictionary
* [`IsList`](https://dirty-equals.helpmanual.io/types/sequence/#dirty_equals.IsList) and
  [`IsTuple`](https://dirty-equals.helpmanual.io/types/sequence/#dirty_equals.IsTuple)
  lets you compare partial lists and tuples, with or without order constraints
* nesting any of these types inside any others
* [`IsInstance`](https://dirty-equals.helpmanual.io/types/other/#dirty_equals.IsInstance)
  lets you simply confirm the type of an object
* You can even use [boolean operators](https://dirty-equals.helpmanual.io/usage/#boolean-logic)
  `|` and `&` to combine multiple conditions
* and much more...

## Installation

Simply:

```bash
pip install dirty-equals

dirty-equals requires Python 3.9+.

Core symbols most depended-on inside this repo

Shape

Function 127
Method 120
Class 64
Route 5

Languages

Python100%

Modules by API surface

tests/test_other.py41 symbols
dirty_equals/_numeric.py37 symbols
dirty_equals/_base.py37 symbols
dirty_equals/_other.py35 symbols
tests/test_base.py21 symbols
tests/test_dict.py15 symbols
dirty_equals/_inspection.py15 symbols
dirty_equals/_dict.py14 symbols
tests/test_inspection.py13 symbols
dirty_equals/_sequence.py13 symbols
dirty_equals/_datetime.py13 symbols
tests/test_datetime.py11 symbols

Datastores touched

appDatabase · 1 repos

For agents

$ claude mcp add dirty-equals \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page