Skip to content

Basic Matchers

Any

Matches any object that is an instance of the given type

Parameters:

Name Type Description Default
match_type type

type to match

required

Anything

Matches any Python object

FloatApprox

Float approximately equal.

Parameters:

Name Type Description Default
value float

target value.

required
magnitude Optional[float]

maximum magnitude difference. Defaults to None.

None
percent Optional[float]

maximum percentage difference. Percentage differences are always calculated based on the expected value, regardless of ordering. Defaults to None.

None

If both a magnitude and percent are specified, both will be checked.

Raises:

Type Description
ValueError

At least one of magnitude or percent must be specified

ValueError

Cannot calculate a percentage difference from 0

Equals

Matches objects that have the same value.

This is equivalent to the == operator, but with additional information on the difference, which can help with debugging.

Parameters:

Name Type Description Default
value object

object to check

required

Is

Matches values that have the same identity as the given value.

While this isn't as useful for top-level comparisons, it can be used effectively for checking nested data structures.

Parameters:

Name Type Description Default
value object

object to check

required