Skip to main content

compyre

What is this?

compyre provides container unpacking and elementwise equality comparisons for arbitrary objects using their native functionality. It offers convenient defaults, while being fully configurable.

"X all the Y" meme with "compyre all the things" as text

Why do I need it?

Have you ever found yourself in a situation where you needed to test a potentially nested container of values against a reference? pytest, the de facto standard test framework for Python, features awesome failure reporting for builtin types such as dictionaries, lists, integers, strings, and so on.

But what about other common types that come with their own comparison logic, e.g. numpy.ndarray and numpy.testing.assert_allclose? How do you compare a dictionary or worse a dataclass of these?

  • Did you ever skip writing a proper test in such a situation and opted to write a simple, but incomplete one instead?
  • If not, did you write the test as loop over the individual elements, and later spend more time debugging, because you have no way of knowing for which element the test failure happened?
  • If not, is manually writing out all the assertions and maintaining them keeping you from working on the stuff that actually matters for your application or library?

If you have answered "yes" for any of the questions above, compyre was made for you.

How do I get started?

Most basic cases can be covered by compyre.equal or compyre.assert_equal. The former provides a boolean check, while the latter raises an AssertionError with information what elements mismatch and why.

import dataclasses

import numpy as np

import compyre

@dataclasses.dataclass
class MyObject:
    id: str
    data: list[np.ndarray]

expected = MyObject(
    id="foo",
    data=[np.array([1, 2]), np.array([3, 4])],
)

actual = MyObject(
    id="bar",
    data=[np.array([1, 2]), np.array([3, 5])],
)

compyre.assert_equal(actual, expected)
AssertionError: comparison resulted in 2 error(s):

id
    AssertionError: 'bar' != 'foo'
data.1
    AssertionError: 
    Not equal to tolerance rtol=1e-07, atol=0

    Mismatched elements: 1 / 2 (50%)
    Max absolute difference among violations: 1
    Max relative difference among violations: 0.25
     ACTUAL: array([3, 5])
     DESIRED: array([3, 4])

How do I learn more?

Please have a look at the documentation.

Metadata

Release files for compyre 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for compyre 0.3.0
File Size Uploaded
compyre-0.3.0.tar.gz 300.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for compyre 0.3.0
File Interpreter ABI Platform
compyre-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 317.5 kB

Release files / compyre-0.3.0.tar.gz

Download URL compyre-0.3.0.tar.gz
Size 300.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2065e8f525c529c7b33bab1f1c525cc17f18c6cbf08914986893816ced05dc0d
BLAKE2b-256 checksum
How to use checksums
0dec88b493a68d9f04b8afb9e506ccfc904c9a1e46f643651489f073f84d262c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / compyre-0.3.0-py3-none-any.whl

Download URL compyre-0.3.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d11b48f1c38570ba05f6f76a91b4022d9dd654f063e979711d55dc8b4974c09
BLAKE2b-256 checksum
How to use checksums
3b8cf026d24c967a261eb0be095170c782d62248b9d87ebb299457dbc388b4d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page