Skip to content

Commit d568d0b

Browse files
committed
TEST: Add check to make sure WrapStruct.get supports storage of values which
evaluate to False
1 parent 2486482 commit d568d0b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

nibabel/tests/test_wrapstruct.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ def test_mappingness(self):
183183
assert_equal(hdr.get(keys[0]), vals[0])
184184
assert_equal(hdr.get(keys[0], 'default'), vals[0])
185185

186+
# make sure .get returns values
187+
# which evaluate to False. We
188+
# have to use a different falsy
189+
# value depending on the data
190+
# type of the first header field.
191+
if np.issubdtype(hdr_dt[0], np.number):
192+
falsyval = 0
193+
else:
194+
falsyval = ''
195+
196+
hdr[keys[0]] = falsyval
197+
assert_equal(hdr[keys[0]], falsyval)
198+
assert_equal(hdr.get(keys[0]), falsyval)
199+
assert_equal(hdr.get(keys[0], -1), falsyval)
200+
201+
186202
def test_endianness_ro(self):
187203
# endianness is a read only property
188204
''' Its use in initialization tested in the init tests.

0 commit comments

Comments
 (0)