@@ -416,6 +416,34 @@ def validate_shape_deprecated(self, imaker, params):
416
416
assert_equal (img .get_shape (), params ['shape' ])
417
417
assert_equal (len (w ), 1 )
418
418
419
+ def validate_mmap_parameter (self , imaker , params ):
420
+ img = imaker ()
421
+ fname = img .get_filename ()
422
+ with InTemporaryDirectory ():
423
+ # Load test files with mmap parameters
424
+ # or
425
+ # Save a generated file so we can test it
426
+ if fname is None :
427
+ # Skip only formats we can't write
428
+ if not img .rw or not img .valid_exts :
429
+ return
430
+ fname = 'image' + img .valid_exts [0 ]
431
+ img .to_filename (fname )
432
+ rt_img = img .__class__ .from_filename (fname , mmap = True )
433
+ assert_almost_equal (img .get_fdata (), rt_img .get_fdata ())
434
+ rt_img = img .__class__ .from_filename (fname , mmap = False )
435
+ assert_almost_equal (img .get_fdata (), rt_img .get_fdata ())
436
+ rt_img = img .__class__ .from_filename (fname , mmap = 'c' )
437
+ assert_almost_equal (img .get_fdata (), rt_img .get_fdata ())
438
+ rt_img = img .__class__ .from_filename (fname , mmap = 'r' )
439
+ assert_almost_equal (img .get_fdata (), rt_img .get_fdata ())
440
+ # r+ is specifically not valid for images
441
+ assert_raises (ValueError ,
442
+ img .__class__ .from_filename , fname , mmap = 'r+' )
443
+ assert_raises (ValueError ,
444
+ img .__class__ .from_filename , fname , mmap = 'invalid' )
445
+ del rt_img # to allow windows to delete the directory
446
+
419
447
420
448
class HeaderShapeMixin (object ):
421
449
""" Tests that header shape can be set and got
0 commit comments