Skip to content

Commit 075f5e7

Browse files
committed
Added tests for decode_value function
1 parent 538d4dd commit 075f5e7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

nibabel/streamlines/tests/test_trk.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ def test_load_file_with_wrong_information(self):
153153
new_trk_file = trk_file[:996] + hdr_size + trk_file[996+4:]
154154
assert_raises(HeaderError, TrkFile.load, BytesIO(new_trk_file))
155155

156+
# Simulate a TRK file with a wrong scalar_name.
157+
trk_file = open(DATA['complex_trk_fname'], 'rb').read()
158+
noise = np.int32(42).tostring()
159+
new_trk_file = trk_file[:47] + noise + trk_file[47+4:]
160+
assert_raises(HeaderError, TrkFile.load, BytesIO(new_trk_file))
161+
162+
# Simulate a TRK file with a wrong property_name.
163+
noise = np.int32(42).tostring()
164+
new_trk_file = trk_file[:254] + noise + trk_file[254+4:]
165+
assert_raises(HeaderError, TrkFile.load, BytesIO(new_trk_file))
166+
156167
def test_load_complex_file_in_big_endian(self):
157168
trk_file = open(DATA['complex_trk_big_endian_fname'], 'rb').read()
158169
# We use hdr_size as an indicator of little vs big endian.

nibabel/streamlines/trk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import nibabel as nib
1313

1414
from nibabel.openers import Opener
15-
from nibabel.py3k import asbytes, asstr
15+
from nibabel.py3k import asstr
1616
from nibabel.volumeutils import (native_code, swapped_code)
1717
from nibabel.orientations import (aff2axcodes, axcodes2ornt)
1818

@@ -203,7 +203,7 @@ def decode_value_from_name(encoded_name):
203203
elif len(splits) > 2:
204204
# The remaining bytes are not \x00, raising.
205205
msg = ("Wrong scalar_name or property_name: '{}'."
206-
" Unused characters should be \\x00.").format(name)
206+
" Unused characters should be \\x00.").format(encoded_name)
207207
raise HeaderError(msg)
208208

209209
return name, value

0 commit comments

Comments
 (0)