|
2 | 2 | import os |
3 | 3 | import unittest |
4 | 4 | from typing import List |
| 5 | +from unittest.mock import patch |
| 6 | + |
| 7 | +from flow_preprocessor.exceptions.exceptions import ImageFetchException |
5 | 8 | from flow_preprocessor.preprocessing_logic.preprocess import Preprocessor |
6 | 9 |
|
7 | 10 |
|
@@ -30,11 +33,33 @@ def test_preprocess_crop_false(self): |
30 | 33 | asyncio.run(self.preprocessor.preprocess_xml_file_list(self.xml_files, self.in_path, self.out_path)) |
31 | 34 |
|
32 | 35 | def test_preprocess_crop_true(self): |
33 | | - asyncio.run(self.preprocessor.preprocess_xml_file_list(self.xml_files, self.in_path, self.out_path, crop=True)) |
| 36 | + asyncio.run(self.preprocessor.preprocess_xml_file_list(self.xml_files, |
| 37 | + self.in_path, |
| 38 | + self.out_path, |
| 39 | + crop=True, |
| 40 | + stop_on_fail=False)) |
34 | 41 |
|
35 | 42 | def test_preprocess_abbrev_true(self): |
36 | 43 | asyncio.run( |
37 | | - self.preprocessor.preprocess_xml_file_list(self.xml_files, self.in_path, self.out_path, abbrev=True)) |
| 44 | + self.preprocessor.preprocess_xml_file_list(self.xml_files, |
| 45 | + self.in_path, |
| 46 | + self.out_path, |
| 47 | + abbrev=True, |
| 48 | + stop_on_fail=False)) |
| 49 | + |
| 50 | + def test_preprocess_with_failure_due_to_invalid_file(self): |
| 51 | + # Simulate invalid XML files that would lead to an ImageFetchException |
| 52 | + invalid_xml_files = ["invalid_file.xml"] |
| 53 | + |
| 54 | + with patch( |
| 55 | + 'flow_preprocessor.preprocessing_logic.preprocess.Preprocessor.preprocess_xml_file_list') as mock_preprocess: |
| 56 | + mock_preprocess.side_effect = ImageFetchException("Simulated failure during file processing.") |
| 57 | + |
| 58 | + with self.assertRaises(ImageFetchException) as context: |
| 59 | + asyncio.run(self.preprocessor.preprocess_xml_file_list( |
| 60 | + invalid_xml_files, self.in_path, self.out_path, stop_on_fail=True)) |
| 61 | + |
| 62 | + self.assertIn("Simulated failure during file processing", str(context.exception)) |
38 | 63 |
|
39 | 64 | def tearDown(self) -> None: |
40 | 65 | """ |
|
0 commit comments