Skip to content

Commit 9eccf32

Browse files
committed
TEST: Move special case header equality check into TestSerializableImageAPI
1 parent 7867a59 commit 9eccf32

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

nibabel/tests/test_filebasedimages.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ def obj_params(self):
8787
class TestSerializableImageAPI(TestFBImageAPI, SerializeMixin):
8888
image_maker = SerializableNumpyImage
8989

90+
@staticmethod
91+
def _header_eq(header_a, header_b):
92+
""" FileBasedHeader is an abstract class, so __eq__ is undefined.
93+
Checking for the same header type is sufficient, here. """
94+
return type(header_a) == type(header_b) == FileBasedHeader
95+
9096

9197
def test_filebased_header():
9298
# Test stuff about the default FileBasedHeader

nibabel/tests/test_image_api.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -545,19 +545,13 @@ def validate_to_from_bytes(self, imaker, params):
545545

546546
@staticmethod
547547
def _header_eq(header_a, header_b):
548-
""" Quick-and-dirty header equality check
548+
""" Header equality check that can be overridden by a subclass of this test
549549
550-
Abstract classes may have undefined equality, in which case test for
551-
same type
550+
This allows us to retain the same tests above when testing an image that uses an
551+
abstract class as a header, namely when testing the FileBasedImage API, which
552+
raises a NotImplementedError for __eq__
552553
"""
553-
not_implemented = False
554-
header_eq = True
555-
try:
556-
header_eq = header_a == header_b
557-
except NotImplementedError:
558-
header_eq = type(header_a) == type(header_b)
559-
560-
return header_eq
554+
return header_a == header_b
561555

562556

563557

0 commit comments

Comments
 (0)