Skip to content

Commit b3e8f87

Browse files
Address CodeRabbit review suggestions
- Add MetaTensor import and return type for better type safety - Improve docstrings with clinical rationale for CT and MRI pipelines - Fix test_modality_case_insensitivity using proper mocking - Remove broad exception catching in tests Signed-off-by: Hitendrasinh Rathod <[email protected]>
1 parent 2986d2e commit b3e8f87

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

monai/tests/test_clinical_preprocessing.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
1111

12-
import tempfile
1312
from pathlib import Path
13+
from unittest.mock import Mock, patch
1414

1515
import numpy as np
1616
import pytest
@@ -78,23 +78,16 @@ def test_unsupported_modality():
7878
assert "MRI" in msg
7979

8080

81-
def test_modality_case_insensitivity():
81+
@patch("monai.transforms.clinical_preprocessing.LoadImage")
82+
def test_modality_case_insensitivity(mock_load):
8283
"""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+
8487
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
9891

9992

10093
def test_preprocess_dicom_series_integration(tmp_path):

0 commit comments

Comments
 (0)