Skip to content

Commit a042e27

Browse files
matthew-bretteffigies
authored andcommitted
MAINT: PEP8 and import cleanup for cifti2 tests
No functional changes.
1 parent 06313c9 commit a042e27

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

nibabel/cifti2/tests/test_cifti2.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55

66
import numpy as np
77

8-
from ...nifti1 import data_type_codes, intent_codes
9-
10-
from ... import cifti2 as ci
11-
12-
from numpy.testing import (assert_array_almost_equal,
13-
assert_array_equal)
14-
15-
from nose.tools import assert_true, assert_equal, assert_raises, assert_is_none
8+
from nibabel import cifti2 as ci
169

10+
from nose.tools import assert_equal, assert_raises, assert_is_none
1711

1812

1913
def compare_xml_leaf(str1, str2):
@@ -27,6 +21,7 @@ def compare_xml_leaf(str1, str2):
2721
print((x2.tag, x2.attrib, x2.text))
2822
return test
2923

24+
3025
def test_cifti2_metadata():
3126
md = ci.Cifti2MetaData()
3227
assert_equal(len(md), 0)
@@ -61,6 +56,7 @@ def test_cifti2_metadata():
6156
assert_equal(md.to_xml().decode('utf-8'),
6257
'<MetaData><MD><Name>b</Name><Value>bval</Value></MD></MetaData>')
6358

59+
6460
def test_cifti2_labeltable():
6561
lt = ci.Cifti2LabelTable()
6662
assert_equal(len(lt), 0)
@@ -90,7 +86,6 @@ def test_cifti2_labeltable():
9086
assert_raises(ValueError, lt.__setitem__, 0, test_tuple[:-1])
9187

9288

93-
9489
def test_cifti2_label():
9590
lb = ci.Cifti2Label()
9691
lb.label = 'Test'
@@ -120,11 +115,13 @@ def test_cifti2_label():
120115
assert_raises(ci.CIFTI2HeaderError, lb.to_xml)
121116
lb.key = 0
122117

118+
123119
def test_cifti2_parcel():
124120
pl = ci.Cifti2Parcel()
125121
assert_raises(ci.CIFTI2HeaderError, pl.to_xml)
126122
assert_raises(TypeError, pl.append_cifti_vertices, None)
127123

124+
128125
def test_cifti2_vertices():
129126
vs = ci.Cifti2Vertices()
130127
assert_raises(ci.CIFTI2HeaderError, vs.to_xml)
@@ -146,18 +143,22 @@ def test_cifti2_vertices():
146143
assert_equal(vs[0], 10)
147144
assert_equal(len(vs), 3)
148145

146+
149147
def test_cifti2_transformationmatrixvoxelindicesijktoxyz():
150148
tr = ci.Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ()
151149
assert_raises(ci.CIFTI2HeaderError, tr.to_xml)
152150

151+
153152
def test_cifti2_surface():
154153
s = ci.Cifti2Surface()
155154
assert_raises(ci.CIFTI2HeaderError, s.to_xml)
156155

156+
157157
def test_cifti2_volume():
158158
vo = ci.Cifti2Volume()
159159
assert_raises(ci.CIFTI2HeaderError, vo.to_xml)
160160

161+
161162
def test_cifti2_vertexindices():
162163
vi = ci.Cifti2VertexIndices()
163164
assert_equal(len(vi), 0)
@@ -172,7 +173,7 @@ def test_cifti2_vertexindices():
172173
vi[0] = 10
173174
assert_equal(vi[0], 10)
174175
assert_equal(len(vi), 3)
175-
176+
176177

177178
def test_cifti2_voxelindicesijk():
178179
vi = ci.Cifti2VoxelIndicesIJK()
@@ -214,6 +215,7 @@ def test_cifti2_voxelindicesijk():
214215
'<VoxelIndicesIJK>0 1 2\n3 4 6</VoxelIndicesIJK>'
215216
)
216217

