(monkeypatch, capsys)
| 36 | |
| 37 | @pytest.mark.asyncio |
| 38 | async def test_run_demo_loop_streaming(monkeypatch, capsys): |
| 39 | model = FakeModel() |
| 40 | target_agent = Agent(name="target", model=model) |
| 41 | agent = Agent( |
| 42 | name="test", |
| 43 | model=model, |
| 44 | tools=[get_function_tool("foo", "tool_result")], |
| 45 | handoffs=[target_agent], |
| 46 | ) |
| 47 | |
| 48 | # A single user turn that exercises every streamed event branch: |
| 49 | # a tool call, the tool output, a handoff (agent update), then a text answer. |
| 50 | model.add_multiple_turn_outputs( |
| 51 | [ |
| 52 | [get_function_tool_call("foo", "{}")], |
| 53 | [get_handoff_tool_call(target_agent)], |
| 54 | [get_text_message("all done")], |
| 55 | ] |
| 56 | ) |
| 57 | |
| 58 | inputs = iter(["Hello", "exit"]) |
| 59 | monkeypatch.setattr("builtins.input", lambda _=" > ": next(inputs)) |
| 60 | |
| 61 | await run_demo_loop(agent, stream=True) |
| 62 | |
| 63 | output = capsys.readouterr().out |
| 64 | assert "all done" in output |
| 65 | assert "[tool called]" in output |
| 66 | assert "[tool output: tool_result]" in output |
| 67 | assert "[Agent updated: target]" in output |
| 68 | |
| 69 | |
| 70 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected