|
3 | 3 | This module contains tests for CLI helper functions in sky.client.cli.command. |
4 | 4 | """ |
5 | 5 | import traceback |
6 | | -from typing import Dict, List, Optional, Tuple, Union |
| 6 | +from typing import Any, Dict, List, Optional, Tuple, Union |
7 | 7 | from unittest import mock |
8 | 8 |
|
9 | 9 | import colorama |
@@ -75,6 +75,7 @@ def test_handle_jobs_queue_request_success_tuple_response(): |
75 | 75 | mock_stream.assert_called_once_with(request_id) |
76 | 76 | mock_format.assert_called_once_with( |
77 | 77 | managed_jobs_list, |
| 78 | + pool_status=None, |
78 | 79 | show_all=False, |
79 | 80 | show_user=False, |
80 | 81 | max_jobs=10, |
@@ -128,6 +129,89 @@ def test_handle_jobs_queue_request_success_list_response(): |
128 | 129 | mock_stream.assert_called_once_with(request_id) |
129 | 130 | mock_format.assert_called_once_with( |
130 | 131 | mock_job_records, |
| 132 | + pool_status=None, |
| 133 | + show_all=True, |
| 134 | + show_user=True, |
| 135 | + max_jobs=None, |
| 136 | + status_counts=None, |
| 137 | + ) |
| 138 | + |
| 139 | + |
| 140 | +def test_handle_jobs_queue_request_success_list_response_with_pool_status(): |
| 141 | + """Test _handle_jobs_queue_request with list response (legacy API).""" |
| 142 | + # Create mock managed job records as dicts |
| 143 | + mock_jobs = [ |
| 144 | + { |
| 145 | + 'job_id': 1, |
| 146 | + 'job_name': 'test-job-1' |
| 147 | + }, |
| 148 | + { |
| 149 | + 'job_id': 2, |
| 150 | + 'job_name': 'test-job-2' |
| 151 | + }, |
| 152 | + { |
| 153 | + 'job_id': 3, |
| 154 | + 'job_name': 'test-job-3' |
| 155 | + }, |
| 156 | + ] |
| 157 | + |
| 158 | + # Mock job records using the model |
| 159 | + mock_job_records = [responses.ManagedJobRecord(**job) for job in mock_jobs] |
| 160 | + |
| 161 | + # Mock pool status records using the model |
| 162 | + mock_pool_statuses = [ |
| 163 | + { |
| 164 | + 'replica_info': [ |
| 165 | + { |
| 166 | + 'replica_id': 1, |
| 167 | + 'used_by': 3, |
| 168 | + }, |
| 169 | + { |
| 170 | + 'replica_id': 2, |
| 171 | + 'used_by': 2, |
| 172 | + }, |
| 173 | + { |
| 174 | + 'replica_id': 3, |
| 175 | + 'used_by': 1, |
| 176 | + }, |
| 177 | + ], |
| 178 | + }, |
| 179 | + ] |
| 180 | + |
| 181 | + request_id = server_common.RequestId[List[responses.ManagedJobRecord]]( |
| 182 | + 'test-request-id') |
| 183 | + |
| 184 | + pool_status_request_id = server_common.RequestId[List[Dict[str, Any]]]( |
| 185 | + 'test-pool-status-request-id') |
| 186 | + |
| 187 | + with mock.patch.object(client_sdk, |
| 188 | + 'stream_and_get', |
| 189 | + side_effect=[mock_job_records, |
| 190 | + mock_pool_statuses]) as mock_stream: |
| 191 | + with mock.patch.object(usage_lib.messages.usage, 'set_internal'): |
| 192 | + with mock.patch.object( |
| 193 | + table_utils, 'format_job_table', |
| 194 | + return_value='formatted table') as mock_format: |
| 195 | + num_jobs, msg = command._handle_jobs_queue_request( |
| 196 | + request_id=request_id, |
| 197 | + show_all=True, |
| 198 | + show_user=True, |
| 199 | + max_num_jobs_to_show=None, |
| 200 | + pool_status_request_id=pool_status_request_id, |
| 201 | + is_called_by_user=True, |
| 202 | + only_in_progress=False, |
| 203 | + ) |
| 204 | + |
| 205 | + # Verify the result - should count unique job IDs |
| 206 | + assert num_jobs == 3 |
| 207 | + assert msg == 'formatted table' |
| 208 | + mock_stream.assert_has_calls([ |
| 209 | + mock.call(request_id), |
| 210 | + mock.call(pool_status_request_id), |
| 211 | + ]) |
| 212 | + mock_format.assert_called_once_with( |
| 213 | + mock_job_records, |
| 214 | + pool_status=mock_pool_statuses, |
131 | 215 | show_all=True, |
132 | 216 | show_user=True, |
133 | 217 | max_jobs=None, |
|
0 commit comments