Private
Public Access
test(api_events): migrate 2 sites to send_result() (Phase 2.8)
The test_send_emits_events_proper and test_send_emits_tool_events tests both call ai_client.send(). Migrating to send_result() + assert result.ok. Changes: - Rename ai_client.send(...) to ai_client.send_result(...) (2 sites) - Add assert result.ok (2 sites) - Add "from src.result_types import Result" import 4 tests pass.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
from src import ai_client
|
from src import ai_client
|
||||||
|
from src.result_types import Result
|
||||||
|
|
||||||
|
|
||||||
class MockUsage:
|
class MockUsage:
|
||||||
@@ -60,7 +61,8 @@ def test_send_emits_events_proper() -> None:
|
|||||||
ai_client.events.on("request_start", start_callback)
|
ai_client.events.on("request_start", start_callback)
|
||||||
ai_client.events.on("response_received", response_callback)
|
ai_client.events.on("response_received", response_callback)
|
||||||
ai_client.set_provider("gemini", "gemini-2.5-flash-lite")
|
ai_client.set_provider("gemini", "gemini-2.5-flash-lite")
|
||||||
ai_client.send("context", "message", )
|
result = ai_client.send_result("context", "message", )
|
||||||
|
assert result.ok
|
||||||
assert start_callback.called
|
assert start_callback.called
|
||||||
assert response_callback.called
|
assert response_callback.called
|
||||||
args, kwargs = start_callback.call_args
|
args, kwargs = start_callback.call_args
|
||||||
@@ -103,5 +105,6 @@ def test_send_emits_tool_events() -> None:
|
|||||||
tool_callback(*args, **kwargs)
|
tool_callback(*args, **kwargs)
|
||||||
|
|
||||||
ai_client.events.on("tool_execution", debug_tool)
|
ai_client.events.on("tool_execution", debug_tool)
|
||||||
result = ai_client.send("context", "message", enable_tools=True)
|
result = ai_client.send_result("context", "message", enable_tools=True)
|
||||||
|
assert result.ok
|
||||||
assert tool_callback.call_count >= 1
|
assert tool_callback.call_count >= 1
|
||||||
|
|||||||
Reference in New Issue
Block a user