@@ -493,6 +493,19 @@ def validate_affine_deprecated(self, imaker, params):
493493 assert_true (aff is img .get_affine ())
494494
495495
496+ class SerializeMixin (object ):
497+
498+ def validate_serialize (self , imaker , params ):
499+ img = imaker ()
500+ serialized = img .serialize ()
501+ with InTemporaryDirectory ():
502+ fname = 'img' + self .standard_extension
503+ img .to_filename (fname )
504+ with open (fname , 'rb' ) as fobj :
505+ file_contents = fobj .read ()
506+ assert serialized == file_contents
507+
508+
496509class LoadImageAPI (GenericImageAPI ,
497510 DataInterfaceMixin ,
498511 AffineMixin ,
@@ -613,7 +626,7 @@ class TestNifti1PairAPI(TestSpm99AnalyzeAPI):
613626 can_save = True
614627
615628
616- class TestNifti1API (TestNifti1PairAPI ):
629+ class TestNifti1API (TestNifti1PairAPI , SerializeMixin ):
617630 klass = image_maker = Nifti1Image
618631 standard_extension = '.nii'
619632
@@ -660,7 +673,7 @@ def loader(self, fname):
660673# standard_extension = '.v'
661674
662675
663- class TestMGHAPI (ImageHeaderAPI ):
676+ class TestMGHAPI (ImageHeaderAPI , SerializeMixin ):
664677 klass = image_maker = MGHImage
665678 example_shapes = ((2 , 3 , 4 ), (2 , 3 , 4 , 5 )) # MGH can only do >= 3D
666679 has_scaling = True
0 commit comments