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/False or raise an AssertionError or Exception.
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 from unittest to standalone assertions.
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.
fromassertifiers.identityimportAssertifyIsInstanceis_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
fromassertifiers.identityimportAssertifyIsInstanceis_instance=AssertifyIsInstance(raises=AssertionError)
is_instance("example str", int) # raise AssertionError("'example str' is not an instance of <class 'int'>")
The Tidelift Subscription provides access to a continuously curated stream of human-researched and maintainer-verified data on open source packages and their licenses, releases, vulnerabilities, and development practices.