Update test_stream_agent.py

This commit is contained in:
2026-05-18 10:52:50 +00:00
parent 7667e99d7f
commit 68181be0ce
+18 -12
View File
@@ -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)