Skip to content

Commit fa73ad4

Browse files
committed
TEST: Test MGHHeader._HeaderData fully
1 parent 3f62445 commit fa73ad4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

nibabel/freesurfer/tests/test_mghformat.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,12 @@ def test_mghheader_default_structarr():
340340

341341
def test_deprecated_fields():
342342
hdr = MGHHeader()
343+
hdr_data = MGHHeader._HeaderData(hdr.structarr)
343344

344345
# mrparams is the only deprecated field at the moment
346+
# Accessing hdr_data is equivalent to accessing hdr, so double all checks
345347
assert_array_equal(hdr['mrparams'], 0)
348+
assert_array_equal(hdr_data['mrparams'], 0)
346349

347350
hdr['mrparams'] = [1, 2, 3, 4]
348351
assert_array_almost_equal(hdr['mrparams'], [1, 2, 3, 4])
@@ -351,12 +354,26 @@ def test_deprecated_fields():
351354
assert_equal(hdr['te'], 3)
352355
assert_equal(hdr['ti'], 4)
353356
assert_equal(hdr['fov'], 0)
357+
assert_array_almost_equal(hdr_data['mrparams'], [1, 2, 3, 4])
358+
assert_equal(hdr_data['tr'], 1)
359+
assert_equal(hdr_data['flip_angle'], 2)
360+
assert_equal(hdr_data['te'], 3)
361+
assert_equal(hdr_data['ti'], 4)
362+
assert_equal(hdr_data['fov'], 0)
354363

355364
hdr['tr'] = 5
356365
hdr['flip_angle'] = 6
357366
hdr['te'] = 7
358367
hdr['ti'] = 8
359368
assert_array_almost_equal(hdr['mrparams'], [5, 6, 7, 8])
369+
assert_array_almost_equal(hdr_data['mrparams'], [5, 6, 7, 8])
370+
371+
hdr_data['tr'] = 9
372+
hdr_data['flip_angle'] = 10
373+
hdr_data['te'] = 11
374+
hdr_data['ti'] = 12
375+
assert_array_almost_equal(hdr['mrparams'], [9, 10, 11, 12])
376+
assert_array_almost_equal(hdr_data['mrparams'], [9, 10, 11, 12])
360377

361378

362379
class TestMGHImage(tsi.TestSpatialImage, tsi.MmapImageMixin):
@@ -379,7 +396,7 @@ def _set_something_into_hdr(self, hdr):
379396
hdr['dims'] = [4, 3, 2, 1]
380397

381398
def get_bad_bb(self):
382-
return b'\xff' + bytes(self.header_class._hdrdtype.itemsize)
399+
return b'\xff' + b'\x00' * self.header_class._hdrdtype.itemsize
383400

384401
# Update tests to account for big-endian requirement
385402
def test_general_init(self):

0 commit comments

Comments
 (0)