24
24
25
25
import warnings
26
26
from functools import partial
27
+ from ..externals .six import string_types
27
28
28
29
import numpy as np
29
30
@@ -283,11 +284,21 @@ class LoadImageAPI(GenericImageAPI):
283
284
# Sequence of dictionaries, where dictionaries have keys
284
285
# 'fname" in addition to keys for ``params`` (see obj_params docstring)
285
286
example_images = ()
287
+ # Class of images to be tested
288
+ klass = None
286
289
287
290
def obj_params (self ):
288
291
for img_params in self .example_images :
289
292
yield lambda : self .loader (img_params ['fname' ]), img_params
290
293
294
+ def validate_path_maybe_image (self , imaker , params ):
295
+ for img_params in self .example_images :
296
+ test , sniff = self .klass .path_maybe_image (img_params ['fname' ])
297
+ assert_true (isinstance (test , bool ))
298
+ if sniff is not None :
299
+ assert isinstance (sniff [0 ], bytes )
300
+ assert isinstance (sniff [1 ], string_types )
301
+
291
302
292
303
class MakeImageAPI (LoadImageAPI ):
293
304
""" Validation for images we can make with ``func(data, affine, header)``
@@ -346,48 +357,48 @@ def header_maker(self):
346
357
class TestAnalyzeAPI (ImageHeaderAPI ):
347
358
""" General image validation API instantiated for Analyze images
348
359
"""
349
- image_maker = AnalyzeImage
360
+ klass = image_maker = AnalyzeImage
350
361
has_scaling = False
351
362
can_save = True
352
363
standard_extension = '.img'
353
364
354
365
355
366
class TestSpatialImageAPI (TestAnalyzeAPI ):
356
- image_maker = SpatialImage
367
+ klass = image_maker = SpatialImage
357
368
can_save = False
358
369
359
370
360
371
class TestSpm99AnalyzeAPI (TestAnalyzeAPI ):
361
372
# SPM-type analyze need scipy for mat file IO
362
- image_maker = Spm99AnalyzeImage
373
+ klass = image_maker = Spm99AnalyzeImage
363
374
has_scaling = True
364
375
can_save = have_scipy
365
376
366
377
367
378
class TestSpm2AnalyzeAPI (TestSpm99AnalyzeAPI ):
368
- image_maker = Spm2AnalyzeImage
379
+ klass = image_maker = Spm2AnalyzeImage
369
380
370
381
371
382
class TestNifti1PairAPI (TestSpm99AnalyzeAPI ):
372
- image_maker = Nifti1Pair
383
+ klass = image_maker = Nifti1Pair
373
384
can_save = True
374
385
375
386
376
387
class TestNifti1API (TestNifti1PairAPI ):
377
- image_maker = Nifti1Image
388
+ klass = image_maker = Nifti1Image
378
389
standard_extension = '.nii'
379
390
380
391
381
392
class TestNifti2PairAPI (TestNifti1PairAPI ):
382
- image_maker = Nifti2Pair
393
+ klass = image_maker = Nifti2Pair
383
394
384
395
385
396
class TestNifti2API (TestNifti1API ):
386
- image_maker = Nifti2Image
397
+ klass = image_maker = Nifti2Image
387
398
388
399
389
400
class TestMinc1API (ImageHeaderAPI ):
390
- image_maker = Minc1Image
401
+ klass = image_maker = Minc1Image
391
402
loader = minc1 .load
392
403
example_images = MINC1_EXAMPLE_IMAGES
393
404
@@ -397,7 +408,7 @@ def __init__(self):
397
408
if not have_h5py :
398
409
raise SkipTest ('Need h5py for these tests' )
399
410
400
- image_maker = Minc2Image
411
+ klass = image_maker = Minc2Image
401
412
loader = minc2 .load
402
413
example_images = MINC2_EXAMPLE_IMAGES
403
414
@@ -406,6 +417,7 @@ class TestPARRECAPI(LoadImageAPI):
406
417
def loader (self , fname ):
407
418
return parrec .load (fname )
408
419
420
+ klass = parrec .PARRECImage
409
421
example_images = PARREC_EXAMPLE_IMAGES
410
422
411
423
@@ -418,7 +430,7 @@ def loader(self, fname):
418
430
419
431
420
432
class TestMGHAPI (ImageHeaderAPI ):
421
- image_maker = MGHImage
433
+ klass = image_maker = MGHImage
422
434
example_shapes = ((2 , 3 , 4 ), (2 , 3 , 4 , 5 )) # MGH can only do >= 3D
423
435
has_scaling = True
424
436
can_save = True
0 commit comments