Skip to main content

No project description provided

Project description

Maintenance Code Style License: MIT codecov

assertify

assertify -- assert (ver)ify -- is a Flexible, and Extendable python3.6+ library for boolean expressions, assertions, and verifications.

Key Features:

  • Easy: Designed to make it easy to evaulate 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.
    • assertify_predicates: Is an extension of Assertify which allows for assertifying predicates. This is useful for validating variables or user input.
    • descriptify: Descriptify is a library that contians helpful python descriptors. It uses assertify_predicates to validate various descriptors.

Installation

pip install assertify

Example

Each Assertifier 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

Assertifiers

Comparison

Assertifier Expression raises
AssertifyEqual first == second ValueError
AsserifyNotEqual first != Second ValueError
AssertifyAlmostEqual first ~ second ValueError
AssertifyNotAlmostEqual first !~ second ValueError
AssertifyCountEqual len(first) == len(second) ValueError
AssertifyMultilineEqual first.splitlines() == second.splitlines() ValueError
AssertifySequenceEqual seq1 == seq2 ValueError
AssertifyListEqual list1 == list2 ValueError
AssertifyTupleEqual tuple1 == tuple2 ValueError
AssertifySetEqual set1 == set2 ValueError
AssertifyDictEqual dict1 == dict2 ValueError
AssertifyLess a < b ValueError
AssertifyLessEqual a <= b ValueError
AssertifyGreater a > b ValueError
AssertifyGreater a >= b ValueError

Container

Assertifier Expression raises
AssertifyIn member in container ValueError
AssertifyNotIn member not in container ValueError

Control

Assertifier Expression raises
AssertifyRaises excpected_exception ValueError
AssertifyWarns excpected_warning ValueError
AssertifyLogs logger(level) ValueError

Identity

Assertifier Expression raises
AssertifyIs exp1 is exp2 ValueError
AssertifyIsNot exp1 is not exp2 ValueError
AssertifyIsNone obj is None ValueError
AssertifyIsNotNone obj is not None ValueError
AssertifyIsInstance isinstance(obj,class) TypeError
AssertifyIsInstances isinstance(obj,cls) for cls in classes TypeError
AssertifyIsNotInstance not isinstance(obj,class) TypeError
AssertifyIsNotInstances not isinstance(obj,cls) for cls in classes TypeError

Logic

Assertifier Expression raises
AssertifyTrue expr ValueError
AssertifyFalse not expr ValueError

Regex

Assertifier Expression raises
AssertifyRaisesRegex expected_regex in expected_exception_message ValueError
AssertifyWarnsRegex expected_regex in expected_warning_message ValueError
AssertifyRegex text in expected_regex ValueError
AssertifyNotRegex text not in expected_regex ValueError

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assertify-2.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

assertify-2.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file assertify-2.0.tar.gz.

File metadata

  • Download URL: assertify-2.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for assertify-2.0.tar.gz
Algorithm Hash digest
SHA256 88398a82b25865c912c0198ed5f044598722129ef934dcb4ec3857759d0d77d2
MD5 cc3b3d9c0dcd3f7ebda15817305e94f2
BLAKE2b-256 ea5feb4fb594ee0da4dacee8e7bd6102c6601792fa5cd3767adc262d293546d2

See more details on using hashes here.

File details

Details for the file assertify-2.0-py3-none-any.whl.

File metadata

  • Download URL: assertify-2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for assertify-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6730a45d9358f74c272ce15ab3111df055f85d96bbf33c2cd695a06e7d4e0097
MD5 737cd51a44acf82d17bc387bec940ade
BLAKE2b-256 6af3d5ecccc7d16f9fa43a1746fa7461194ce2139874a84e3ecd0e1fb5a07879

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page