Skip to content

Commit 6315c3b

Browse files
lionpelouxclaude
andcommitted
Refactor test to use inline code instead of create_module
As suggested by @DouweM, the test now defines classes directly inline instead of using the create_module helper with a string, since we're not dynamically generating code. Note: The snapshot changed because inline classes have their function scope in the qualified name, resulting in a longer sanitized tool name. This still correctly tests bracket sanitization. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f16acbc commit 6315c3b

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

tests/test_agent.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -636,30 +636,26 @@ def validate_output(ctx: RunContext[None], o: Any) -> Any:
636636
assert got_tool_call_name == snapshot('final_result_Bar')
637637

638638

639-
def test_output_type_generic_class_name_sanitization(create_module: Callable[[str], Any]):
639+
def test_output_type_generic_class_name_sanitization():
640640
"""Test that generic class names with brackets are properly sanitized."""
641-
module_code = '''
642-
from pydantic import BaseModel
643-
from typing import Generic, TypeVar
641+
from typing import Generic, TypeVar
644642

645-
T = TypeVar('T')
643+
T = TypeVar('T')
646644

647-
class Result(BaseModel, Generic[T]):
648-
"""A generic result class."""
649-
value: T
650-
success: bool
645+
class Result(BaseModel, Generic[T]):
646+
"""A generic result class."""
651647

652-
class StringData(BaseModel):
653-
text: str
648+
value: T
649+
success: bool
654650

655-
# This will have a name like "Result[StringData]" which needs sanitization
656-
OutputType = [Result[StringData], Result[int]]
657-
'''
651+
class StringData(BaseModel):
652+
text: str
658653

659-
mod = create_module(module_code)
654+
# This will have a name like "Result[StringData]" which needs sanitization
655+
output_type = [Result[StringData], Result[int]]
660656

661657
m = TestModel()
662-
agent = Agent(m, output_type=mod.OutputType)
658+
agent = Agent(m, output_type=output_type)
663659
agent.run_sync('Hello')
664660

665661
# The sanitizer should remove brackets from the generic type name
@@ -668,7 +664,12 @@ class StringData(BaseModel):
668664
assert len(m.last_model_request_parameters.output_tools) == 2
669665

670666
tool_names = [tool.name for tool in m.last_model_request_parameters.output_tools]
671-
assert tool_names == snapshot(['final_result_ResultStringData', 'final_result_Resultint'])
667+
assert tool_names == snapshot(
668+
[
669+
'final_result_Resulttest_output_type_generic_class_name_sanitizationlocalsStringData',
670+
'final_result_Resultint',
671+
]
672+
)
672673

673674

674675
def test_output_type_with_two_descriptions():

0 commit comments

Comments
 (0)