assertionlib.assertion_functions

A module with various new assertion functions.

Index

len_eq(a, b, /) Check if the length of a is equivalent to b: len(a) == b.
str_eq(a, b, /, *[, str_converter]) Check if the string-representation of a is equivalent to b: repr(a) == b.
shape_eq(a, b, /) Check if the shapes of a and b are equivalent: a.shape == getattr(b, 'shape', b).
isdisjoint(a, b, /) Check if a has no elements in b.
issuperset(a, b, /) Check if a contains all elements from b.
issubset(a, b, /) Check if b contains all elements in a.
function_eq(func1, func2, /) Check if two functions are equivalent by checking if their __code__ is identical.

API

assertionlib.assertion_functions.len_eq(a: Sized, b: int, /)bool[source]

Check if the length of a is equivalent to b: len(a) == b.

assertionlib.assertion_functions.str_eq(a: T, b: str, /, *, str_converter: Callable[[T], str] = <built-in function repr>)bool[source]

Check if the string-representation of a is equivalent to b: repr(a) == b.

assertionlib.assertion_functions.shape_eq(a: numpy.ndarray, b: Union[numpy.ndarray, Tuple[int, ...]], /)bool[source]

Check if the shapes of a and b are equivalent: a.shape == getattr(b, 'shape', b).

b should be either an object with the shape attribute (e.g. a NumPy array) or a tuple representing a valid array shape.

assertionlib.assertion_functions.isdisjoint(a: Iterable[Hashable], b: Iterable[Hashable], /)bool[source]

Check if a has no elements in b.

assertionlib.assertion_functions.issuperset(a: Iterable[Hashable], b: Iterable[Hashable], /)bool[source]

Check if a contains all elements from b.

assertionlib.assertion_functions.issubset(a: Iterable[Hashable], b: Iterable[Hashable], /)bool[source]

Check if b contains all elements in a.

assertionlib.assertion_functions.function_eq(func1: function, func2: function, /)bool[source]

Check if two functions are equivalent by checking if their __code__ is identical.

func1 and func2 should be instances of FunctionType or any other object with access to the __code__ attribute.