Skip to main content

No project description provided

Project description

Code Style License: MIT Linting and Testing codecov

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, documented, and tested makes it great for editor support and extension.
  • There is More!!!:
    • assertify: Simple, Flexible, and Extendable python3.6+ library to evaluate an expression and return True/False or raise an AssertionError or Exception.

Installation

pip install unittest-assertions

Examples

from unittest_assertions.identity import AssertIsInstance

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

assert_equal = AssertEqual()
assert_equal(1, 1)
assert_equal(first="hello", second="hello")
from unittest_assertions import AssertNotIn
assert_in = AssertNotIn()
assert_in(member=1, container=[5,2,3])

Asserters

Container

Asserter Expression
AssertIn assert member in container
AssertNotIn assert member not in container

Control

Asserter Expression
AssertRaises assert function raises expected_exception
AssertWarns assert function warns expected_warning
AssertLogs assert logger(level)

Equality

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

Identity

Asserter Expression
AssertTrue assert expr is True
AssertFalse assert expr is False
AssertIs assert exp1 is exp2
AssertIsNot assert exp1 is not exp2
AssertIsNone assert obj is None
AssertIsNotNone assert obj is not None
AssertIsInstance assert isinstance(obj,class)
AssertIsNotInstance assert not isinstance(obj,class)

Regex

Asserter Expression
AssertRaisesRegex assert expected_regex in expected_exception_message
AssertWarnsRegex assert expected_regex in expected_warning_message
AssertRegex assert text in expected_regex
AssertNotRegex assert 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-3.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

unittest_assertions-3.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unittest_assertions-3.1.tar.gz
  • Upload date:
  • Size: 10.7 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

Hashes for unittest_assertions-3.1.tar.gz
Algorithm Hash digest
SHA256 d37a2460acaf53c8001a71b6b6d7e9e84d8e581dcb45af827849cce3ce171712
MD5 530255f4000a240722a43135ce719e87
BLAKE2b-256 4c61f42944d8fe46d11c6a635fd2ac404839eddba023bbdfaaa21e416c2042b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unittest_assertions-3.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 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

Hashes for unittest_assertions-3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4c1ab33d1e9b542a666f7f5ca8159fa02a1a01bf13a97a545b308104beb1e189
MD5 6d937c02fd65e28498a7afec21acbb31
BLAKE2b-256 63c606547f5a598faf9e52102f44d147171503d00bbf50e73c6a2ced97959556

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