@@ -93,10 +93,7 @@ def test_sniff_and_guessed_image_type(img_klasses=all_image_classes):
93
93
For each, we expect:
94
94
* When the file matches the expected class, things should
95
95
either work, or fail if we're doing bad stuff.
96
- * When the file is a mismatch, it should either
97
- * Fail to be loaded if the image type is unrelated to the expected class
98
- * Load or fail in a consistent manner, if there is a relationship between
99
- the image class and expected image class.
96
+ * When the file is a mismatch, the functions should not throw.
100
97
"""
101
98
102
99
def test_image_class (img_path , expected_img_klass ):
@@ -116,24 +113,19 @@ def check_img(img_path, img_klass, sniff_mode, sniff, expect_success, msg):
116
113
is_img , new_sniff = img_klass .is_image (img_path , sniff )
117
114
118
115
if expect_success :
116
+ # Check that the sniff returned is appropriate.
119
117
new_msg = '%s returned sniff==None (%s)' % (img_klass .__name__ , msg )
120
118
expected_sizeof_hdr = getattr (img_klass .header_class , 'sizeof_hdr' , 0 )
121
119
current_sizeof_hdr = len (new_sniff ) if new_sniff is not None else 0
122
120
assert_true (current_sizeof_hdr >= expected_sizeof_hdr , new_msg )
123
121
124
- # Build a message to the user.
125
- new_msg = '%s (%s) image is%s a %s image.' % (
126
- basename (img_path ),
127
- msg ,
128
- '' if is_img else ' not' ,
129
- img_klass .__name__ )
130
-
131
- if expect_success is None :
132
- assert_true (True , new_msg ) # No expectation, pass if no Exception
133
- # elif is_img != expect_success:
134
- # print('Failed! %s' % new_msg)
135
- else :
136
- assert_equal (is_img , expect_success , new_msg )
122
+ # Check that the image type was recognized.
123
+ new_msg = '%s (%s) image is%s a %s image.' % (
124
+ basename (img_path ),
125
+ msg ,
126
+ '' if is_img else ' not' ,
127
+ img_klass .__name__ )
128
+ assert_true (is_img , new_msg )
137
129
138
130
if sniff_mode == 'vanilla' :
139
131
return new_sniff
@@ -152,23 +144,20 @@ def check_img(img_path, img_klass, sniff_mode, sniff, expect_success, msg):
152
144
153
145
for klass in img_klasses :
154
146
if klass == expected_img_klass :
155
- expect_success = (sniff_mode not in ['bad_sniff' ] or
147
+ # Class will load unless you pass a bad sniff,
148
+ # the header actually uses the sniff, and the
149
+ # sniff check is actually something meaningful
150
+ # (we're looking at you, Minc1Header...)
151
+ expect_success = (sniff_mode != 'bad_sniff' or
156
152
sizeof_hdr == 0 or
157
153
klass == Minc1Image ) # special case...
158
- elif (issubclass (klass , expected_img_klass ) or
159
- issubclass (expected_img_klass , klass )):
160
- expect_success = None # Images are related; can't be sure.
161
154
else :
162
- # Usually, if the two images are unrelated, they
163
- # won't be able to be loaded. But here's a
164
- # list of manually confirmed special cases
165
- expect_success = ((expected_img_klass == Nifti1Pair and klass == Spm99AnalyzeImage ) or
166
- (expected_img_klass == Nifti2Pair and klass == Spm99AnalyzeImage ))
167
-
168
- msg = '%s / %s / %s' % (expected_img_klass .__name__ , sniff_mode , str (expect_success ))
169
- print (msg )
155
+ expect_success = False # Not sure the relationships
156
+
170
157
# Reuse the sniff... but it will only change for some
171
158
# sniff_mode values.
159
+ msg = '%s/ %s/ %s' % (expected_img_klass .__name__ , sniff_mode ,
160
+ str (expect_success ))
172
161
sniff = check_img (img_path , klass , sniff_mode = sniff_mode ,
173
162
sniff = sniff , expect_success = expect_success ,
174
163
msg = msg )
@@ -182,7 +171,7 @@ def check_img(img_path, img_klass, sniff_mode, sniff, expect_success, msg):
182
171
('small.mnc' , Minc2Image ),
183
172
('test.mgz' , MGHImage ),
184
173
('analyze.hdr' , Spm2AnalyzeImage )]:
185
- print ('Testing: %s %s' % (img_filename , image_klass .__name__ ))
174
+ # print('Testing: %s %s' % (img_filename, image_klass.__name__))
186
175
test_image_class (pjoin (DATA_PATH , img_filename ), image_klass )
187
176
188
177
0 commit comments