citeformer.backends.mock¶
Scripted backend used in unit tests.
MockBackend emits predetermined responses given a prompt; unknown prompts fall
back to a deterministic echo that respects the source-id range. It lets the
orchestration layer be tested end-to-end without loading a real model.
Module Contents¶
Classes¶
Scripted backend for tests. |
API¶
- class citeformer.backends.mock.MockBackend(responses: dict[str, str] | None = None)¶
Bases:
citeformer.backends.base.BackendScripted backend for tests.
Construct with a
responsesmapping from prompt to pre-canned output. Any prompt not in the mapping gets a deterministic echo of the form"Mock response for: <prompt> [1]."— which satisfies theREQUIREDpolicy trivially when at least one source is in scope. The marker in the fallback honours themarker_styleoption so tests for non-bracket styles see the right delimiters in the echoed output.Attributes: responses: Pre-canned responses keyed by exact prompt string.
Initialization
Construct a MockBackend.
Args: responses: Optional mapping from prompt to canned response.
- generate(prompt: str, sources: list[citeformer.core.Source], policy: citeformer.core.Policy, **options: Any) str¶
Return a scripted response or a deterministic fallback.
The fallback echo emits a marker (shape determined by the
marker_styleoption, default[1]) when sources are in scope, so that downstream parsers and verifiers see at least one citation. When there are no sources, it returns the echo with no marker regardless of policy — the caller is responsible for not invokinggenerate()with an empty source list underREQUIRED.
- stream(prompt: str, sources: list[citeformer.core.Source], policy: citeformer.core.Policy, **options: Any) collections.abc.Iterator[str]¶
Yield the mock response in small chunks to exercise stream consumers.
Splits the scripted response at word boundaries so downstream streaming tests see more than one chunk without relying on tokenizer behavior.