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

Examples

from unittest_assertions.identity import AssertIsInstance

assert_is_instance = AssertIsInstance()
assert_is_instance("example str", int) # raise TypeError("'example str' is not an instance of <class 'int'> : Raised a AssertionError")
from unittest_assertions.comparison import AssertEqual
assert_equal = AssertEqual()
assert_equal(1,1)
assert_equal(first="hello",second="hello")
from unittest_assertions.container import AssertNotIn
assert_in = AssertNotIn()
assert_in(member=1,container=[5,2,3])

Asserters

Comparison

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()
AsseritySequenceEqual 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

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

Logic

Asserter Expression
AssertTrue assert expr
AssertFalse assert not expr

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

Uploaded Source

Built Distribution

unittest_assertions-2.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unittest_assertions-2.3.tar.gz
  • Upload date:
  • Size: 7.9 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 unittest_assertions-2.3.tar.gz
Algorithm Hash digest
SHA256 b9c3dbd46531716c4893d98b4f094640403aec1f450914c0c4f7b695036dbf58
MD5 d4c0d3ac9ccb0e923ab7e4e0492e3ffc
BLAKE2b-256 c7050db76322edcfb66b27e627440334fad7df73e76ddea844cf4203bab6a9d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unittest_assertions-2.3-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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 unittest_assertions-2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9310df6a952e848282c2c08ccc30ed18e84d019d1167e45f55f2057e46329335
MD5 4d1a3ca5905f8e2c6934d1b09df50b76
BLAKE2b-256 efa13a6005cdcedfd6a360660f5abc280da8c180af676acf6464ec5e28403e8c

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