betty.assertion.error module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.assertion.error module

Provide assertion failures.

exception betty.assertion.error.AssertionFailed

  Bases: `UserFacingError`, `ValueError`

  An assertion failure.

  __init__(message: Localizable)
  property contexts: tuple[Localizable, ...]

    Get the human-readable contexts describing where the error occurred in the source data.

  localize(localizer: Localizer) → str

    Localize `self` to a human-readable string.

  raised(error_type: type[AssertionFailed]) → bool

    Check if the error matches the given error type.

  with_context(*contexts: Localizable) → Self

    Add a message describing the error’s context.

exception betty.assertion.error.AssertionFailedGroup

  Bases: `AssertionFailed`

  A group of zero or more assertion failures.

  __init__(errors: list[AssertionFailed] | None = None)
  append(*errors: AssertionFailed) → None

    Append errors to this collection.

  assert_valid() → Iterator[Self]

    Assert that this collection contains no errors.

  catch(*contexts: Localizable) → Iterator[AssertionFailedGroup]

    Catch any errors raised within this context manager and add them to the collection.

    Returns:

      A new collection that will only contain any newly raised errors.

  property invalid: bool

    Check that this collection contains at least one error.

  localize(localizer: Localizer) → str

    Localize `self` to a human-readable string.

  raised(error_type: type[AssertionFailed]) → bool

    Check if the error matches the given error type.

  property valid: bool

    Check that this collection contains no errors.

  with_context(*contexts: Localizable) → Self

    Add a message describing the error’s context.