99# See the License for the specific language governing permissions and
1010# limitations under the License.
1111
12+ import tempfile
13+ from pathlib import Path
1214
1315import numpy as np
1416import pytest
@@ -78,14 +80,21 @@ def test_unsupported_modality():
7880
7981def test_modality_case_insensitivity ():
8082 """Test case-insensitive modality handling."""
81- # These should all work without error
83+ # Test each case variation
8284 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
8387 try :
84- # We're not actually loading an image, just checking the function doesn't fail on modality parsing
85- if isinstance (modality , str ) and modality .strip ().upper () in {"CT" , "MR" , "MRI" }:
86- assert True
88+ # This will fail on file loading, but not on modality parsing
89+ preprocess_dicom_series ("non_existent_file.dcm" , modality )
8790 except (ModalityTypeError , UnsupportedModalityError ):
8891 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
8998
9099
91100def test_preprocess_dicom_series_integration (tmp_path ):
@@ -98,9 +107,6 @@ def test_preprocess_dicom_series_integration(tmp_path):
98107
99108 # Test with each modality
100109 for modality in ["CT" , "MRI" ]:
101- try :
102- result = preprocess_dicom_series (str (test_file ), modality )
103- assert result is not None
104- assert hasattr (result , "shape" )
105- except Exception as e :
106- pytest .fail (f"Failed to preprocess with modality { modality } : { e } " )
110+ result = preprocess_dicom_series (str (test_file ), modality )
111+ assert result is not None
112+ assert hasattr (result , "shape" )
0 commit comments