Skip to content

Commit bd57006

Browse files
committed
fix: one more test case, reaching EOF
1 parent 48d0f73 commit bd57006

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

nibabel/streamlines/tck.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,17 @@ def _read_header(cls, fileobj):
327327

328328
f.fobj.seek(1, os.SEEK_CUR) # Skip \n
329329

330-
# Read all key-value pairs contained in the header
330+
found_end = False
331+
332+
# Read all key-value pairs contained in the header, stop at EOF
331333
for n_line, line in enumerate(f.fobj, 1):
332334
line = asstr(line).strip()
333335

334336
if not line: # Skip empty lines
335337
continue
336338

337339
if line == "END": # End of the header
340+
found_end = True
338341
break
339342

340343
if ':' not in line: # Invalid header line
@@ -343,6 +346,9 @@ def _read_header(cls, fileobj):
343346
key, value = line.split(":", 1)
344347
hdr[key.strip()] = value.strip()
345348

349+
if not found_end:
350+
raise HeaderError("Missing END in the header.")
351+
346352
offset_data = f.tell()
347353

348354
# Set the file position where it was, in case it was previously open

nibabel/streamlines/tests/test_tck.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ def setup_module():
2525
global DATA
2626

2727
DATA['empty_tck_fname'] = pjoin(data_path, "empty.tck")
28-
DATA['no-magic-number_tck_fname'] = pjoin(data_path, "no-magic-number.tck")
29-
DATA['no-header-end_tck_fname'] = pjoin(data_path, "no-header-end.tck")
28+
DATA['no_magic_number_tck_fname'] = pjoin(data_path, "no_magic_number.tck")
29+
DATA['no_header_end_tck_fname'] = pjoin(data_path, "no_header_end.tck")
30+
DATA['no_header_end_eof_tck_fname'] = pjoin(data_path, "no_header_end_eof.tck")
3031
# simple.tck contains only streamlines
3132
DATA['simple_tck_fname'] = pjoin(data_path, "simple.tck")
3233
DATA['simple_tck_big_endian_fname'] = pjoin(data_path,
@@ -56,15 +57,23 @@ def test_load_no_magic_number_file(self):
5657
for lazy_load in [False, True]:
5758
with pytest.raises(HeaderError):
5859
TckFile.load(
59-
DATA['no-magic-number_tck_fname'],
60+
DATA['no_magic_number_tck_fname'],
6061
lazy_load=lazy_load
6162
)
6263

6364
def test_load_no_header_end_file(self):
6465
for lazy_load in [False, True]:
6566
with pytest.raises(HeaderError):
6667
TckFile.load(
67-
DATA['no-header-end_tck_fname'],
68+
DATA['no_header_end_tck_fname'],
69+
lazy_load=lazy_load
70+
)
71+
72+
def test_load_no_header_end_eof_file(self):
73+
for lazy_load in [False, True]:
74+
with pytest.raises(HeaderError):
75+
TckFile.load(
76+
DATA['no_header_end_eof_tck_fname'],
6877
lazy_load=lazy_load
6978
)
7079

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mrtrix tracks
2+
count: 0000000000
3+
datatype: Float32LE
4+
file: . 67
File renamed without changes.

0 commit comments

Comments
 (0)