teff.testing¶
teff.testing
¶
Offline test doubles for LLM-backed nodes and the harness transport.
teff.testing is a companion for writing fast, offline tests of
graphs that contain :class:~teff.node.llm.LLM or
:class:~teff.node.agent.ReActAgent nodes. It provides two layers:
-
:class:
FakeLLM— a drop-in :class:~teff.node.Nodesubclass that answers with a canned string instead of calling a model. Use it to build a graph whose model behaviour is fully deterministic. -
:func:
mock_llm— a pytest fixture that patches :class:~teff.harness.Harnessso realLLM/ReActAgentnodes (including YAML-loaded workflows) run without network. The fixture returns a :class:MockLLMrecord of every request.
No API keys or network access are required by either layer.
Classes:
| Name | Description |
|---|---|
FakeLLM |
An LLM node that returns a canned reply without any transport. |
MockLLM |
Canned transport recording every model request. |
Functions:
| Name | Description |
|---|---|
canned_json |
Return value formatted as a JSON string an LLM might output. |
mock_llm |
Run |
FakeLLM
¶
Bases: Node
An LLM node that returns a canned reply without any transport.
Mirrors the LLM node contract for the common cases: system
and prompt templates are rendered from state, and the reply is
written under output_key. content (default "mock")
may itself be a {key} template.
Examples:
A graph with a single deterministic LLM step::
from teff.testing import FakeLLM
graph = Graph(
nodes={"answer": FakeLLM({"prompt": "hi {name}", "content": "hello {name}"})},
edges=[],
entry_point="answer",
)
Source code in teff/testing.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
MockLLM
¶
Canned transport recording every model request.
Instances expose content (the text every reply carries) and
tool_calls (optional structured tool calls to attach), plus
calls — the list of request bodies Harness built. This
lets assertions inspect prompts, model names, and tool schemas sent
to the "model".
Source code in teff/testing.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
canned_json
¶
canned_json(value)
Return value formatted as a JSON string an LLM might output.
Source code in teff/testing.py
127 128 129 | |
mock_llm
¶
mock_llm(monkeypatch)
Run LLM / ReActAgent nodes offline with canned replies.
Patches :class:~teff.harness.Harness transport so any graph —
built programmatically or loaded from YAML — never touches the
network. Returns a :class:MockLLM with content and
tool_calls you can adjust mid-test and calls for
assertions on the request bodies.
Example::
async def test_flow(mock_llm):
mock_llm.content = "42"
graph = ...
result = await graph.run(state={...})
Source code in teff/testing.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |