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:
- 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:
- 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:
- Return type:
- 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:
- Returns:
A new collection that will only contain any newly raised errors.
- Parameters:
contexts (
betty.locale.localizable.Localizable
)
- localize(localizer: betty.locale.Localizer) str [source]¶
Localize
self
to a human-readable string.- Parameters:
localizer (
betty.locale.Localizer
)- Return type:
- 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:
- 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