Skip to content

Commit 9a75973

Browse files
fix tests and mypy
1 parent b9d1f50 commit 9a75973

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

python/packages/azure-ai/tests/test_azure_ai_agent_client.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -623,24 +623,6 @@ async def test_azure_ai_chat_client_prepare_options_with_auto_tool_choice(
623623
assert run_options["tool_choice"] == AgentsToolChoiceOptionMode.AUTO
624624

625625

626-
async def test_azure_ai_chat_client_prepare_tool_choice_none_string(
627-
mock_agents_client: MagicMock,
628-
) -> None:
629-
"""Test _prepare_tool_choice when tool_choice is string 'none'."""
630-
chat_client = create_test_azure_ai_chat_client(mock_agents_client)
631-
632-
# Create a mock tool for testing
633-
mock_tool = MagicMock()
634-
chat_options: ChatOptions = {"tools": [mock_tool], "tool_choice": "none"}
635-
636-
# Call the method
637-
chat_client._prepare_tool_choice(chat_options) # type: ignore
638-
639-
# Verify tools are cleared and tool_choice is set to NONE mode
640-
assert chat_options.get("tools") is None
641-
assert chat_options.get("tool_choice") == ToolMode.NONE.mode
642-
643-
644626
async def test_azure_ai_chat_client_prepare_options_tool_choice_required_specific_function(
645627
mock_agents_client: MagicMock,
646628
) -> None:
@@ -651,7 +633,7 @@ async def test_azure_ai_chat_client_prepare_options_tool_choice_required_specifi
651633

652634
dict_tool = {"type": "function", "function": {"name": "test_function"}}
653635

654-
chat_options: ChatOptions = {"tools": [dict_tool], "tool_choice": required_tool_mode}
636+
chat_options = {"tools": [dict_tool], "tool_choice": required_tool_mode}
655637
messages = [ChatMessage(role=Role.USER, text="Hello")]
656638

657639
run_options, _ = await chat_client._prepare_options(messages, chat_options) # type: ignore

python/packages/core/agent_framework/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2497,7 +2497,7 @@ def prepare_messages(
24972497
def prepend_instructions_to_messages(
24982498
messages: list[ChatMessage],
24992499
instructions: str | Sequence[str] | None,
2500-
role: Role | Literal["system", "user", "assistant", "developer"] = "system",
2500+
role: Role | Literal["system", "user", "assistant"] = "system",
25012501
) -> list[ChatMessage]:
25022502
"""Prepend instructions to a list of messages with a specified role.
25032503

python/packages/core/tests/core/test_clients.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,18 @@ async def test_chat_client_instructions_handling(chat_client_base: ChatClientPro
5353
mock_inner_get_response.assert_called_once()
5454
_, kwargs = mock_inner_get_response.call_args
5555
messages = kwargs.get("messages", [])
56-
assert len(messages) == 2
57-
assert messages[0].role == Role.SYSTEM
58-
assert messages[0].text == instructions
59-
assert messages[1].role == Role.USER
60-
assert messages[1].text == "hello"
56+
assert len(messages) == 1
57+
assert messages[0].role == Role.USER
58+
assert messages[0].text == "hello"
59+
60+
from agent_framework._types import prepend_instructions_to_messages
61+
62+
appended_messages = prepend_instructions_to_messages(
63+
[ChatMessage(role=Role.USER, text="hello")],
64+
instructions,
65+
)
66+
assert len(appended_messages) == 2
67+
assert appended_messages[0].role == Role.SYSTEM
68+
assert appended_messages[0].text == "You are a helpful assistant."
69+
assert appended_messages[1].role == Role.USER
70+
assert appended_messages[1].text == "hello"

python/packages/core/tests/core/test_types.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,19 +1470,21 @@ def test_chat_message_from_dict_with_mixed_content():
14701470
assert len(message_dict["contents"]) == 3
14711471

14721472

1473-
def test_chat_options_edge_cases():
1473+
async def test_chat_options_edge_cases():
14741474
"""Test ChatOptions edge cases for better coverage."""
14751475
from agent_framework import validate_tool_mode, validate_tools
14761476

1477-
# Test with tools conversion
1477+
# Test with tools conversion - validate_tools converts callables to AIFunction
14781478
def sample_tool():
14791479
return "test"
14801480

14811481
options: ChatOptions = {"tools": [sample_tool], "tool_choice": "auto"}
1482+
1483+
# validate_tool_mode handles tool_choice validation
14821484
assert validate_tool_mode(options.get("tool_choice")) == ToolMode.AUTO
14831485

1484-
# Validate tools is a list
1485-
validated_tools = validate_tools(options.get("tools"))
1486+
# validate_tools handles tools validation and normalization (async)
1487+
validated_tools = await validate_tools(options.get("tools"))
14861488
assert validated_tools is not None
14871489
assert len(validated_tools) == 1
14881490

0 commit comments

Comments
 (0)