joythief.numbers module

Matchers for numeric types (e.g. float).

class joythief.numbers.CloseTo(expected, *, rel_tol=None, abs_tol=None)[source]

Bases: Matcher[float]

Matches any numeric value approximately equal to an expected value.

Comparison is delegated to math.isclose(), so the same tolerance semantics apply: the relative tolerance is the maximum allowed difference relative to the larger absolute value of the inputs, and the absolute tolerance is the minimum allowed difference - useful when comparing values near zero.

Parameters:
  • expected (float) – the value to compare against.

  • rel_tol (float | None) – relative tolerance, defaulting to 1e-09. Must be less than 1.0.

  • abs_tol (float | None) – absolute tolerance, defaulting to 0.0.

Raises:

ValueError – if either tolerance is negative, or rel_tol is not less than 1.0.

class joythief.numbers.NaN(*args, **kwargs)[source]

Bases: Matcher[float]

Matches any float instance representing NaN.

IEEE 754 NaN (“not a number”) instances are, by definition, not equal to each other. This matcher compares equal to e.g. math.nan or float("nan") using math.isnan().

Originally formulated for this answer.

Parameters:
  • args (tp.Any)

  • kwargs (tp.Any)