valid8r.testing.assertions

Assertion helpers for testing with Maybe monads.

Attributes

T

Functions

assert_maybe_success(result, expected_value)

Assert that a Maybe is a Success with the expected value.

assert_maybe_failure(result, expected_error)

Assert that a Maybe is a Failure with the expected error message.

assert_error_equals(result, expected_error[, default])

Assert error via error_or helper.

Module Contents

valid8r.testing.assertions.T[source]
valid8r.testing.assertions.assert_maybe_success(result, expected_value)[source]

Assert that a Maybe is a Success with the expected value.

Parameters:
  • result (valid8r.core.maybe.Maybe[T]) – The Maybe instance to check

  • expected_value (Any) – The expected value inside the Maybe

Returns:

True if result is a Success with the expected value, False otherwise

Return type:

bool

Examples

>>> result = Maybe.success(42)
>>> assert_maybe_success(result, 42)
True
>>> assert_maybe_success(result, 43)
False
valid8r.testing.assertions.assert_maybe_failure(result, expected_error)[source]

Assert that a Maybe is a Failure with the expected error message.

Parameters:
  • result (valid8r.core.maybe.Maybe[T]) – The Maybe instance to check

  • expected_error (str) – The expected error message inside the Maybe

Returns:

True if result is a Failure with the expected error, False otherwise

Return type:

bool

Examples

>>> result = Maybe.failure("Invalid input")
>>> assert_maybe_failure(result, "Invalid input")
True
>>> assert_maybe_failure(result, "Other error")
False
valid8r.testing.assertions.assert_error_equals(result, expected_error, default='')[source]

Assert error via error_or helper.

Parameters:
Return type:

bool