Skip to content

Commit 9699520

Browse files
committed
TST - add tests for version checks and endian writing
1 parent 903f63b commit 9699520

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

nibabel/tests/test_trackvis.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from ..py3k import BytesIO, asbytes
66
from .. import trackvis as tv
7-
from ..volumeutils import swapped_code
7+
from ..volumeutils import native_code, swapped_code
88

99
from nose.tools import assert_true, assert_false, assert_equal, assert_raises
1010

@@ -116,12 +116,18 @@ def test_round_trip():
116116
out_f.seek(0)
117117
streams2, hdr = tv.read(out_f)
118118
assert_true(streamlist_equal(streams, streams2))
119-
# test that we can write in different endianness and get back same result
120-
out_f.seek(0)
121-
tv.write(out_f, streams, {}, swapped_code)
122-
out_f.seek(0)
123-
streams2, hdr = tv.read(out_f)
124-
assert_true(streamlist_equal(streams, streams2))
119+
# test that we can write in different endianness and get back same result,
120+
# for versions 1, 2 and not-specified
121+
for in_dict, back_version in (({},2),
122+
({'version':2}, 2),
123+
({'version':1}, 1)):
124+
for endian_code in (native_code, swapped_code):
125+
out_f.seek(0)
126+
tv.write(out_f, streams, in_dict, endian_code)
127+
out_f.seek(0)
128+
streams2, hdr = tv.read(out_f)
129+
assert_true(streamlist_equal(streams, streams2))
130+
assert_equal(hdr['version'], back_version)
125131
# test that we can get out and pass in generators
126132
out_f.seek(0)
127133
streams3, hdr = tv.read(out_f, as_generator=True)
@@ -162,24 +168,24 @@ def test_get_affine():
162168
hdr = tv.empty_header()
163169
# default header gives useless affine
164170
assert_array_equal(tv.aff_from_hdr(hdr),
165-
np.diag([0,0,0,1]))
171+
np.diag([0,0,0,1]))
166172
hdr['voxel_size'] = 1
167173
assert_array_equal(tv.aff_from_hdr(hdr),
168-
np.diag([0,0,0,1]))
174+
np.diag([0,0,0,1]))
169175
# DICOM direction cosines
170176
hdr['image_orientation_patient'] = [1,0,0,0,1,0]
171177
assert_array_equal(tv.aff_from_hdr(hdr),
172-
np.diag([-1,-1,1,1]))
178+
np.diag([-1,-1,1,1]))
173179
# RAS direction cosines
174180
hdr['image_orientation_patient'] = [-1,0,0,0,-1,0]
175181
assert_array_equal(tv.aff_from_hdr(hdr),
176-
np.eye(4))
182+
np.eye(4))
177183
# translations
178184
hdr['origin'] = [1,2,3]
179185
exp_aff = np.eye(4)
180186
exp_aff[:3,3] = [-1,-2,3]
181187
assert_array_equal(tv.aff_from_hdr(hdr),
182-
exp_aff)
188+
exp_aff)
183189
# now use the easier vox_to_ras field
184190
hdr = tv.empty_header()
185191
aff = np.eye(4)

0 commit comments

Comments
 (0)