MCPcopy
hub / github.com/google/adk-python / test_cli_run_integration

Function test_cli_run_integration

tests/integration/test_cli_run.py:24–78  ·  view source on GitHub ↗

Integration test for `adk run` with query using CliRunner (No mocks).

(tmp_path: Path)

Source from the content-addressed store, hash-verified

22
23
24def test_cli_run_integration(tmp_path: Path) -> None:
25 """Integration test for `adk run` with query using CliRunner (No mocks)."""
26 # Arrange
27 agent_dir = tmp_path / "dummy_agent"
28 agent_dir.mkdir()
29
30 # Create __init__.py
31 with open(agent_dir / "__init__.py", "w") as f:
32 f.write("from . import agent\n")
33
34 # Create agent.py
35 agent_code = """
36from google.adk.agents import Agent
37from google.adk.events.event import Event
38from typing import AsyncGenerator
39
40class DummyAgent(Agent):
41 async def run_async(self, ctx) -> AsyncGenerator[Event, None]:
42 # Yield a text response
43 from google.adk.events.event import Event
44 text = ctx.user_content.parts[0].text if ctx.user_content and ctx.user_content.parts else "No input"
45 yield Event(author="dummy", output=f"Echo: {text}")
46
47root_agent = DummyAgent(name="dummy", model="gemini-2.5-flash")
48"""
49 with open(agent_dir / "agent.py", "w") as f:
50 f.write(agent_code)
51
52 runner = CliRunner()
53
54 # Act
55 result = runner.invoke(
56 cli_tools_click.main,
57 ["run", "--jsonl", str(agent_dir), "hello world"],
58 )
59
60 # Assert
61 assert result.exit_code == 0
62
63 # Check stdout
64 stdout = result.stdout
65 assert stdout, "Stdout should not be empty"
66
67 # Parse JSONL lines
68 lines = stdout.strip().split("\n")
69 assert len(lines) > 0
70
71 # The last line should be the final output or event
72 last_line = lines[-1]
73 try:
74 data = json.loads(last_line)
75 assert "output" in data
76 assert "Echo: hello world" in data["output"]
77 except json.JSONDecodeError:
78 pytest.fail(f"Stdout contained non-JSON line: {last_line}")

Callers

nothing calls this directly

Calls 5

openFunction · 0.85
splitMethod · 0.80
stripMethod · 0.80
writeMethod · 0.45
invokeMethod · 0.45

Tested by

no test coverage detected