218+
217219
def test_matrixindicesmap():
218220
mim = ci.Cifti2MatrixIndicesMap(0, 'CIFTI_INDEX_TYPE_LABELS')
219221
volume = ci.Cifti2Volume()
@@ -243,6 +245,7 @@ def test_matrixindicesmap():
243245

244246
assert_raises(ValueError, setattr, mim, 'volume', parcel)
245247

248+
246249
def test_matrix():
247250
m = ci.Cifti2Matrix()
248251
assert_raises(TypeError, m, setattr, 'metadata', ci.Cifti2Parcel())

nibabel/cifti2/tests/test_cifti2io.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99
from __future__ import division, print_function, absolute_import
1010

1111
from os.path import join as pjoin, dirname
12-
import sys
1312
import io
1413
from distutils.version import LooseVersion
1514

16-
import numpy as np
17-
1815
import nibabel as nib
1916
from nibabel import cifti2 as ci
2017
from nibabel.tmpdirs import InTemporaryDirectory
2118
from nibabel.tests.nibabel_data import get_nibabel_data, needs_nibabel_data
2219

23-
from numpy.testing import assert_array_equal, assert_array_almost_equal
24-
from nose.tools import (assert_true, assert_false, assert_equal,
25-
assert_raises)
20+
from numpy.testing import assert_array_almost_equal
21+
from nose.tools import (assert_true, assert_equal, assert_raises)
2622

2723
NIBABEL_TEST_DATA = pjoin(dirname(nib.__file__), 'tests', 'data')
2824
NIFTI2_DATA = pjoin(NIBABEL_TEST_DATA, 'example_nifti2.nii.gz')
@@ -48,24 +44,28 @@ def test_read_nifti2():
4844
filemap[k].fileobj = io.open(NIFTI2_DATA)
4945
assert_raises(ValueError, ci.Cifti2Image.from_file_map, filemap)
5046

47+
5148
@needs_nibabel_data('nitest-cifti2')
5249
def test_read_internal():
5350
img2 = ci.load(DATA_FILE6)
5451
assert_true(isinstance(img2.header, ci.Cifti2Header))
5552
assert_equal(img2.shape, (1, 91282))
5653

54+
5755
@needs_nibabel_data('nitest-cifti2')
5856
def test_read():
5957
img2 = nib.load(DATA_FILE6)
6058
assert_true(isinstance(img2.header, ci.Cifti2Header))
6159
assert_equal(img2.shape, (1, 91282))
6260

61+
6362
@needs_nibabel_data('nitest-cifti2')
6463
def test_version():
6564
for i, dat in enumerate(datafiles):
6665
img = nib.load(dat)
6766
assert_equal(LooseVersion(img.header.version), LooseVersion('2'))
6867

