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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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