From 68181be0ce35a4ebefa5b9f966aa26c89d4085c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B8=D0=BD=D0=B0=D1=80=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D0=B8=D1=82=D0=BE=D0=B2?= Date: Mon, 18 May 2026 10:52:50 +0000 Subject: [PATCH] Update test_stream_agent.py --- test_stream_agent.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/test_stream_agent.py b/test_stream_agent.py index 901a0a2..f3d2cb8 100644 --- a/test_stream_agent.py +++ b/test_stream_agent.py @@ -1,18 +1,24 @@ -from stream_agent import StreamingAIAgent +from langchain_core.messages import AIMessage + +from stream_agent import format_message -def test_stream_returns_chunks(monkeypatch): - monkeypatch.delenv("OPENAI_API_KEY", raising=False) - agent = StreamingAIAgent() +def test_format_message_with_content(): + message = AIMessage(content="hello") - chunks = list(agent.stream("test question")) - - assert len(chunks) > 3 - assert "".join(chunks).strip() + assert format_message(message) == "hello" -def test_invoke_matches_stream(monkeypatch): - monkeypatch.delenv("OPENAI_API_KEY", raising=False) - agent = StreamingAIAgent() +def test_format_message_with_tool_call(): + message = AIMessage( + content="", + tool_calls=[ + { + "name": "get_demo_price", + "args": {"product": "молоко", "city": "Казань"}, + "id": "call-1", + } + ], + ) - assert agent.invoke("hello") == "".join(agent.stream("hello")) + assert "get_demo_price" in format_message(message)