Skip to main content

No project description provided

Project description

unittest_assertions

Thin wrapper around the python builtin unittest allowing developers to use the builtin assertions for non-unittest use cases.

Key Features:

  • Easy: Designed to make it be simple allowing developers to use the builtin unittest assertions for their own use cases.
  • Great Developer Experience: Being fully typed makes it great for editor support.
  • There is More!!!:
    • assertify: Simple, Flexible, and Extendable python3.6+ library to evaulate an expression and return True/False or raise an AssertionError or Exception.
    • 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 unittest-assertions

Example

from unittest_assertions.identity import AssertIsInstance

assert_is_instance = AssertIsInstance(msg="Raised a AssertionError")
assert_is_instance("example str", int) # raise TypeError("'example str' is not an instance of <class 'int'> : Raised a AssertionError")

Asserters

Comparison

Asserter Expression
AssertEqual first == second
AssertNotEqual first != Second
AssertAlmostEqual first ~ second
AssertNotAlmostEqual first !~ second
AssertCountEqual len(first) == len(second)
AssertMultilineEqual first.splitlines() == second.splitlines()
AsseritySequenceEqual seq1 == seq2
AssertListEqual list1 == list2
AssertTupleEqual tuple1 == tuple2
AssertSetEqual set1 == set2
AssertDictEqual dict1 == dict2
AssertLess a < b
AssertLessEqual a <= b
AssertGreater a > b
AssertGreater a >= b

Container

Asserter Expression
AssertIn member in container
AssertNotIn member not in container

Control

Asserter Expression
AssertRaises excpected_exception
AssertWarns excpected_warning
AssertLogs logger(level)

Identity

Asserter Expression
AssertIs exp1 is exp2
AssertIsNot exp1 is not exp2
AssertIsNone obj is None
AssertIsNotNone obj is not None
AssertIsInstance isinstance(obj,class)
AssertIsInstances isinstance(obj,cls) for cls in classes
AssertIsNotInstance not isinstance(obj,class)
AssertIsNotInstances not isinstance(obj,cls) for cls in classes

Logic

Asserter Expression
AssertTrue expr
AssertFalse not expr

Regex

Asserter Expression
AssertRaisesRegex expected_regex in expected_exception_message
AssertWarnsRegex expected_regex in expected_warning_message
AssertRegex text in expected_regex
AssertNotRegex text not in expected_regex

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

unittest_assertions-1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

unittest_assertions-1.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file unittest_assertions-1.2.tar.gz.

File metadata

  • Download URL: unittest_assertions-1.2.tar.gz
  • Upload date:
  • Size: 5.7 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 unittest_assertions-1.2.tar.gz
Algorithm Hash digest
SHA256 229a5aa0481116e7ee0ffb473bdf5316312118658b8bd161332e1d1e1fc0ac78
MD5 a23c30633ed1699f5d7b225adea4ec54
BLAKE2b-256 2df566fd8e6a191bc3afbc9cbeaac05eb2b8cc37d8f6a9e280f6756e4b62926b

See more details on using hashes here.

File details

Details for the file unittest_assertions-1.2-py3-none-any.whl.

File metadata

  • Download URL: unittest_assertions-1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 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 unittest_assertions-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e37554e87a0c12d814f024492d59d186ab912771c75e49450b025b2f9aace4c1
MD5 101008681bf0dabf91261b753f1957af
BLAKE2b-256 c13c7aec99ad8c3d982456c587acf82ec23fd7e5a1f25ff3822fc5b3c1fc9c14

See more details on using hashes here.

Supported by

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