Registry / testing / anys
library0.3.1pypypi✓ verified 23d ago

anys provides a collection of matchers designed for pytest-style assertions, enabling more flexible comparisons in unit tests. Instead of strict equality checks, it allows developers to assert that values meet specific criteria (e.g., `ANY_DATETIME_STR` for any valid ISO 8601 timestamp string). This simplifies testing dynamic or partially unpredictable data structures. The library is actively maintained, with the current version being 0.3.1.

pip install anys
INSTALL
IMPORT
SIG · ANYS
A
anys
testingpythonv0.3.1
Install
1.6s avg
Import
20ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.022s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.018s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ANY_DATETIME_STR
from anys import ANY_DATETIME_STR
ANY_INT
from anys import ANY_INT
ANY_STR
from anys import ANY_STR
AnyGT
from anys import AnyGT
AnyLT
from anys import AnyLT
AnyMatch
from anys import AnyMatch
import anys; assert foo == anys.AnyMatch(...)
While technically possible, the documentation examples primarily use direct `from anys import ...` for brevity and clarity when using specific matchers.

This quickstart demonstrates how to use `anys` for flexible assertions, particularly with dynamic data like API responses. It uses `ANY_STR` to match any string and `ANY_DATETIME_STR` to match any valid ISO 8601 datetime string, allowing the test to pass even if the exact values for `id`, `created_at`, `status`, or `last_login` are not known in advance.

from anys import ANY_DATETIME_STR def test_api_response(): # Imagine this is a dynamic response from an API or function dynamic_data = { "id": "user-123", "name": "Test User", "created_at": "2024-04-12T10:30:00Z", "details": { "status": "active", "last_login": "2024-04-12T10:29:55Z" } } # Assert against a structure with matchers for dynamic fields expected_pattern = { "id": ANY_STR, # Match any string "name": "Test User", "created_at": ANY_DATETIME_STR, # Match any valid ISO datetime string "details": { "status": ANY_STR, "last_login": ANY_DATETIME_STR } } assert dynamic_data == expected_pattern print("Assertion successful: Dynamic data matches expected pattern!") test_api_response()
Debug
Known issues
gotchaWhen an `anys` matcher encounters a `TypeError` or `ValueError` during comparison (e.g., attempting to apply a regular expression matcher like `AnyMatch(r'\d+')` to an integer `42`), the library explicitly suppresses the exception and the comparison silently evaluates to `False`. This behavior, while intended, can mask unexpected type mismatches that might indicate a deeper issue if not anticipated.
fix
Be explicit about the expected types when using matchers. If a type mismatch might be indicative of a bug, consider adding a separate `isinstance()` check or use matchers specifically designed for numeric types (e.g., `ANY_INT`, `AnyGT`).
affects: All versions
gotchaMost `anys` class constructors (e.g., `AnyHas`, `AnyMapping`, `AnyDictOf`) are not designed to take other `anys` matchers as arguments for their keys or specific internal structures unless explicitly documented. Attempting to nest matchers in unsupported ways may lead to unexpected comparison results, `False` evaluations due to suppressed errors, or incorrect behavior.
fix
Consult the `anys` documentation for each specific matcher to understand what types of arguments it accepts. For complex nested matching, ensure each level of matching is compatible with the parent matcher's design.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'anys'
The 'anys' library is not installed in the Python environment.
fix
Install the 'anys' library using pip: 'pip install anys'.
ImportError: cannot import name 'ANY_DATETIME_STR' from 'anys'
The 'ANY_DATETIME_STR' matcher is not available in the 'anys' library.
fix
Use the 'ANY_STR' matcher from 'anys' for string comparisons.
TypeError: 'ANY' object is not callable
Attempting to call an 'ANY' matcher as a function, which is not supported.
fix
Use 'ANY' as a value in assertions without calling it as a function.
AssertionError: assert <value> == <anys matcher>
An 'anys' matcher encountered a TypeError or ValueError during comparison (e.g., trying to match a regex against an integer), but the library silently suppressed the error and evaluated the comparison to `False` instead of raising a descriptive exception. This leads to a generic `AssertionError` without clearly indicating the underlying type mismatch.
fix
Explicitly check the expected type of the value using `isinstance()` before applying the `anys` matcher, or use `anys` matchers specifically designed for the expected numeric or string types (e.g., `ANY_INT`, `AnyGT`, `ANY_STR`).
NameError: name 'ANY_DATETIME_STR' is not defined
The `ANY_DATETIME_STR` (or other top-level `anys` matchers like `ANY_INT`, `ANY_STR`) constant was used without being explicitly imported from the `anys` library. This is a common Python `NameError` when a constant or object is referenced before it has been assigned or imported.
fix
Add the necessary import statement: `from anys import ANY_DATETIME_STR` (or the specific matcher you intend to use) at the beginning of your Python file.
Upgrade
Version history
0.3.1latest on PyPI · released Dec 1, 2024
Audit
Dependencies
pythonrequiredRequires Python 3.8 or higher for compatibility.
Agent activity
53 hits · last 30 days
node
48
Amazon
1
OpenAI (training)
1
Resources
anys — pip install anys · libregistry