betty.assertions.record module

Key-value record data assertions.

final class betty.assertions.record.Field

Bases: Generic

A key-value mapping field.

__init__(name: str, assertion: Pipe[ValueT, ReturnT] | None = None, *, as_name: str | None = None, optional: bool = False) None
as_name: str | None = None
assertion: Pipe[ValueT, ReturnT] | None = None
name: str
optional: bool = False
betty.assertions.record.assert_record(*fields: Field[Any, Any], allow_extra: bool = False) Pipeline[Any, MutableMapping[str, Any]]

Assert that a value is a record: a key-value mapping of arbitrary value types, with a known structure.

To validate a key-value mapping as a records, assertions for all possible keys MUST be provided. Any keys present in the value for which no field assertions are provided will cause the entire record assertion to fail.