-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathtest_span_data.py
More file actions
67 lines (55 loc) · 2.45 KB
/
test_span_data.py
File metadata and controls
67 lines (55 loc) · 2.45 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
"""Tests for span data export methods."""
from __future__ import annotations
import pytest
from agents.tracing.span_data import FunctionSpanData
class TestFunctionSpanDataExport:
"""FunctionSpanData.export() must preserve output values faithfully."""
def test_dict_output_preserved_as_dict(self) -> None:
"""Dict outputs should stay as dicts, not be converted to Python repr strings."""
span = FunctionSpanData(name="my_tool", input="query", output={"key": "value", "n": 42})
exported = span.export()
assert exported["output"] == {"key": "value", "n": 42}
assert isinstance(exported["output"], dict)
def test_string_output_preserved(self) -> None:
span = FunctionSpanData(name="my_tool", input="query", output="hello world")
exported = span.export()
assert exported["output"] == "hello world"
def test_none_output_preserved(self) -> None:
span = FunctionSpanData(name="my_tool", input="query", output=None)
exported = span.export()
assert exported["output"] is None
@pytest.mark.parametrize(
"output",
[0, False, "", []],
ids=["zero", "false", "empty_str", "empty_list"],
)
def test_falsy_output_not_converted_to_none(self, output: object) -> None:
"""Falsy but valid outputs (0, False, '', []) must not become None."""
span = FunctionSpanData(name="my_tool", input="query", output=output)
exported = span.export()
assert exported["output"] is not None
assert exported["output"] == output
def test_list_output_preserved(self) -> None:
span = FunctionSpanData(name="my_tool", input="query", output=[1, 2, 3])
exported = span.export()
assert exported["output"] == [1, 2, 3]
assert isinstance(exported["output"], list)
def test_numeric_output_preserved(self) -> None:
span = FunctionSpanData(name="my_tool", input="query", output=42)
exported = span.export()
assert exported["output"] == 42
def test_export_includes_all_fields(self) -> None:
span = FunctionSpanData(
name="my_tool",
input="query",
output="result",
mcp_data={"server": "test"},
)
exported = span.export()
assert exported == {
"type": "function",
"name": "my_tool",
"input": "query",
"output": "result",
"mcp_data": {"server": "test"},
}