betty.assertion.error module

Provide assertion failures.

exception betty.assertion.error.AssertionFailed[source]

Bases: UserFacingError, ValueError

An assertion failure.

Parameters:

message (betty.locale.localizable.Localizable)

__init__(message: betty.locale.localizable.Localizable)[source]
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[source]

Localize self to a human-readable string.

Parameters:

localizer (betty.locale.Localizer)

Return type:

str

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

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[source]

Add a message describing the error’s context.

Parameters:

contexts (betty.locale.localizable.Localizable)

Return type:

typing.Self

exception betty.assertion.error.AssertionFailedGroup[source]

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)[source]
Parameters:

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

append(*errors: betty.assertion.error.AssertionFailed) None[source]

Append errors to this collection.

Parameters:

errors (betty.assertion.error.AssertionFailed)

Return type:

None

assert_valid() Iterator[Self][source]

Assert that this collection contains no errors.

Return type:

typing.Iterator[typing.Self]

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

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[source]

Localize self to a human-readable string.

Parameters:

localizer (betty.locale.Localizer)

Return type:

str

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

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[source]

Add a message describing the error’s context.

Parameters:

contexts (betty.locale.localizable.Localizable)

Return type:

typing.Self