Skip to content

Commit 0d22fc4

Browse files
authored
More robust tests (#2575)
1 parent a5b8418 commit 0d22fc4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

integrations/openrouter/tests/test_openrouter_chat_generator.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def test_live_run_with_tools(self, tools):
339339
tool_call = message.tool_call
340340
assert isinstance(tool_call, ToolCall)
341341
assert tool_call.tool_name == "weather"
342-
assert tool_call.arguments == {"city": "Paris"}
342+
assert "paris" in tool_call.arguments["city"].lower(), f"Expected 'paris' in city: {tool_call.arguments}"
343343
assert message.meta["finish_reason"] == "tool_calls"
344344

345345
@pytest.mark.skipif(
@@ -371,7 +371,12 @@ def test_live_run_with_tools_and_response(self, tools):
371371
assert tool_call.tool_name == "weather"
372372

373373
arguments = [tool_call.arguments for tool_call in tool_calls]
374-
assert sorted(arguments, key=lambda x: x["city"]) == [{"city": "Berlin"}, {"city": "Paris"}]
374+
# Extract city names and check they contain the expected cities
375+
# (LLM may return "Paris, France" or "Berlin, Germany" instead of just city names)
376+
cities = [arg["city"].lower() for arg in arguments]
377+
assert len(cities) == 2
378+
assert any("berlin" in city for city in cities), f"Expected 'berlin' in one of {cities}"
379+
assert any("paris" in city for city in cities), f"Expected 'paris' in one of {cities}"
375380
assert tool_message.meta["finish_reason"] == "tool_calls"
376381

377382
new_messages = [
@@ -453,10 +458,9 @@ def test_pipeline_with_openrouter_chat_generator(self, tools):
453458
}
454459
)
455460

456-
assert (
457-
"The weather in Paris is sunny and 32°C"
458-
== results["tool_invoker"]["tool_messages"][0].tool_call_result.result
459-
)
461+
result = results["tool_invoker"]["tool_messages"][0].tool_call_result.result
462+
assert "paris" in result.lower(), f"Expected 'paris' in result: {result}"
463+
assert "sunny and 32°c" in result.lower(), f"Expected 'sunny and 32°c' in result: {result}"
460464

461465
@pytest.mark.skipif(
462466
not os.environ.get("OPENROUTER_API_KEY", None),

integrations/openrouter/tests/test_openrouter_chat_generator_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async def test_live_run_with_tools_and_response_async(self, tools):
198198
tool_call = tool_message.tool_call
199199
assert tool_call.id, "Tool call does not contain value for 'id' key"
200200
assert tool_call.tool_name == "weather"
201-
assert tool_call.arguments == {"city": "Paris"}
201+
assert "paris" in tool_call.arguments["city"].lower(), f"Expected 'paris' in city: {tool_call.arguments}"
202202
assert tool_message.meta["finish_reason"] == "tool_calls"
203203

204204
new_messages = [
@@ -260,7 +260,7 @@ async def callback(chunk: StreamingChunk):
260260
tool_call = tool_message.tool_call
261261
assert tool_call.id, "Tool call does not contain value for 'id' key"
262262
assert tool_call.tool_name == "weather"
263-
assert tool_call.arguments == {"city": "Paris"}
263+
assert "paris" in tool_call.arguments["city"].lower(), f"Expected 'paris' in city: {tool_call.arguments}"
264264
assert tool_message.meta["finish_reason"] == "tool_calls"
265265

266266
@pytest.mark.skipif(
@@ -314,7 +314,7 @@ def echo_function(text: str) -> str:
314314

315315
# Pass mixed list: echo_tool (individual) and toolset (weather + time) at runtime
316316
# This tests that both individual tools and toolsets can be combined
317-
messages = [ChatMessage.from_user("Echo this: Hello World")]
317+
messages = [ChatMessage.from_user("Echo this via tool: Hello World")]
318318
results = await component.run_async(messages, tools=[echo_tool, toolset])
319319

320320
assert len(results["replies"]) == 1

0 commit comments

Comments
 (0)