Skip to content

Commit 2986d2e

Browse files
Fix CodeRabbit review issues
- Fix test_modality_case_insensitivity to actually test function - Remove broad Exception catch in integration test - Improve error handling in tests Signed-off-by: Hitendrasinh Rathod <[email protected]>
1 parent f513c16 commit 2986d2e

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

monai/tests/test_clinical_preprocessing.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
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

1315
import numpy as np
1416
import pytest
@@ -78,14 +80,21 @@ def test_unsupported_modality():
7880

7981
def 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

91100
def 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")

monai/transforms/clinical_preprocessing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def preprocess_dicom_series(path: str, modality: str) -> Any:
8080
modality: Imaging modality. Supported values are "CT", "MR", and "MRI" (case-insensitive).
8181
8282
Returns:
83-
Preprocessed image data (typically a MetaTensor or NumPy array).
83+
The preprocessed image data.
8484
8585
Raises:
8686
ModalityTypeError: If modality is not a string.
@@ -109,4 +109,4 @@ def preprocess_dicom_series(path: str, modality: str) -> Any:
109109
"get_ct_preprocessing_pipeline",
110110
"get_mri_preprocessing_pipeline",
111111
"preprocess_dicom_series",
112-
]
112+
]

0 commit comments

Comments
 (0)