🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

unittest-assertions

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unittest-assertions

3.1
PyPI
Maintainers
1

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

AsserterExpression
AssertInassert member in container
AssertNotInassert member not in container

Control

AsserterExpression
AssertRaisesassert function raises expected_exception
AssertWarnsassert function warns expected_warning
AssertLogsassert logger(level)

Equality

AsserterExpression
AssertEqualassert first == second
AssertNotEqualassert first != second
AssertAlmostEqualassert first ~= second
AssertNotAlmostEqualassert first !~= second
AssertCountEqualassert Counter(list(first) == Counter(list(second))
AssertMultilineEqualassert first.splitlines() == second.splitlines()
AssertSequenceEqualassert seq1 == seq2
AssertListEqualassert list1 == list2
AssertTupleEqualassert tuple1 == tuple2
AssertSetEqualassert set1 == set2
AssertDictEqualassert dict1 == dict2
AssertLessassert a < b
AssertLessEqualassert a <= b
AssertGreaterassert a > b
AssertGreaterassert a >= b

Identity

AsserterExpression
AssertTrueassert expr is True
AssertFalseassert expr is False
AssertIsassert exp1 is exp2
AssertIsNotassert exp1 is not exp2
AssertIsNoneassert obj is None
AssertIsNotNoneassert obj is not None
AssertIsInstanceassert isinstance(obj,class)
AssertIsNotInstanceassert not isinstance(obj,class)

Regex

AsserterExpression
AssertRaisesRegexassert expected_regex in expected_exception_message
AssertWarnsRegexassert expected_regex in expected_warning_message
AssertRegexassert text in expected_regex
AssertNotRegexassert text not in expected_regex

Keywords

python unittest pytest assertions assert assertify verify verification booleans standalone

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts