File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 9
9
def test_raise_on_missing_reader ():
10
10
"""Test the raise_on_missing_reader flag behavior."""
11
11
print ("Testing LoadImage raise_on_missing_reader flag..." )
12
-
12
+
13
13
# Test 1: Unknown reader with flag enabled - should raise OptionalImportError
14
14
print ("Test 1: Unknown reader with raise_on_missing_reader=True" )
15
15
try :
@@ -18,9 +18,9 @@ def test_raise_on_missing_reader():
18
18
return False
19
19
except OptionalImportError as e :
20
20
print (f"PASS: Got expected OptionalImportError: { e } " )
21
-
21
+
22
22
# Test 2: Unknown reader with flag disabled - should warn but not raise
23
- print ("\n Test 2: Unknown reader with raise_on_missing_reader=False" )
23
+ print ("\n Test 2: Unknown reader with raise_on_missing_reader=False" )
24
24
try :
25
25
with warnings .catch_warnings (record = True ) as w :
26
26
warnings .simplefilter ("always" )
@@ -36,7 +36,7 @@ def test_raise_on_missing_reader():
36
36
except Exception as e :
37
37
print (f"FAIL: Unexpected error: { e } " )
38
38
return False
39
-
39
+
40
40
# Test 3: Valid reader - should work regardless of flag
41
41
print ("\n Test 3: Valid reader (PILReader) with both flag settings" )
42
42
try :
@@ -46,7 +46,7 @@ def test_raise_on_missing_reader():
46
46
except Exception as e :
47
47
print (f"FAIL: Unexpected error with valid reader: { e } " )
48
48
return False
49
-
49
+
50
50
print ("\n All tests passed!" )
51
51
return True
52
52
Original file line number Diff line number Diff line change @@ -452,7 +452,7 @@ def test_raise_on_missing_reader_flag(self):
452
452
# Test with flag enabled - should raise exception for unknown reader name
453
453
with self .assertRaises (OptionalImportError ):
454
454
LoadImage (image_only = True , reader = "UnknownReaderName" , raise_on_missing_reader = True )
455
-
455
+
456
456
# Test with flag disabled - should warn but not raise exception for unknown reader name
457
457
# This should succeed and create the loader with fallback behavior
458
458
with warnings .catch_warnings (record = True ) as w :
@@ -461,7 +461,7 @@ def test_raise_on_missing_reader_flag(self):
461
461
self .assertIsInstance (loader_with_fallback , LoadImage )
462
462
# Should have produced a warning about the unknown reader
463
463
self .assertTrue (any ("Cannot find reader 'UnknownReaderName'" in str (warning .message ) for warning in w ))
464
-
464
+
465
465
# The flag should work properly with valid readers too
466
466
loader_with_flag = LoadImage (image_only = True , reader = "ITKReader" , raise_on_missing_reader = False )
467
467
loader_without_flag = LoadImage (image_only = True , reader = "ITKReader" )
You can’t perform that action at this time.
0 commit comments