Skip to content

Commit 685256d

Browse files
committed
NF - wrapstruct == non wrapstruct returns False
It was previously raising AttributeErrors trying to find the parts to compare.
1 parent a80d2be commit 685256d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

nibabel/tests/test_wrapstruct.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def test__eq__(self):
138138
# Check byteswapping maintains equality
139139
hdr3 = hdr2.as_byteswapped()
140140
assert_equal(hdr2, hdr3)
141+
# Check comparing to funny thing says no
142+
assert_not_equal(hdr1, None)
143+
assert_not_equal(hdr1, 1)
141144

142145
def test_to_from_fileobj(self):
143146
# Successful write using write_to

nibabel/wrapstruct.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,13 @@ def __eq__(self, other):
289289
'''
290290
this_end = self.endianness
291291
this_bb = self.binaryblock
292-
if this_end == other.endianness:
293-
return this_bb == other.binaryblock
292+
try:
293+
other_end = other.endianness
294+
other_bb = other.binaryblock
295+
except AttributeError:
296+
return False
297+
if this_end == other_end:
298+
return this_bb == other_bb
294299
other_bb = other._structarr.byteswap().tostring()
295300
return this_bb == other_bb
296301

0 commit comments

Comments
 (0)