betty.assertion.error module - Betty 0.4.0a3 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.

  Parameters:

    message (`betty.locale.localizable.Localizable`)

  __init__(message: betty.locale.localizable.Localizable)
    Parameters:

      message (`betty.locale.localizable.Localizable`)

  property contexts: tuple[Localizable, ...]

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

  localize(localizer: betty.locale.Localizer) → str

    Localize `self` to a human-readable string.

    Parameters:

      localizer (`betty.locale.Localizer`)

    Return type:

      `str`

  raised(error_type: type[betty.assertion.error.AssertionFailed]) → bool

    Check if the error matches the given error type.

    Parameters:

      error_type (`type`[`betty.assertion.error.AssertionFailed`])

    Return type:

      `bool`

  with_context(*contexts: betty.locale.localizable.Localizable) → Self

    Add a message describing the error’s context.

    Parameters:

      contexts (`betty.locale.localizable.Localizable`)

    Return type:

      `typing.Self`

exception betty.assertion.error.AssertionFailedGroup

  Bases: `AssertionFailed`

  A group of zero or more assertion failures.

  Parameters:

    errors (`list`[`betty.assertion.error.AssertionFailed`] | `None`)

  __init__(errors: list[betty.assertion.error.AssertionFailed] | None = None)
    Parameters:

      errors (`list`[`betty.assertion.error.AssertionFailed`] | `None`)

  append(*errors: betty.assertion.error.AssertionFailed) → None

    Append errors to this collection.

    Parameters:

      errors (`betty.assertion.error.AssertionFailed`)

    Return type:

      `None`

  assert_valid() → Iterator[Self]

    Assert that this collection contains no errors.

    Return type:

      `typing.Iterator`[`typing.Self`]

  catch(*contexts: betty.locale.localizable.Localizable) → Iterator[betty.assertion.error.AssertionFailedGroup]

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

    Return type:

      `typing.Iterator`[`betty.assertion.error.AssertionFailedGroup`]

    Returns:

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

    Parameters:

      contexts (`betty.locale.localizable.Localizable`)

  property invalid: bool

    Check that this collection contains at least one error.

  localize(localizer: betty.locale.Localizer) → str

    Localize `self` to a human-readable string.

    Parameters:

      localizer (`betty.locale.Localizer`)

    Return type:

      `str`

  raised(error_type: type[betty.assertion.error.AssertionFailed]) → bool

    Check if the error matches the given error type.

    Parameters:

      error_type (`type`[`betty.assertion.error.AssertionFailed`])

    Return type:

      `bool`

  property valid: bool

    Check that this collection contains no errors.

  with_context(*contexts: betty.locale.localizable.Localizable) → Self

    Add a message describing the error’s context.

    Parameters:

      contexts (`betty.locale.localizable.Localizable`)

    Return type:

      `typing.Self`