@@ -506,36 +506,55 @@ def validate_to_bytes(self, imaker, params):
506
506
507
507
def validate_from_bytes (self , imaker , params ):
508
508
img = imaker ()
509
+ klass = getattr (self , 'klass' , img .__class__ )
509
510
with InTemporaryDirectory ():
510
511
fname = 'img' + self .standard_extension
511
512
img .to_filename (fname )
512
513
513
514
all_images = list (getattr (self , 'example_images' , [])) + [{'fname' : fname }]
514
515
for img_params in all_images :
515
- img_a = self . klass .from_filename (img_params ['fname' ])
516
+ img_a = klass .from_filename (img_params ['fname' ])
516
517
with open (img_params ['fname' ], 'rb' ) as fobj :
517
- img_b = self . klass .from_bytes (fobj .read ())
518
+ img_b = klass .from_bytes (fobj .read ())
518
519
519
- assert img_a .header == img_b .header
520
+ assert self . _header_eq ( img_a .header , img_b .header )
520
521
assert np .array_equal (img_a .get_data (), img_b .get_data ())
521
522
522
523
def validate_to_from_bytes (self , imaker , params ):
523
524
img = imaker ()
525
+ klass = getattr (self , 'klass' , img .__class__ )
524
526
with InTemporaryDirectory ():
525
527
fname = 'img' + self .standard_extension
526
528
img .to_filename (fname )
527
529
528
530
all_images = list (getattr (self , 'example_images' , [])) + [{'fname' : fname }]
529
531
for img_params in all_images :
530
- img_a = self . klass .from_filename (img_params ['fname' ])
532
+ img_a = klass .from_filename (img_params ['fname' ])
531
533
bytes_a = img_a .to_bytes ()
532
534
533
- img_b = self . klass .from_bytes (bytes_a )
535
+ img_b = klass .from_bytes (bytes_a )
534
536
535
537
assert img_b .to_bytes () == bytes_a
536
- assert img_a .header == img_b .header
538
+ assert self . _header_eq ( img_a .header , img_b .header )
537
539
assert np .array_equal (img_a .get_data (), img_b .get_data ())
538
540
541
+ @staticmethod
542
+ def _header_eq (header_a , header_b ):
543
+ """ Quick-and-dirty header equality check
544
+
545
+ Abstract classes may have undefined equality, in which case test for
546
+ same type
547
+ """
548
+ not_implemented = False
549
+ header_eq = True
550
+ try :
551
+ header_eq = header_a == header_b
552
+ except NotImplementedError :
553
+ header_eq = type (header_a ) == type (header_b )
554
+
555
+ return header_eq
556
+
557
+
539
558
540
559
class LoadImageAPI (GenericImageAPI ,
541
560
DataInterfaceMixin ,
0 commit comments