68+
6969
@needs_nibabel_data('nitest-cifti2')
7070
def test_readwritedata():
7171
with InTemporaryDirectory():
@@ -78,8 +78,10 @@ def test_readwritedata():
7878
# Order should be preserved in load/save
7979
for mim1, mim2 in zip(img.header.matrix,
8080
img2.header.matrix):
81-
named_maps1 = [m_ for m_ in mim1 if isinstance(m_, ci.Cifti2NamedMap)]
82-
named_maps2 = [m_ for m_ in mim2 if isinstance(m_, ci.Cifti2NamedMap)]
81+
named_maps1 = [m_ for m_ in mim1
82+
if isinstance(m_, ci.Cifti2NamedMap)]
83+
named_maps2 = [m_ for m_ in mim2
84+
if isinstance(m_, ci.Cifti2NamedMap)]
8385
assert_equal(len(named_maps1), len(named_maps2))
8486
for map1, map2 in zip(named_maps1, named_maps2):
8587
assert_equal(map1.map_name, map2.map_name)
@@ -103,8 +105,10 @@ def test_nibabel_readwritedata():
103105
# Order should be preserved in load/save
104106
for mim1, mim2 in zip(img.header.matrix,
105107
img2.header.matrix):
106-
named_maps1 = [m_ for m_ in mim1 if isinstance(m_, ci.Cifti2NamedMap)]
107-
named_maps2 = [m_ for m_ in mim2 if isinstance(m_, ci.Cifti2NamedMap)]
108+
named_maps1 = [m_ for m_ in mim1
109+
if isinstance(m_, ci.Cifti2NamedMap)]
110+
named_maps2 = [m_ for m_ in mim2
111+
if isinstance(m_, ci.Cifti2NamedMap)]
108112
assert_equal(len(named_maps1), len(named_maps2))
109113
for map1, map2 in zip(named_maps1, named_maps2):
110114
assert_equal(map1.map_name, map2.map_name)
@@ -148,15 +152,17 @@ def test_cifti2types():
148152
counter[ci.Cifti2BrainModel] += 1
149153
if isinstance(map_.vertex_indices, ci.Cifti2VertexIndices):
150154
counter[ci.Cifti2VertexIndices] += 1
151-
if isinstance(map_.voxel_indices_ijk, ci.Cifti2VoxelIndicesIJK):
155+
if isinstance(map_.voxel_indices_ijk,
156+
ci.Cifti2VoxelIndicesIJK):
152157
counter[ci.Cifti2VoxelIndicesIJK] += 1
153158
elif isinstance(map_, ci.Cifti2NamedMap):
154159
counter[ci.Cifti2NamedMap] += 1
155160
assert_true(isinstance(map_.metadata, ci.Cifti2MetaData))
156161
if isinstance(map_.label_table, ci.Cifti2LabelTable):
157162
counter[ci.Cifti2LabelTable] += 1
158163
for label in map_.label_table:
159-
assert_true(isinstance(map_.label_table[label], ci.Cifti2Label))
164+
assert_true(isinstance(map_.label_table[label],
165+
ci.Cifti2Label))
160166
counter[ci.Cifti2Label] += 1
161167
elif isinstance(map_, ci.Cifti2Parcel):
162168
counter[ci.Cifti2Parcel] += 1
@@ -175,11 +181,16 @@ def test_cifti2types():
175181
ci.Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ):
176182
counter[ci.Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ] += 1
177183

178-
assert_equal(list(mim.named_maps), [m_ for m_ in mim if isinstance(m_, ci.Cifti2NamedMap)])
179-
assert_equal(list(mim.surfaces), [m_ for m_ in mim if isinstance(m_, ci.Cifti2Surface)])
180-
assert_equal(list(mim.parcels), [m_ for m_ in mim if isinstance(m_, ci.Cifti2Parcel)])
181-
assert_equal(list(mim.brain_models), [m_ for m_ in mim if isinstance(m_, ci.Cifti2BrainModel)])
182-
assert_equal([mim.volume] if mim.volume else [], [m_ for m_ in mim if isinstance(m_, ci.Cifti2Volume)])
184+
assert_equal(list(mim.named_maps),
185+
[m_ for m_ in mim if isinstance(m_, ci.Cifti2NamedMap)])
186+
assert_equal(list(mim.surfaces),
187+
[m_ for m_ in mim if isinstance(m_, ci.Cifti2Surface)])
188+
assert_equal(list(mim.parcels),
189+
[m_ for m_ in mim if isinstance(m_, ci.Cifti2Parcel)])
190+
assert_equal(list(mim.brain_models),
191+
[m_ for m_ in mim if isinstance(m_, ci.Cifti2BrainModel)])
192+
assert_equal([mim.volume] if mim.volume else [],
193+
[m_ for m_ in mim if isinstance(m_, ci.Cifti2Volume)])
183194

184195
for klass, count in counter.items():
185196
assert_true(count > 0, "No exercise of " + klass.__name__)

0 commit comments

Comments
 (0)