dp3.testing ¶
Testing helpers for DP3 applications.
DP3ModuleTestCase ¶
Bases: ModuleAssertions, TestCase, Generic[ModuleT]
Base class for unit tests of DP3 secondary modules.
By default the app configuration directory is read from DP3_CONFIG_DIR. Subclasses may set
config_dir explicitly when they need a fixed fixture config.
make_timeseries_datapoint ¶
make_timeseries_datapoint(etype: str, eid: Any, attr: str, v: Mapping[str, Sequence[Any]], src: str = 'test', t1: datetime | None = None, t2: datetime | None = None, **fields) -> DataPointBase
Create a validated timeseries datapoint.
For regular timeseries attributes, t2 is inferred when omitted by using the
attribute's configured time_step and the number of samples in v:
t2 = t1 + len(series) * time_step. For irregular timeseries, t1 is inferred from
the first time value when omitted. For irregular-interval timeseries, t1 is inferred
from the first time_first value when omitted.
Source code in dp3/testing/case.py
registered ¶
Return registrations matching kind and the supplied registration fields.
Source code in dp3/testing/case.py
assert_registered ¶
Assert that at least one callback registration matches the supplied fields.
Source code in dp3/testing/case.py
assert_registered_once ¶
Assert that exactly one callback registration matches the supplied fields.
Source code in dp3/testing/case.py
assert_registered_attrs ¶
assert_registered_attrs(entity: str, expected_attrs: Iterable[str], *, kind: str = 'on_new_attr', exact: bool = True) -> list[HookRegistration]
Assert that attribute hook registrations exist for the supplied entity attributes.
Source code in dp3/testing/case.py
assert_scheduler_registered ¶
Assert that at least one scheduler callback registration matches the supplied fields.
HookRegistration
dataclass
¶
HookRegistration(kind: str, hook: Callable, entity: str | None = None, attr: str | None = None, hook_type: str | None = None, hook_id: str | None = None, entity_type: str | None = None, attr_type: str | None = None, depends_on: list[list[str]] = list(), may_change: list[list[str]] = list(), refresh: Any = None, period: Any = None, deprecated: bool = False, extra: dict[str, Any] = dict())
Captured callback registration made by a secondary module.
TestCallbackRegistrar ¶
TestCallbackRegistrar(model_spec: ModelSpec, log: Logger | None = None, update_batch_period: Any = None)
Callback registrar implementation for module unit tests.
Source code in dp3/testing/registrar.py
get_scheduler_job ¶
Return a registered scheduler job by id, callable, or callable name.
Source code in dp3/testing/registrar.py
resolve_config_dir ¶
Return an absolute DP3 config directory path.
Explicit config_dir values take precedence. If no explicit path is supplied, the path is
read from env_var.