|
| 1 | +import logging |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from agents.util._transforms import transform_string_function_style |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.parametrize( |
| 9 | + ("name", "transformed"), |
| 10 | + [ |
| 11 | + ("My Tool", "my_tool"), |
| 12 | + ("My-Tool", "my_tool"), |
| 13 | + ], |
| 14 | +) |
| 15 | +def test_transform_string_function_style_warns_for_replaced_characters( |
| 16 | + caplog: pytest.LogCaptureFixture, |
| 17 | + name: str, |
| 18 | + transformed: str, |
| 19 | +) -> None: |
| 20 | + with caplog.at_level(logging.WARNING, logger="openai.agents"): |
| 21 | + assert transform_string_function_style(name) == transformed |
| 22 | + |
| 23 | + assert f"Tool name {name!r} contains invalid characters" in caplog.text |
| 24 | + assert f"transformed to {transformed!r}" in caplog.text |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.parametrize( |
| 28 | + ("name", "transformed"), |
| 29 | + [ |
| 30 | + ("MyTool", "mytool"), |
| 31 | + ("transfer_to_Agent", "transfer_to_agent"), |
| 32 | + ("snake_case", "snake_case"), |
| 33 | + ], |
| 34 | +) |
| 35 | +def test_transform_string_function_style_does_not_warn_for_case_only_changes( |
| 36 | + caplog: pytest.LogCaptureFixture, |
| 37 | + name: str, |
| 38 | + transformed: str, |
| 39 | +) -> None: |
| 40 | + with caplog.at_level(logging.WARNING, logger="openai.agents"): |
| 41 | + assert transform_string_function_style(name) == transformed |
| 42 | + |
| 43 | + assert caplog.records == [] |
0 commit comments