-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathtest_serialization.py
More file actions
73 lines (56 loc) · 2.12 KB
/
Copy pathtest_serialization.py
File metadata and controls
73 lines (56 loc) · 2.12 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
"""Tests for the shared serialize_tool_args helper.
Covers plain dicts, dicts containing Python Enums (the SecuritySchemeType
scenario), dicts containing Pydantic models, non-dict values, and edge cases.
"""
import enum
import json
from pydantic import BaseModel
from ag_ui_adk.serialization import serialize_tool_args
class FakeSecuritySchemeType(enum.Enum):
oauth2 = "oauth2"
apiKey = "apiKey"
class NestedModel(BaseModel):
url: str
scheme_type: FakeSecuritySchemeType
class TestSerializeToolArgs:
def test_plain_dict(self):
args = {"city": "Seattle", "units": "metric"}
result = serialize_tool_args(args)
assert json.loads(result) == args
def test_dict_with_enum_value(self):
"""Regression (#1331): SecuritySchemeType-like enums must not raise TypeError."""
args = {
"auth_type": FakeSecuritySchemeType.oauth2,
"scopes": ["read", "write"],
}
result = serialize_tool_args(args)
parsed = json.loads(result)
assert parsed["auth_type"] == "oauth2"
assert parsed["scopes"] == ["read", "write"]
def test_dict_with_pydantic_model_value(self):
args = {
"endpoint": NestedModel(
url="https://example.com",
scheme_type=FakeSecuritySchemeType.apiKey,
)
}
result = serialize_tool_args(args)
parsed = json.loads(result)
assert parsed["endpoint"]["url"] == "https://example.com"
assert parsed["endpoint"]["scheme_type"] == "apiKey"
def test_dict_with_nested_enum(self):
args = {
"config": {
"type": FakeSecuritySchemeType.oauth2,
"enabled": True,
}
}
result = serialize_tool_args(args)
parsed = json.loads(result)
assert parsed["config"]["type"] == "oauth2"
def test_string_args_passthrough(self):
assert serialize_tool_args("raw_string") == "raw_string"
def test_non_dict_non_string(self):
assert serialize_tool_args(42) == "42"
def test_empty_dict(self):
assert serialize_tool_args({}) == "{}"