@@ -505,24 +505,36 @@ def validate_to_bytes(self, imaker, params):
505505 assert serialized == file_contents
506506
507507 def validate_from_bytes (self , imaker , params ):
508- for img_params in self . example_images :
509- img_a = self . klass . from_filename ( img_params [ 'fname' ])
510- with open ( img_params [ ' fname' ], 'rb' ) as fobj :
511- img_b = self . klass . from_bytes ( fobj . read () )
508+ img = imaker ()
509+ with InTemporaryDirectory ():
510+ fname = 'img' + self . standard_extension
511+ img . to_filename ( fname )
512512
513- assert img_a .header == img_b .header
514- assert np .array_equal (img_a .get_data (), img_b .get_data ())
513+ all_images = list (getattr (self , 'example_images' , [])) + [{'fname' : fname }]
514+ for img_params in all_images :
515+ img_a = self .klass .from_filename (img_params ['fname' ])
516+ with open (img_params ['fname' ], 'rb' ) as fobj :
517+ img_b = self .klass .from_bytes (fobj .read ())
515518
516- def validate_round_trip (self , imaker , params ):
517- for img_params in self .example_images :
518- img_a = self .klass .from_filename (img_params ['fname' ])
519- bytes_a = img_a .to_bytes ()
519+ assert img_a .header == img_b .header
520+ assert np .array_equal (img_a .get_data (), img_b .get_data ())
521+
522+ def validate_to_from_bytes (self , imaker , params ):
523+ img = imaker ()
524+ with InTemporaryDirectory ():
525+ fname = 'img' + self .standard_extension
526+ img .to_filename (fname )
527+
528+ all_images = list (getattr (self , 'example_images' , [])) + [{'fname' : fname }]
529+ for img_params in all_images :
530+ img_a = self .klass .from_filename (img_params ['fname' ])
531+ bytes_a = img_a .to_bytes ()
520532
521- img_b = self .klass .from_bytes (bytes_a )
533+ img_b = self .klass .from_bytes (bytes_a )
522534
523- assert img_b .to_bytes () == bytes_a
524- assert img_a .header == img_b .header
525- assert np .array_equal (img_a .get_data (), img_b .get_data ())
535+ assert img_b .to_bytes () == bytes_a
536+ assert img_a .header == img_b .header
537+ assert np .array_equal (img_a .get_data (), img_b .get_data ())
526538
527539
528540class LoadImageAPI (GenericImageAPI ,
0 commit comments