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.
- Easy: Designed to make it easy to evaluate an expression and return
True
/False
or raise anAssertionError
orException
. - 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 fromunittest
to standalone assertions.
- unittest_assertions: Assertify is built on top of the
pip install assertify
raises an appropriate exception by default.
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'>")
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'>")
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
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
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 |
Assertifier | Expression | raises |
---|---|---|
AssertifyIn | assertify member in container |
ValueError |
AssertifyNotIn | assertify member not in container |
ValueError |
Assertifier | Expression | raises |
---|---|---|
AssertifyRaises | assertify function raises expected_exception |
ValueError |
AssertifyWarns | assertify function warns expected_warning |
ValueError |
AssertifyLogs | assertify logger(level) |
ValueError |
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 |
Assertifier | Expression | raises |
---|---|---|
AssertifyTrue | assertify expr is True |
ValueError |
AssertifyFalse | assertify expr is False |
ValueError |
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 |