|
9 | 9 | # See the License for the specific language governing permissions and |
10 | 10 | # limitations under the License. |
11 | 11 |
|
12 | | -import tempfile |
13 | 12 | from pathlib import Path |
| 13 | +from unittest.mock import Mock, patch |
14 | 14 |
|
15 | 15 | import numpy as np |
16 | 16 | import pytest |
@@ -78,23 +78,16 @@ def test_unsupported_modality(): |
78 | 78 | assert "MRI" in msg |
79 | 79 |
|
80 | 80 |
|
81 | | -def test_modality_case_insensitivity(): |
| 81 | +@patch("monai.transforms.clinical_preprocessing.LoadImage") |
| 82 | +def test_modality_case_insensitivity(mock_load): |
82 | 83 | """Test case-insensitive modality handling.""" |
83 | | - # Test each case variation |
| 84 | + # Mock the LoadImage to avoid actual file I/O |
| 85 | + mock_load.return_value = Mock(return_value=Mock()) |
| 86 | + |
84 | 87 | for modality in ["CT", "ct", "Ct", "CT ", "MR", "mr", "MRI", "mri", " MrI "]: |
85 | | - # Just test that the function doesn't raise modality-related errors |
86 | | - # We're not testing actual image loading, just modality parsing |
87 | | - try: |
88 | | - # This will fail on file loading, but not on modality parsing |
89 | | - preprocess_dicom_series("non_existent_file.dcm", modality) |
90 | | - except (ModalityTypeError, UnsupportedModalityError): |
91 | | - pytest.fail(f"Modality {modality!r} should be accepted") |
92 | | - except FileNotFoundError: |
93 | | - # This is expected - the file doesn't exist, but modality parsing worked |
94 | | - pass |
95 | | - except Exception: |
96 | | - # Any other error is fine for this test |
97 | | - pass |
| 88 | + # Should not raise modality errors |
| 89 | + result = preprocess_dicom_series("dummy.dcm", modality) |
| 90 | + assert result is not None |
98 | 91 |
|
99 | 92 |
|
100 | 93 | def test_preprocess_dicom_series_integration(tmp_path): |
|
0 commit comments