assertify
assertify -- assert or (ver)ify -- is a Flexible, and Extendable python3.6+ library for evaluating an expression by returning False or raising an AssertionError or the given Exception if the expression is invalid.
Key Features:
- Easy: Designed to make it easy to evaluate an expression and return
True/Falseor raise anAssertionErrororException. - Great Developer Experience: Being fully typed makes it great for editor support.
- There is More!!!:
- unittest_assertions: Assertify is built on top of the
unittest_assertions, which is a library that converts the assertions fromunittestto standalone assertions.
- unittest_assertions: Assertify is built on top of the
Installation
pip install assertify
Example
raises an appropriate exception by default.
Exception Example
AssertifyIsInstance will raise a TypeError by default, but you can also specify any other type of exception.
from assertifiers.identity import AssertifyIsInstance
is_instance = AssertifyIsInstance()
is_instance("example str", int) # raise TypeError("'example str' is not an instance of <class 'int'>")
Assertion Example
Specify AssertionError to be raised
from assertifiers.identity import AssertifyIsInstance
is_instance = AssertifyIsInstance(raises=AssertionError)
is_instance("example str", int) # raise AssertionError("'example str' is not an instance of <class 'int'>")
Boolean Example
If raises=None assertify will return a Boolean.
from assertifiers.identity import AssertifyIsInstance
is_instance = AssertifyIsInstance(raises=None)
print(is_instance("example str", int)) # False
Predicate (Partial Function) Example
from functools import partial
from assertifiers.identity import AssertifyIsInstances
is_instance = AssertifyIsInstances(must_be_instance_of=any)
predicate_is_instance = partial(is_instance,classes=[int,float])
print(predicate_is_instance(obj=7.62)) # True
Assertifiers
Comparison
| Assertifier | Expression | raises |
|---|---|---|
| AssertifyEqual | assertify first == second |
ValueError |
| AssertifyNotEqual | assertify first != Second |
ValueError |
| AssertifyAlmostEqual | assertify first ~= second |
ValueError |
| AssertifyNotAlmostEqual | assertify first !~= second |
ValueError |
| AssertifyCountEqual | assertify len(first) == len(second) |
ValueError |
| AssertifyMultilineEqual | assertify first.splitlines() == second.splitlines() |
ValueError |
| AssertifySequenceEqual | assertify seq1 == seq2 |
ValueError |
| AssertifyListEqual | assertify list1 == list2 |
ValueError |
| AssertifyTupleEqual | assertify tuple1 == tuple2 |
ValueError |
| AssertifySetEqual | assertify set1 == set2 |
ValueError |
| AssertifyDictEqual | assertify dict1 == dict2 |
ValueError |
| AssertifyLess | assertify a < b |
ValueError |
| AssertifyLessEqual | assertify a <= b |
ValueError |
| AssertifyGreater | assertify a > b |
ValueError |
| AssertifyGreater | assertify a >= b |
ValueError |
Container
| Assertifier | Expression | raises |
|---|---|---|
| AssertifyIn | assertify member in container |
ValueError |
| AssertifyNotIn | assertify member not in container |
ValueError |
Control
| Assertifier | Expression | raises |
|---|---|---|
| AssertifyRaises | assertify function raises expected_exception |
ValueError |
| AssertifyWarns | assertify function warns expected_warning |
ValueError |
| AssertifyLogs | assertify logger(level) |
ValueError |
Identity
| Assertifier | Expression | raises |
|---|---|---|
| AssertifyIs | assertify exp1 is exp2 |
ValueError |
| AssertifyIsNot | assertify exp1 is not exp2 |
ValueError |
| AssertifyIsNone | assertify obj is None |
ValueError |
| AssertifyIsNotNone | assertify obj is not None |
ValueError |
| AssertifyIsInstance | assertify isinstance(obj,class) |
TypeError |
| AssertifyIsInstances | assertify isinstance(obj,cls) for cls in classes |
TypeError |
| AssertifyIsNotInstance | assertify not isinstance(obj,class) |
TypeError |
| AssertifyIsNotInstances | assertify not isinstance(obj,cls) for cls in classes |
TypeError |
Logic
| Assertifier | Expression | raises |
|---|---|---|
| AssertifyTrue | assertify expr is True |
ValueError |
| AssertifyFalse | assertify expr is False |
ValueError |
Regex
| Assertifier | Expression | raises |
|---|---|---|
| AssertifyRaisesRegex | assertify expected_regex in expected_exception_message |
ValueError |
| AssertifyWarnsRegex | assertify expected_regex in expected_warning_message |
ValueError |
| AssertifyRegex | assertify text in expected_regex |
ValueError |
| AssertifyNotRegex | assertify text not in expected_regex |
ValueError |
Metadata
Release files for assertify 3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| assertify-3.0.tar.gz | 12.6 kB | Without provenance | Details for assertify-3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| assertify-3.0-py3-none-any.whl | Python 3 | none | any | Details for assertify-3.0-py3-none-any.whl |
Total release size: 26.1 kB
Release files / assertify-3.0.tar.gz
| Download URL | assertify-3.0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5b9369762ce81e9f35067693a4ba2218793175885f4d69a75545efa25a2d92d
|
|
BLAKE2b-256 checksum How to use checksums |
305acb65b988824ae6b33ac1067f398447b43527a7d0c4aecc11496d8252552a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.3 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Release files / assertify-3.0-py3-none-any.whl
| Download URL | assertify-3.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58eca1f94eed9674da7dadd645a12fbf3b888a3ffa78cb81aedcd79aa2fa65b1
|
|
BLAKE2b-256 checksum How to use checksums |
6aabb0414d1e1d426e9fa8460cfd46a3436517c77b2d36813cf117b63bc4bdfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.3 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Security for assertify 3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.