Skip to content

Commit 3b753dc

Browse files
committed
Refactored TRK file. Removed unnecessary classmethod in TractogramFile
1 parent 196761a commit 3b753dc

File tree

5 files changed

+80
-281
lines changed

5 files changed

+80
-281
lines changed

nibabel/streamlines/tests/test_streamlines.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ def test_is_supported_detect_format():
8585
# Valid file without extension
8686
for tfile_cls in nib.streamlines.FORMATS.values():
8787
f = BytesIO()
88-
f.write(tfile_cls.get_magic_number())
88+
f.write(tfile_cls.MAGIC_NUMBER)
8989
f.seek(0, os.SEEK_SET)
9090
assert_true(nib.streamlines.is_supported(f))
9191
assert_true(nib.streamlines.detect_format(f) is tfile_cls)
9292

9393
# Wrong extension but right magic number
9494
for tfile_cls in nib.streamlines.FORMATS.values():
9595
with tempfile.TemporaryFile(mode="w+b", suffix=".txt") as f:
96-
f.write(tfile_cls.get_magic_number())
96+
f.write(tfile_cls.MAGIC_NUMBER)
9797
f.seek(0, os.SEEK_SET)
9898
assert_true(nib.streamlines.is_supported(f))
9999
assert_true(nib.streamlines.detect_format(f) is tfile_cls)
@@ -169,11 +169,12 @@ def test_load_complex_file(self):
169169

170170
tractogram = Tractogram(DATA['streamlines'])
171171

172-
if tfile.support_data_per_point():
172+
if tfile.SUPPORTS_DATA_PER_POINT:
173173
tractogram.data_per_point = DATA['data_per_point']
174174

175-
if tfile.support_data_per_streamline():
176-
tractogram.data_per_streamline = DATA['data_per_streamline']
175+
if tfile.SUPPORTS_DATA_PER_STREAMLINE:
176+
data = DATA['data_per_streamline']
177+
tractogram.data_per_streamline = data
177178

178179
assert_tractogram_equal(tfile.tractogram,
179180
tractogram)
@@ -236,18 +237,19 @@ def test_save_complex_file(self):
236237
# If streamlines format does not support saving data
237238
# per point or data per streamline, a warning message
238239
# should be issued.
239-
if not (cls.support_data_per_point() and
240-
cls.support_data_per_streamline()):
240+
if not (cls.SUPPORTS_DATA_PER_POINT and
241+
cls.SUPPORTS_DATA_PER_STREAMLINE):
241242
assert_equal(len(w), 1)
242243
assert_true(issubclass(w[0].category, Warning))
243244

244245
tractogram = Tractogram(DATA['streamlines'])
245246

246-
if cls.support_data_per_point():
247+
if cls.SUPPORTS_DATA_PER_POINT:
247248
tractogram.data_per_point = DATA['data_per_point']
248249

249-
if cls.support_data_per_streamline():
250-
tractogram.data_per_streamline = DATA['data_per_streamline']
250+
if cls.SUPPORTS_DATA_PER_STREAMLINE:
251+
data = DATA['data_per_streamline']
252+
tractogram.data_per_streamline = data
251253

252254
tfile = nib.streamlines.load(filename, lazy_load=False)
253255
assert_tractogram_equal(tfile.tractogram, tractogram)

nibabel/streamlines/tests/test_tractogram_file.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ def test_subclassing_tractogram_file():
88

99
# Missing 'save' method
1010
class DummyTractogramFile(TractogramFile):
11-
@classmethod
12-
def get_magic_number(cls):
13-
return False
14-
15-
@classmethod
16-
def support_data_per_point(cls):
17-
return False
18-
19-
@classmethod
20-
def support_data_per_streamline(cls):
21-
return False
22-
2311
@classmethod
2412
def is_correct_format(cls, fileobj):
2513
return False
@@ -32,18 +20,6 @@ def load(cls, fileobj, lazy_load=True):
3220

3321
# Missing 'load' method
3422
class DummyTractogramFile(TractogramFile):
35-
@classmethod
36-
def get_magic_number(cls):
37-
return False
38-
39-
@classmethod
40-
def support_data_per_point(cls):
41-
return False
42-
43-
@classmethod
44-
def support_data_per_streamline(cls):
45-
return False
46-
4723
@classmethod
4824
def is_correct_format(cls, fileobj):
4925
return False
@@ -55,26 +31,11 @@ def save(self, fileobj):
5531

5632

5733
def test_tractogram_file():
58-
assert_raises(NotImplementedError, TractogramFile.get_magic_number)
5934
assert_raises(NotImplementedError, TractogramFile.is_correct_format, "")
60-
assert_raises(NotImplementedError, TractogramFile.support_data_per_point)
61-
assert_raises(NotImplementedError, TractogramFile.support_data_per_streamline)
6235
assert_raises(NotImplementedError, TractogramFile.load, "")
6336

6437
# Testing calling the 'save' method of `TractogramFile` object.
6538
class DummyTractogramFile(TractogramFile):
66-
@classmethod
67-
def get_magic_number(cls):
68-
return False
69-
70-
@classmethod
71-
def support_data_per_point(cls):
72-
return False
73-
74-
@classmethod
75-
def support_data_per_streamline(cls):
76-
return False
77-
7839
@classmethod
7940
def is_correct_format(cls, fileobj):
8041
return False

nibabel/streamlines/tests/test_trk.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from nibabel.externals.six import BytesIO
77

88
from nibabel.testing import suppress_warnings, clear_and_catch_warnings
9-
from nibabel.testing import assert_arrays_equal, check_iteration
9+
from nibabel.testing import assert_arrays_equal
1010
from nose.tools import assert_equal, assert_raises, assert_true
1111
from numpy.testing import assert_array_equal
1212

@@ -431,13 +431,3 @@ def test_write_scalars_and_properties_name_too_long(self):
431431
def test_str(self):
432432
trk = TrkFile.load(self.complex_trk_filename)
433433
str(trk) # Simply test it's not failing when called.
434-
435-
def test_read_buffer_size(self):
436-
tmp = TrkFile.READ_BUFFER_SIZE
437-
TrkFile.READ_BUFFER_SIZE = 1
438-
439-
for lazy_load in [False, True]:
440-
trk = TrkFile.load(self.complex_trk_filename, lazy_load=lazy_load)
441-
assert_tractogram_equal(trk.tractogram, self.complex_tractogram)
442-
443-
TrkFile.READ_BUFFER_SIZE = tmp

nibabel/streamlines/tractogram_file.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,6 @@ def get_affine(self):
6464
""" Returns vox -> rasmm affine. """
6565
return self.affine
6666

67-
@abstractclassmethod
68-
def get_magic_number(cls):
69-
""" Returns streamlines file's magic number. """
70-
raise NotImplementedError()
71-
72-
@abstractclassmethod
73-
def support_data_per_point(cls):
74-
""" Tells if this format supports saving data per point. """
75-
raise NotImplementedError()
76-
77-
@abstractclassmethod
78-
def support_data_per_streamline(cls):
79-
""" Tells if this format supports saving data per streamline. """
80-
raise NotImplementedError()
81-
8267
@abstractclassmethod
8368
def is_correct_format(cls, fileobj):
8469
""" Checks if the file has the right streamlines file format.

0 commit comments

Comments
 (0)