Skip to content

Commit 891aca5

Browse files
committed
Apply black formating
1 parent 0dd2d33 commit 891aca5

File tree

8 files changed

+51
-62
lines changed

8 files changed

+51
-62
lines changed

cosmotech/coal/cosmotech_api/runner/download.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from cosmotech.orchestrator.utils.translate import T
3434

3535

36-
3736
def download_runner_data(
3837
organization_id: str,
3938
workspace_id: str,

cosmotech/coal/cosmotech_api/twin_data_layer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ def generate_query_insert(self) -> str:
137137
return query
138138

139139

140-
def get_dataset_id_from_runner(
141-
organization_id: str, workspace_id: str, runner_id: str
142-
) -> str:
140+
def get_dataset_id_from_runner(organization_id: str, workspace_id: str, runner_id: str) -> str:
143141
"""
144142
Get the dataset ID from a runner.
145143
@@ -153,7 +151,7 @@ def get_dataset_id_from_runner(
153151
"""
154152
api_client, _ = get_api_client()
155153
api_runner = RunnerApi(api_client)
156-
154+
157155
runner_info = api_runner.get_runner(
158156
organization_id,
159157
workspace_id,

tests/unit/coal/test_azure/test_adx/test_adx_ingestion_edge_cases.py

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,14 @@ def test_check_ingestion_status_with_logs_and_messages(
7777

7878
# Act
7979
with patch(
80-
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
81-
return_value=MagicMock(IngestionSourceId=source_id)
80+
"cosmotech.coal.azure.adx.ingestion.SuccessMessage", return_value=MagicMock(IngestionSourceId=source_id)
8281
):
8382
result = list(check_ingestion_status(mock_ingest_client, [source_id], logs=True))
8483

8584
# Assert
8685
assert len(result) == 1
8786
assert result[0] == (source_id, IngestionStatus.SUCCESS)
88-
87+
8988
# Verify that the message was deleted
9089
mock_success_queue.delete_message.assert_called_once_with(mock_message)
9190

@@ -123,19 +122,16 @@ def test_check_ingestion_status_with_multiple_messages(
123122

124123
# Act
125124
with patch(
126-
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
127-
side_effect=[
128-
MagicMock(IngestionSourceId=source_id1),
129-
MagicMock(IngestionSourceId=source_id2)
130-
]
125+
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
126+
side_effect=[MagicMock(IngestionSourceId=source_id1), MagicMock(IngestionSourceId=source_id2)],
131127
):
132128
result = list(check_ingestion_status(mock_ingest_client, [source_id1, source_id2], logs=True))
133129

134130
# Assert
135131
assert len(result) == 2
136132
assert (source_id1, IngestionStatus.SUCCESS) in result
137133
assert (source_id2, IngestionStatus.QUEUED) in result or (source_id2, IngestionStatus.SUCCESS) in result
138-
134+
139135
# Verify that at least one message was deleted
140136
assert mock_success_queue.delete_message.call_count >= 1
141137

@@ -166,15 +162,14 @@ def test_check_ingestion_status_with_success_messages_and_logs(
166162

167163
# Act
168164
with patch(
169-
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
170-
return_value=MagicMock(IngestionSourceId=source_id)
165+
"cosmotech.coal.azure.adx.ingestion.SuccessMessage", return_value=MagicMock(IngestionSourceId=source_id)
171166
):
172167
result = list(check_ingestion_status(mock_ingest_client, [source_id], logs=True))
173168

174169
# Assert
175170
assert len(result) == 1
176171
assert result[0] == (source_id, IngestionStatus.SUCCESS)
177-
172+
178173
# Verify that the message was deleted
179174
mock_success_queue.delete_message.assert_called_once_with(mock_success_message)
180175

@@ -205,15 +200,14 @@ def test_check_ingestion_status_with_failure_messages_and_logs(
205200

206201
# Act
207202
with patch(
208-
"cosmotech.coal.azure.adx.ingestion.FailureMessage",
209-
return_value=MagicMock(IngestionSourceId=source_id)
203+
"cosmotech.coal.azure.adx.ingestion.FailureMessage", return_value=MagicMock(IngestionSourceId=source_id)
210204
):
211205
result = list(check_ingestion_status(mock_ingest_client, [source_id], logs=True))
212206

213207
# Assert
214208
assert len(result) == 1
215209
assert result[0] == (source_id, IngestionStatus.FAILURE)
216-
210+
217211
# Verify that the message was deleted
218212
mock_failure_queue.delete_message.assert_called_once_with(mock_failure_message)
219213

@@ -249,18 +243,17 @@ def test_check_ingestion_status_with_logs_and_status_messages(
249243

250244
# Act
251245
with patch(
252-
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
253-
return_value=MagicMock(IngestionSourceId=source_id)
246+
"cosmotech.coal.azure.adx.ingestion.SuccessMessage", return_value=MagicMock(IngestionSourceId=source_id)
254247
):
255248
result = list(check_ingestion_status(mock_ingest_client, [source_id], logs=True))
256249

257250
# Assert
258251
assert len(result) == 1
259252
assert result[0] == (source_id, IngestionStatus.SUCCESS)
260-
253+
261254
# Verify that the debug log was called with the correct message
262255
mock_logger.debug.assert_any_call(T("coal.logs.adx.status_messages").format(success=2, failure=1))
263-
256+
264257
# Verify that the message was deleted
265258
mock_success_queue.delete_message.assert_called_once_with(mock_success_message1)
266259

@@ -291,47 +284,50 @@ def test_check_ingestion_status_with_no_matching_messages(
291284

292285
# Act
293286
with patch(
294-
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
295-
return_value=MagicMock(IngestionSourceId="different-source-id")
287+
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
288+
return_value=MagicMock(IngestionSourceId="different-source-id"),
296289
):
297290
result = list(check_ingestion_status(mock_ingest_client, [source_id], logs=True))
298291

299292
# Assert
300293
assert len(result) == 1
301294
assert result[0] == (source_id, IngestionStatus.QUEUED)
302-
295+
303296
# Verify that no messages were deleted
304297
mock_success_queue.delete_message.assert_not_called()
305298

306299
def test_status_messages_log_line_true(self):
307300
"""Test the specific log line that's not being covered with logs=True."""
308301
# Import the module directly to access the function
309302
import cosmotech.coal.azure.adx.ingestion as ingestion_module
310-
303+
311304
# Create mock objects
312305
mock_logger = MagicMock()
313306
mock_t = MagicMock()
314307
mock_format = MagicMock()
315308
mock_t.return_value = mock_format
316309
mock_format.format.return_value = "Status message"
317-
310+
318311
# Replace the real objects with mocks
319312
original_logger = ingestion_module.LOGGER
320313
original_t = ingestion_module.T
321314
ingestion_module.LOGGER = mock_logger
322315
ingestion_module.T = mock_t
323-
316+
324317
try:
325318
# Create test data
326319
successes = [1, 2, 3] # Just need a list with a length
327320
failures = [1] # Just need a list with a length
328321
logs = True
329-
322+
330323
# Call the specific line directly
331324
if logs:
332-
ingestion_module.LOGGER.debug(ingestion_module.T("coal.logs.adx.status_messages").format(
333-
success=len(successes), failure=len(failures)))
334-
325+
ingestion_module.LOGGER.debug(
326+
ingestion_module.T("coal.logs.adx.status_messages").format(
327+
success=len(successes), failure=len(failures)
328+
)
329+
)
330+
335331
# Verify the mocks were called correctly
336332
mock_t.assert_called_once_with("coal.logs.adx.status_messages")
337333
mock_format.format.assert_called_once_with(success=3, failure=1)
@@ -340,33 +336,36 @@ def test_status_messages_log_line_true(self):
340336
# Restore the original objects
341337
ingestion_module.LOGGER = original_logger
342338
ingestion_module.T = original_t
343-
339+
344340
def test_status_messages_log_line_false(self):
345341
"""Test the specific log line that's not being covered with logs=False."""
346342
# Import the module directly to access the function
347343
import cosmotech.coal.azure.adx.ingestion as ingestion_module
348-
344+
349345
# Create mock objects
350346
mock_logger = MagicMock()
351347
mock_t = MagicMock()
352-
348+
353349
# Replace the real objects with mocks
354350
original_logger = ingestion_module.LOGGER
355351
original_t = ingestion_module.T
356352
ingestion_module.LOGGER = mock_logger
357353
ingestion_module.T = mock_t
358-
354+
359355
try:
360356
# Create test data
361357
successes = [1, 2, 3] # Just need a list with a length
362358
failures = [1] # Just need a list with a length
363359
logs = False
364-
360+
365361
# Call the specific line directly
366362
if logs:
367-
ingestion_module.LOGGER.debug(ingestion_module.T("coal.logs.adx.status_messages").format(
368-
success=len(successes), failure=len(failures)))
369-
363+
ingestion_module.LOGGER.debug(
364+
ingestion_module.T("coal.logs.adx.status_messages").format(
365+
success=len(successes), failure=len(failures)
366+
)
367+
)
368+
370369
# Verify the mocks were not called
371370
mock_t.assert_not_called()
372371
mock_logger.debug.assert_not_called()
@@ -405,21 +404,20 @@ def test_check_ingestion_status_with_logs_disabled(
405404

406405
# Act
407406
with patch(
408-
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
409-
return_value=MagicMock(IngestionSourceId=source_id)
407+
"cosmotech.coal.azure.adx.ingestion.SuccessMessage", return_value=MagicMock(IngestionSourceId=source_id)
410408
):
411409
result = list(check_ingestion_status(mock_ingest_client, [source_id], logs=False))
412410

413411
# Assert
414412
assert len(result) == 1
415413
assert result[0] == (source_id, IngestionStatus.SUCCESS)
416-
414+
417415
# Verify that the debug log was not called with the status messages
418416
for call_args in mock_logger.debug.call_args_list:
419417
args, kwargs = call_args
420418
if len(args) > 0 and isinstance(args[0], str) and "status_messages" in args[0]:
421419
assert False, "LOGGER.debug should not be called with status_messages when logs=False"
422-
420+
423421
# Verify that the message was deleted
424422
mock_success_queue.delete_message.assert_called_once_with(mock_success_message)
425423

@@ -443,7 +441,7 @@ def test_check_ingestion_status_with_multiple_queues(
443441
mock_message = MagicMock()
444442
mock_message.content = '{"IngestionSourceId": "source-id-multiple-queues"}'
445443
mock_success_queue2.receive_messages.return_value = [mock_message]
446-
444+
447445
# Set up the success queues
448446
mock_status_queues.success._get_queues.return_value = [mock_success_queue1, mock_success_queue2]
449447

@@ -454,15 +452,14 @@ def test_check_ingestion_status_with_multiple_queues(
454452

455453
# Act
456454
with patch(
457-
"cosmotech.coal.azure.adx.ingestion.SuccessMessage",
458-
return_value=MagicMock(IngestionSourceId=source_id)
455+
"cosmotech.coal.azure.adx.ingestion.SuccessMessage", return_value=MagicMock(IngestionSourceId=source_id)
459456
):
460457
result = list(check_ingestion_status(mock_ingest_client, [source_id], logs=True))
461458

462459
# Assert
463460
assert len(result) == 1
464461
assert result[0] == (source_id, IngestionStatus.SUCCESS)
465-
462+
466463
# Verify that the message was deleted from the correct queue
467464
mock_success_queue1.delete_message.assert_not_called()
468465
mock_success_queue2.delete_message.assert_called_once_with(mock_message)

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ def mock_runner_api(self):
170170
mock_api = MagicMock(spec=RunnerApi)
171171
return mock_api
172172

173-
174173
@pytest.fixture
175174
def mock_dataset_api(self):
176175
"""Create a mock DatasetApi."""
@@ -196,7 +195,6 @@ def test_get_dataset_id_from_runner(self, mock_get_api_client, mock_runner_api):
196195
assert result == "dataset-123"
197196
mock_runner_api.get_runner.assert_called_once_with("org-123", "ws-123", "runner-123")
198197

199-
200198
@patch("cosmotech.coal.cosmotech_api.twin_data_layer.get_api_client")
201199
def test_get_dataset_id_from_runner_no_ids(self, mock_get_api_client, mock_runner_api):
202200
"""Test the get_dataset_id_from_runner function with no IDs."""
@@ -212,7 +210,6 @@ def test_get_dataset_id_from_runner_no_ids(self, mock_get_api_client, mock_runne
212210
with pytest.raises(ValueError):
213211
get_dataset_id_from_runner("org-123", "ws-123", "runner-123")
214212

215-
216213
@patch("cosmotech.coal.cosmotech_api.twin_data_layer.get_api_client")
217214
def test_get_dataset_id_from_runner_no_datasets(self, mock_get_api_client, mock_runner_api):
218215
"""Test the get_dataset_id_from_runner function with no datasets."""

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer_auth.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def mock_api_client(self):
3636
mock_client.default_headers = {"Default-Header": "value"}
3737
mock_client.configuration.auth_settings.return_value = {
3838
"auth1": {"type": "apiKey", "in": "header", "key": "Authorization", "value": "Bearer token"},
39-
"auth2": {"type": "basic", "in": "header", "key": "Authorization", "value": "Basic credentials"}
39+
"auth2": {"type": "basic", "in": "header", "key": "Authorization", "value": "Basic credentials"},
4040
}
4141
return mock_client
4242

@@ -59,11 +59,11 @@ def test_send_files_to_tdl_auth_params(
5959
# Arrange
6060
mock_api_client = MagicMock()
6161
mock_api_client.default_headers = {"Default-Header": "value"}
62-
62+
6363
# Set up auth settings with multiple auth types
6464
auth_settings = {
6565
"auth1": {"type": "apiKey", "in": "header", "key": "Authorization", "value": "Bearer token"},
66-
"auth2": {"type": "basic", "in": "header", "key": "Basic-Auth", "value": "Basic credentials"}
66+
"auth2": {"type": "basic", "in": "header", "key": "Basic-Auth", "value": "Basic credentials"},
6767
}
6868
mock_api_client.configuration.auth_settings.return_value = auth_settings
6969

@@ -96,19 +96,19 @@ def test_send_files_to_tdl_auth_params(
9696
# Assert
9797
# Verify that _apply_auth_params was called for each auth type
9898
assert mock_api_client._apply_auth_params.call_count == len(auth_settings)
99-
99+
100100
# Check that the header was passed to _process_csv_file with auth params applied
101101
expected_header = {
102102
"Accept": "application/json",
103103
"Content-Type": "text/csv",
104104
"User-Agent": "OpenAPI-Generator/1.0.0/python",
105105
"Default-Header": "value",
106106
}
107-
107+
108108
# Verify that _process_csv_file was called with the expected header
109109
mock_process_csv_file.assert_called_once()
110110
actual_header = mock_process_csv_file.call_args[1]["header"]
111-
111+
112112
# Check that the header contains the expected keys
113113
for key in expected_header:
114114
assert key in actual_header

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer_edge_cases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_process_csv_file_with_errors(self, mock_logger, mock_post):
133133
_process_csv_file(file_path, query, api_url, organization_id, dataset_id, header)
134134

135135
assert f"Error importing data from {file_path}" in str(excinfo.value)
136-
136+
137137
# Verify that errors were logged
138138
mock_logger.error.assert_any_call(T("coal.logs.storage.import_errors").format(count=2))
139139
mock_logger.error.assert_any_call("Error 1")

tests/unit/coal/test_cosmotech_api/test_runner/test_runner_download.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
class TestDownloadFunctions:
2323
"""Tests for top-level functions in the download module."""
2424

25-
2625
@patch("cosmotech.coal.cosmotech_api.runner.download.get_api_client")
2726
@patch("cosmotech.coal.cosmotech_api.runner.download.get_runner_data")
2827
@patch("cosmotech.coal.cosmotech_api.runner.download.format_parameters_list")

tests/unit/coal/test_cosmotech_api/test_runner/test_runner_download_edge_cases.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
class TestDownloadEdgeCases:
2323
"""Tests for edge cases in the download module."""
2424

25-
2625
@patch("cosmotech.coal.cosmotech_api.runner.download.get_api_client")
2726
@patch("cosmotech.coal.cosmotech_api.runner.download.DefaultAzureCredential")
2827
@patch("cosmotech.coal.cosmotech_api.runner.download.get_runner_data")

0 commit comments

Comments
 (0)