Skip to content

Commit 5b20085

Browse files
committed
style: run autoformat.sh
1 parent 45cf164 commit 5b20085

3 files changed

Lines changed: 55 additions & 55 deletions

File tree

src/google/adk/models/lite_llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def _safe_json_serialize(obj) -> str:
547547
try:
548548
return str(obj)
549549
except RecursionError:
550-
return '<non-serializable: recursion depth exceeded>'
550+
return "<non-serializable: recursion depth exceeded>"
551551

552552

553553
def _part_has_payload(part: types.Part) -> bool:

tests/unittests/models/test_litellm_safe_serialize.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,47 @@
2121
Fixes https://github.com/google/adk-python/issues/5412
2222
"""
2323

24-
import pytest
25-
2624
from google.adk.models.lite_llm import _safe_json_serialize
25+
import pytest
2726

2827

2928
def test_circular_reference_returns_str_fallback():
30-
"""json.dumps raises ValueError on circular references; should fall back to str()."""
29+
"""json.dumps raises ValueError on circular references; should fall back to str()."""
30+
31+
class Node:
3132

32-
class Node:
33-
def __init__(self):
34-
self.ref = self
33+
def __init__(self):
34+
self.ref = self
3535

36-
obj = Node()
37-
result = _safe_json_serialize(obj)
38-
assert isinstance(result, str)
39-
# Should return str(obj) fallback rather than raising ValueError
36+
obj = Node()
37+
result = _safe_json_serialize(obj)
38+
assert isinstance(result, str)
39+
# Should return str(obj) fallback rather than raising ValueError
4040

4141

4242
def test_deeply_nested_structure_returns_str_fallback():
43-
"""json.dumps raises RecursionError on deeply nested structures."""
44-
obj = current = {}
45-
for _ in range(10000):
46-
current["child"] = {}
47-
current = current["child"]
43+
"""json.dumps raises RecursionError on deeply nested structures."""
44+
obj = current = {}
45+
for _ in range(10000):
46+
current["child"] = {}
47+
current = current["child"]
4848

49-
result = _safe_json_serialize(obj)
50-
assert isinstance(result, str)
51-
# str(obj) itself can raise RecursionError, so expect the safe fallback
52-
assert "recursion" in result.lower() or result # non-empty string
49+
result = _safe_json_serialize(obj)
50+
assert isinstance(result, str)
51+
# str(obj) itself can raise RecursionError, so expect the safe fallback
52+
assert "recursion" in result.lower() or result # non-empty string
5353

5454

5555
def test_normal_dict_serializes():
56-
"""Normal dicts should serialize as JSON."""
57-
result = _safe_json_serialize({"key": "value", "num": 42})
58-
assert '"key"' in result
59-
assert '"value"' in result
56+
"""Normal dicts should serialize as JSON."""
57+
result = _safe_json_serialize({"key": "value", "num": 42})
58+
assert '"key"' in result
59+
assert '"value"' in result
6060

6161

6262
def test_non_serializable_object_falls_back_to_str():
63-
"""Objects without a JSON representation should fall back to str()."""
64-
obj = object()
65-
result = _safe_json_serialize(obj)
66-
assert isinstance(result, str)
67-
assert "object" in result.lower()
63+
"""Objects without a JSON representation should fall back to str()."""
64+
obj = object()
65+
result = _safe_json_serialize(obj)
66+
assert isinstance(result, str)
67+
assert "object" in result.lower()

tests/unittests/telemetry/test_safe_json_serialize.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,45 @@
2121
Fixes https://github.com/google/adk-python/issues/5411
2222
"""
2323

24-
import pytest
25-
2624
from google.adk.telemetry.tracing import _safe_json_serialize
25+
import pytest
2726

2827

2928
def test_circular_reference_returns_fallback():
30-
"""json.dumps raises ValueError on circular references; should not propagate."""
29+
"""json.dumps raises ValueError on circular references; should not propagate."""
30+
31+
class Node:
3132

32-
class Node:
33-
def __init__(self):
34-
self.ref = self
33+
def __init__(self):
34+
self.ref = self
3535

36-
obj = Node()
37-
result = _safe_json_serialize(obj)
38-
assert isinstance(result, str)
39-
# Should return the fallback rather than raising
40-
assert "not serializable" in result.lower() or result # non-empty string
36+
obj = Node()
37+
result = _safe_json_serialize(obj)
38+
assert isinstance(result, str)
39+
# Should return the fallback rather than raising
40+
assert "not serializable" in result.lower() or result # non-empty string
4141

4242

4343
def test_deeply_nested_structure_returns_fallback():
44-
"""json.dumps raises RecursionError on deeply nested structures."""
45-
obj = current = {}
46-
for _ in range(10000):
47-
current["child"] = {}
48-
current = current["child"]
44+
"""json.dumps raises RecursionError on deeply nested structures."""
45+
obj = current = {}
46+
for _ in range(10000):
47+
current["child"] = {}
48+
current = current["child"]
4949

50-
result = _safe_json_serialize(obj)
51-
assert isinstance(result, str)
50+
result = _safe_json_serialize(obj)
51+
assert isinstance(result, str)
5252

5353

5454
def test_normal_dict_serializes():
55-
"""Normal dicts should serialize without issue."""
56-
result = _safe_json_serialize({"key": "value", "num": 42})
57-
assert '"key"' in result
58-
assert '"value"' in result
55+
"""Normal dicts should serialize without issue."""
56+
result = _safe_json_serialize({"key": "value", "num": 42})
57+
assert '"key"' in result
58+
assert '"value"' in result
5959

6060

6161
def test_non_serializable_object_uses_default():
62-
"""Objects without a JSON representation use the default callback."""
63-
result = _safe_json_serialize(object())
64-
assert isinstance(result, str)
65-
assert "not serializable" in result.lower()
62+
"""Objects without a JSON representation use the default callback."""
63+
result = _safe_json_serialize(object())
64+
assert isinstance(result, str)
65+
assert "not serializable" in result.lower()

0 commit comments

Comments
 (0)