|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +from types import SimpleNamespace |
5 | 6 | from unittest.mock import AsyncMock |
6 | 7 |
|
7 | | -from tests.sdk.conftest import AsyncIterableMock, MockScenarioRunView, MockBenchmarkRunView |
| 8 | +from tests.sdk.conftest import MockScenarioRunView, MockBenchmarkRunView |
| 9 | +from runloop_api_client.sdk.async_scenario_run import AsyncScenarioRun |
8 | 10 | from runloop_api_client.sdk.async_benchmark_run import AsyncBenchmarkRun |
9 | 11 |
|
10 | 12 |
|
@@ -56,39 +58,63 @@ async def test_complete(self, mock_async_client: AsyncMock, benchmark_run_view: |
56 | 58 | assert result.state == "completed" |
57 | 59 | mock_async_client.benchmarks.runs.complete.assert_awaited_once_with("bench_run_123") |
58 | 60 |
|
59 | | - async def test_list_scenario_runs( |
| 61 | + async def test_list_scenario_runs_empty(self, mock_async_client: AsyncMock) -> None: |
| 62 | + """Test list_scenario_runs method with empty results.""" |
| 63 | + page = SimpleNamespace(runs=[]) |
| 64 | + mock_async_client.benchmarks.runs.list_scenario_runs = AsyncMock(return_value=page) |
| 65 | + |
| 66 | + run = AsyncBenchmarkRun(mock_async_client, "bench_run_123", "bench_123") |
| 67 | + result = await run.list_scenario_runs() |
| 68 | + |
| 69 | + assert len(result) == 0 |
| 70 | + mock_async_client.benchmarks.runs.list_scenario_runs.assert_awaited_once_with("bench_run_123") |
| 71 | + |
| 72 | + async def test_list_scenario_runs_single( |
60 | 73 | self, mock_async_client: AsyncMock, scenario_run_view: MockScenarioRunView |
61 | 74 | ) -> None: |
62 | | - """Test list_scenario_runs method.""" |
63 | | - mock_async_client.benchmarks.runs.list_scenario_runs.return_value = AsyncIterableMock([scenario_run_view]) |
| 75 | + """Test list_scenario_runs method with single result.""" |
| 76 | + page = SimpleNamespace(runs=[scenario_run_view]) |
| 77 | + mock_async_client.benchmarks.runs.list_scenario_runs = AsyncMock(return_value=page) |
64 | 78 |
|
65 | 79 | run = AsyncBenchmarkRun(mock_async_client, "bench_run_123", "bench_123") |
66 | 80 | result = await run.list_scenario_runs() |
67 | 81 |
|
68 | 82 | assert len(result) == 1 |
69 | | - assert result[0] == scenario_run_view |
70 | | - mock_async_client.benchmarks.runs.list_scenario_runs.assert_called_once_with("bench_run_123") |
| 83 | + assert isinstance(result[0], AsyncScenarioRun) |
| 84 | + assert result[0].id == scenario_run_view.id |
| 85 | + assert result[0].devbox_id == scenario_run_view.devbox_id |
| 86 | + mock_async_client.benchmarks.runs.list_scenario_runs.assert_awaited_once_with("bench_run_123") |
| 87 | + |
| 88 | + async def test_list_scenario_runs_multiple(self, mock_async_client: AsyncMock) -> None: |
| 89 | + """Test list_scenario_runs method with multiple results.""" |
| 90 | + scenario_run_view1 = MockScenarioRunView(id="run_001", devbox_id="dev_001") |
| 91 | + scenario_run_view2 = MockScenarioRunView(id="run_002", devbox_id="dev_002") |
| 92 | + page = SimpleNamespace(runs=[scenario_run_view1, scenario_run_view2]) |
| 93 | + mock_async_client.benchmarks.runs.list_scenario_runs = AsyncMock(return_value=page) |
| 94 | + |
| 95 | + run = AsyncBenchmarkRun(mock_async_client, "bench_run_123", "bench_123") |
| 96 | + result = await run.list_scenario_runs() |
| 97 | + |
| 98 | + assert len(result) == 2 |
| 99 | + assert isinstance(result[0], AsyncScenarioRun) |
| 100 | + assert isinstance(result[1], AsyncScenarioRun) |
| 101 | + assert result[0].id == "run_001" |
| 102 | + assert result[1].id == "run_002" |
| 103 | + mock_async_client.benchmarks.runs.list_scenario_runs.assert_awaited_once_with("bench_run_123") |
71 | 104 |
|
72 | 105 | async def test_list_scenario_runs_with_params( |
73 | 106 | self, mock_async_client: AsyncMock, scenario_run_view: MockScenarioRunView |
74 | 107 | ) -> None: |
75 | 108 | """Test list_scenario_runs method with filtering parameters.""" |
76 | | - mock_async_client.benchmarks.runs.list_scenario_runs.return_value = AsyncIterableMock([scenario_run_view]) |
| 109 | + page = SimpleNamespace(runs=[scenario_run_view]) |
| 110 | + mock_async_client.benchmarks.runs.list_scenario_runs = AsyncMock(return_value=page) |
77 | 111 |
|
78 | 112 | run = AsyncBenchmarkRun(mock_async_client, "bench_run_123", "bench_123") |
79 | 113 | result = await run.list_scenario_runs(limit=10, state="completed") |
80 | 114 |
|
81 | 115 | assert len(result) == 1 |
82 | | - mock_async_client.benchmarks.runs.list_scenario_runs.assert_called_once_with( |
| 116 | + assert isinstance(result[0], AsyncScenarioRun) |
| 117 | + assert result[0].id == scenario_run_view.id |
| 118 | + mock_async_client.benchmarks.runs.list_scenario_runs.assert_awaited_once_with( |
83 | 119 | "bench_run_123", limit=10, state="completed" |
84 | 120 | ) |
85 | | - |
86 | | - async def test_list_scenario_runs_empty(self, mock_async_client: AsyncMock) -> None: |
87 | | - """Test list_scenario_runs returns empty list when no scenario runs.""" |
88 | | - mock_async_client.benchmarks.runs.list_scenario_runs.return_value = AsyncIterableMock([]) |
89 | | - |
90 | | - run = AsyncBenchmarkRun(mock_async_client, "bench_run_123", "bench_123") |
91 | | - result = await run.list_scenario_runs() |
92 | | - |
93 | | - assert result == [] |
94 | | - mock_async_client.benchmarks.runs.list_scenario_runs.assert_called_once_with("bench_run_123") |
|
0 commit comments