@@ -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 )
0 commit comments