Skip to main content

No project description provided

Project description

Maintenance Code Style License: MIT

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(msg="Raising Exception")
is_instance("example str", int) # raise TypeError("'example str' is not an instance of <class 'int'> : Raising Exception")

Assertion Example

Specify AssertionError to be raised

from assertifiers.identity import AssertifyIsInstance

is_instance = AssertifyIsInstance(raises=AssertionError, msg="Raising AssertionError")
is_instance("example str", int) # raise AssertionError("'example str' is not an instance of <class 'int'> : Raising AssertionError")

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-1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

assertify-1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: assertify-1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for assertify-1.0.tar.gz
Algorithm Hash digest
SHA256 83f94254558907955ef63b38684805be5f3a8b7f9fdeb983e02924727d94d43a
MD5 eec47a4d78396452e531c25ce955acb9
BLAKE2b-256 8d2ae4e303cf7e4bffae077ad5426a6f35e49a3804639663660aa9c628e52506

See more details on using hashes here.

File details

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

File metadata

  • Download URL: assertify-1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for assertify-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2569a7444960831ad5816d8229f82de14e891ec3b8ebf8480767b9493e7054b
MD5 25ae2dfb8606f5dc2cf1f1aa0c9c7be7
BLAKE2b-256 de8eca7401c0aeb1dd86d4b05a1727facedbd325b4ff3051cae4dec4bd44de27

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