-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_runner_abcs.py
More file actions
78 lines (55 loc) · 2.19 KB
/
test_runner_abcs.py
File metadata and controls
78 lines (55 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pytest
from ldai.providers import AgentGraphResult, AgentGraphRunner, ToolRegistry
from ldai.providers.types import LDAIMetrics, RunnerResult
# --- Concrete test doubles ---
class ConcreteAgentGraphRunner:
async def run(self, input):
return AgentGraphResult(
output=f"graph response to: {input}",
raw={"raw": input},
metrics=LDAIMetrics(success=True),
)
class MissingRunMethod:
pass
@pytest.mark.asyncio
async def test_runner_result_fields():
metrics = LDAIMetrics(success=True)
result = RunnerResult(content="done", metrics=metrics, raw={"key": "val"})
assert result.content == "done"
assert result.raw == {"key": "val"}
assert result.metrics is metrics
# --- AgentGraphRunner ---
def test_agent_graph_runner_structural_check_passes():
assert isinstance(ConcreteAgentGraphRunner(), AgentGraphRunner)
def test_agent_graph_runner_structural_check_fails_when_run_missing():
assert not isinstance(MissingRunMethod(), AgentGraphRunner)
@pytest.mark.asyncio
async def test_agent_graph_runner_run_returns_agent_graph_result():
runner = ConcreteAgentGraphRunner()
result = await runner.run("hello graph")
assert isinstance(result, AgentGraphResult)
assert result.output == "graph response to: hello graph"
assert result.raw == {"raw": "hello graph"}
assert result.metrics.success is True
@pytest.mark.asyncio
async def test_agent_graph_result_fields():
metrics = LDAIMetrics(success=False)
result = AgentGraphResult(output="", raw=None, metrics=metrics)
assert result.output == ""
assert result.raw is None
assert result.metrics.success is False
# --- ToolRegistry ---
def test_tool_registry_is_dict_of_callables():
tools: ToolRegistry = {
"search": lambda q: f"results for {q}",
"calculator": lambda x: x * 2,
}
assert tools["search"]("python") == "results for python"
assert tools["calculator"](21) == 42
# --- Top-level exports ---
def test_top_level_exports():
import ldai
assert hasattr(ldai, 'AgentGraphRunner')
assert hasattr(ldai, 'AgentGraphResult')
assert hasattr(ldai, 'RunnerResult')
assert hasattr(ldai, 'ToolRegistry')