ds_common_placeholder_py_lib.testing ==================================== .. py:module:: ds_common_placeholder_py_lib.testing .. autoapi-nested-parse:: **File:** ``testing.py`` **Region:** ``ds-common-placeholder-py-lib`` Description ----------- Test helpers, for tests and offline tooling. Not for code that serves runs. Classes ------- .. autoapisummary:: ds_common_placeholder_py_lib.testing.FakeVault Functions --------- .. autoapisummary:: ds_common_placeholder_py_lib.testing.fake_vault ds_common_placeholder_py_lib.testing.fixed_now Module Contents --------------- .. py:class:: FakeVault What :func:`fake_vault` serves, and every key it was asked for. .. py:attribute:: values :type: dict[str, bytes | str | Exception] .. py:attribute:: default :type: bytes | str | None :value: None .. py:attribute:: reads :type: list[str] :value: [] .. py:method:: read(key: str) -> bytes | str | None .. py:function:: fake_vault(values: collections.abc.Mapping[str, bytes | str | Exception] | None = None, *, default: bytes | str | None = None) -> collections.abc.Iterator[FakeVault] Replace ds-vault while the block runs. .. code-block:: python ctx = Context.from_values({"tenant_id": "t1", "db": {"pw": "@{get_secret, /ds/vault/s/t1/k/prod}"}}) with fake_vault({"/ds/vault/s/t1/k/prod": b"c2VjcmV0"}) as vault: ctx.resolve("db.pw") assert vault.reads == ["/ds/vault/s/t1/k/prod"] The tenant check still runs first, so a key of another tenant never reaches the fake. The fake applies only to the current thread or async task (a context variable); threads started inside the block do not see it, and other threads keep reading ds-vault. Code that resolves in a thread pool needs the context passed along, for example ``executor.submit(contextvars.copy_context().run, fn)``. :param values: Vault key to stored value. An exception value is raised, to simulate a failing read. :param default: Value for keys not in *values*; ``None`` means not found. :Yields: The fake, with ``reads`` recording every key read. .. py:function:: fixed_now(at: str | datetime.datetime) -> collections.abc.Iterator[None] Make the current time *at* while the block runs: for the date functions given no time, and ``get_iso_timestamp_now`` and ``get_unix_timestamp_now``. .. code-block:: python ctx = Context.from_values({"tenant_id": "t1", "run": {"at": "@{get_unix_timestamp_now}"}}) with fixed_now("2026-11-03T10:15:30Z"): ctx.resolve("run.at") # 1793700930 A date function given a time (``@{get_hour, UTC, run.logical_at}``) is unaffected. Like :func:`fake_vault`, it applies to the current thread or async task only, and nests. A thread started inside the block reads the real time; pass the context along, e.g. ``executor.submit(contextvars.copy_context().run, fn)``. :param at: An aware datetime, or an ISO 8601 string with a UTC offset. :raises ValueError: If *at* has no UTC offset.