No project description provided
Project description
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
/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
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 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
assertify-3.0.tar.gz
(12.6 kB
view details)
Built Distribution
assertify-3.0-py3-none-any.whl
(13.5 kB
view details)
File details
Details for the file assertify-3.0.tar.gz
.
File metadata
- Download URL: assertify-3.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b9369762ce81e9f35067693a4ba2218793175885f4d69a75545efa25a2d92d |
|
MD5 | f2150ba466fa6c97aa656927f77f3fd2 |
|
BLAKE2b-256 | 305acb65b988824ae6b33ac1067f398447b43527a7d0c4aecc11496d8252552a |
File details
Details for the file assertify-3.0-py3-none-any.whl
.
File metadata
- Download URL: assertify-3.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58eca1f94eed9674da7dadd645a12fbf3b888a3ffa78cb81aedcd79aa2fa65b1 |
|
MD5 | c9837dc4902f3475932d8639aeb078bc |
|
BLAKE2b-256 | 6aabb0414d1e1d426e9fa8460cfd46a3436517c77b2d36813cf117b63bc4bdfb |