Skip to content

Commit a40c91b

Browse files
author
Salma Elshafey
committed
Modify other test file to match the new output format
1 parent e4b1a37 commit a40c91b

File tree

1 file changed

+70
-92
lines changed

1 file changed

+70
-92
lines changed

sdk/evaluation/azure-ai-evaluation/tests/unittests/test_agent_evaluators.py

Lines changed: 70 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,109 +9,87 @@ class TestEvaluate:
99
def test_tool_call_accuracy_evaluator_missing_inputs(self, mock_model_config):
1010
tool_call_accuracy = ToolCallAccuracyEvaluator(model_config=mock_model_config)
1111

12-
# Test tool_calls provided but missing response
13-
with pytest.raises(EvaluationException) as exc_info:
14-
tool_call_accuracy(
15-
query="Where is the Eiffel Tower?",
16-
response="The Eiffel Tower is in Paris.",
17-
tool_calls="Test",
18-
tool_definitions={
19-
"name": "fetch_weather",
20-
"description": "Fetches the weather information for the specified location.",
21-
"parameters": {
22-
"type": "object",
23-
"properties": {
24-
"location": {
25-
"type": "string",
26-
"description": "The location to fetch weather for."
27-
}
12+
# Test with missing tool_calls and response
13+
result = tool_call_accuracy(
14+
query="Where is the Eiffel Tower?",
15+
tool_definitions=[{
16+
"name": "fetch_weather",
17+
"description": "Fetches the weather information for the specified location.",
18+
"parameters": {
19+
"type": "object",
20+
"properties": {
21+
"location": {
22+
"type": "string",
23+
"description": "The location to fetch weather for."
2824
}
2925
}
3026
}
31-
)
27+
}]
28+
)
29+
assert not result["applicable"]
30+
assert result["tool_call_accurate"] == "not applicable"
31+
assert "No tool calls found in response or provided tool_calls." in result["tool_call_accurate_reason"]
3232

3333
# Test with missing tool_definitions
34-
with pytest.raises(EvaluationException) as exc_info:
35-
tool_call_accuracy(
36-
query="Where is the Eiffel Tower?",
37-
tool_calls={
38-
"type": "tool_call",
39-
"tool_call": {
40-
"id": "call_K21dwOxgCN2syn4qjutMVV7Z",
41-
"type": "function",
42-
"function": {
43-
"name": "fetch_weather",
44-
"arguments": {
45-
"location": "Tokyo"
46-
}
47-
}
48-
}
34+
result = tool_call_accuracy(
35+
query="Where is the Eiffel Tower?",
36+
tool_definitions=[],
37+
tool_calls=[{
38+
"type": "tool_call",
39+
"name": "fetch_weather",
40+
"arguments": {
41+
"location": "Tokyo"
4942
}
50-
)
51-
assert "Tool definitions must be provided." in str(exc_info.value)
52-
53-
# Test with missing tool_cools
54-
with pytest.raises(EvaluationException) as exc_info:
55-
tool_call_accuracy(
56-
query="Where is the Eiffel Tower?",
57-
tool_definitions={
58-
"name": "fetch_weather",
59-
"description": "Fetches the weather information for the specified location.",
60-
"parameters": {
61-
"type": "object",
62-
"properties": {
63-
"location": {
64-
"type": "string",
65-
"description": "The location to fetch weather for."
66-
}
67-
}
68-
}
69-
}
70-
)
43+
}]
44+
)
45+
assert not result["applicable"]
46+
assert result["tool_call_accurate"] == "not applicable"
47+
assert "Tool definitions must be provided." in result["tool_call_accurate_reason"]
7148

72-
assert "Either response or tool_calls must be provided." in str(exc_info.value)
73-
74-
# Test response provided but missing tool_calls
75-
with pytest.raises(EvaluationException) as exc_info:
76-
tool_call_accuracy(
77-
query="Where is the Eiffel Tower?",
78-
response="The Eiffel Tower is in Paris.",
79-
tool_definitions={
80-
"name": "fetch_weather",
81-
"description": "Fetches the weather information for the specified location.",
82-
"parameters": {
83-
"type": "object",
84-
"properties": {
85-
"location": {
86-
"type": "string",
87-
"description": "The location to fetch weather for."
88-
}
49+
# Test with response that has no tool calls
50+
result = tool_call_accuracy(
51+
query="Where is the Eiffel Tower?",
52+
response="The Eiffel Tower is in Paris.",
53+
tool_definitions=[{
54+
"name": "fetch_weather",
55+
"description": "Fetches the weather information for the specified location.",
56+
"parameters": {
57+
"type": "object",
58+
"properties": {
59+
"location": {
60+
"type": "string",
61+
"description": "The location to fetch weather for."
8962
}
9063
}
9164
}
92-
)
93-
94-
assert "response does not have tool calls. Either provide tool_calls or response with tool calls." in str(exc_info.value)
65+
}]
66+
)
67+
assert not result["applicable"]
68+
assert result["tool_call_accurate"] == "not applicable"
69+
assert "No tool calls found in response or provided tool_calls." in result["tool_call_accurate_reason"]
9570

96-
# Test tool_calls provided but missing response
97-
with pytest.raises(EvaluationException) as exc_info:
98-
tool_call_accuracy(
99-
query="Where is the Eiffel Tower?",
100-
response="The Eiffel Tower is in Paris.",
101-
tool_calls="Test",
102-
tool_definitions={
103-
"name": "fetch_weather",
104-
"description": "Fetches the weather information for the specified location.",
105-
"parameters": {
106-
"type": "object",
107-
"properties": {
108-
"location": {
109-
"type": "string",
110-
"description": "The location to fetch weather for."
111-
}
71+
# Test with tool call for which definition is not provided
72+
result = tool_call_accuracy(
73+
query="Where is the Eiffel Tower?",
74+
tool_calls=[{
75+
"type": "tool_call",
76+
"name": "some_other_tool",
77+
"arguments": {}
78+
}],
79+
tool_definitions=[{
80+
"name": "fetch_weather",
81+
"description": "Fetches the weather information for the specified location.",
82+
"parameters": {
83+
"type": "object",
84+
"properties": {
85+
"location": {
86+
"type": "string",
87+
"description": "The location to fetch weather for."
11288
}
11389
}
11490
}
115-
)
116-
117-
assert "Tool definition not found" in str(exc_info.value)
91+
}]
92+
)
93+
assert not result["applicable"]
94+
assert result["tool_call_accurate"] == "not applicable"
95+
assert "Tool definitions for all tool calls must be provided." in result["tool_call_accurate_reason"]

0 commit comments

Comments
 (0)