Skip to content

Commit 1effc55

Browse files
author
Ben Cipollini
committed
TST: Add LabelTable test, test cleanup
1 parent a3b3f41 commit 1effc55

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

nibabel/gifti/tests/test_gifti.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ...nifti1 import data_type_codes, intent_codes
77

8-
from ..gifti import GiftiImage, GiftiDataArray
8+
from ..gifti import GiftiImage, GiftiDataArray, GiftiLabelTable
99

1010
from numpy.testing import (assert_array_almost_equal,
1111
assert_array_equal)
@@ -36,3 +36,14 @@ def test_dataarray():
3636
bs_arr = arr.byteswap().newbyteorder()
3737
da = GiftiDataArray.from_array(bs_arr, 'triangle')
3838
assert_equal(da.datatype, data_type_codes[arr.dtype])
39+
40+
41+
def test_labeltable():
42+
img = GiftiImage()
43+
assert_equal(len(img.labeltable.labels), 0)
44+
45+
new_table = GiftiLabelTable()
46+
new_table.labels += ['test', 'me']
47+
img.labeltable = new_table
48+
assert_equal(len(img.labeltable.labels), 2)
49+

nibabel/gifti/tests/test_giftiio.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,17 @@ def test_read_ordering():
109109
assert_equal(img.darrays[0].data.shape, (3,3))
110110

111111

112-
def test_metadata():
112+
def test_load_metadata():
113113
for i, dat in enumerate(datafiles):
114114
img = gi.read(dat)
115115
me = img.meta
116116
assert_equal(numda[i], img.numDA)
117117
assert_equal(img.version,'1.0')
118118

119119

120-
def test_dataarray1():
120+
def test_load_dataarray1():
121121
img1 = gi.read(DATA_FILE1)
122+
122123
# Round trip
123124
with InTemporaryDirectory():
124125
gi.write(img1, 'test.gii')
@@ -135,8 +136,9 @@ def test_dataarray1():
135136
assert_equal(xform_codes.niistring[img.darrays[0].coordsys.xformspace],'NIFTI_XFORM_TALAIRACH')
136137

137138

138-
def test_dataarray2():
139+
def test_load_dataarray2():
139140
img2 = gi.read(DATA_FILE2)
141+
140142
# Round trip
141143
with InTemporaryDirectory():
142144
gi.write(img2, 'test.gii')
@@ -145,17 +147,19 @@ def test_dataarray2():
145147
assert_array_almost_equal(img.darrays[0].data[:10], DATA_FILE2_darr1)
146148

147149

148-
def test_dataarray3():
150+
def test_load_dataarray3():
149151
img3 = gi.read(DATA_FILE3)
152+
150153
with InTemporaryDirectory():
151154
gi.write(img3, 'test.gii')
152155
bimg = gi.read('test.gii')
153156
for img in (img3, bimg):
154157
assert_array_almost_equal(img.darrays[0].data[30:50], DATA_FILE3_darr1)
155158

156159

157-
def test_dataarray4():
160+
def test_load_dataarray4():
158161
img4 = gi.read(DATA_FILE4)
162+
159163
# Round trip
160164
with InTemporaryDirectory():
161165
gi.write(img4, 'test.gii')
@@ -166,6 +170,7 @@ def test_dataarray4():
166170

167171
def test_dataarray5():
168172
img5 = gi.read(DATA_FILE5)
173+
169174
for da in img5.darrays:
170175
assert_equal(gifti_endian_codes.byteorder[da.endian], 'little')
171176
assert_array_almost_equal(img5.darrays[0].data, DATA_FILE5_darr1)
@@ -212,7 +217,7 @@ def test_readwritedata():
212217
img2.darrays[0].data)
213218

214219

215-
def test_newmetadata():
220+
def test_write_newmetadata():
216221
img = gi.GiftiImage()
217222
attr = gi.GiftiNVPairs(name = 'mykey', value = 'val1')
218223
newmeta = gi.GiftiMetaData(attr)
@@ -226,7 +231,7 @@ def test_newmetadata():
226231
assert_false('mykey' in myme)
227232

228233

229-
def test_getbyintent():
234+
def test_load_getbyintent():
230235
img = gi.read(DATA_FILE1)
231236

232237
da = img.get_arrays_from_intent("NIFTI_INTENT_POINTSET")
@@ -247,8 +252,9 @@ def test_getbyintent():
247252
assert_equal(da, [])
248253

249254

250-
def test_labeltable():
255+
def test_load_labeltable():
251256
img6 = gi.read(DATA_FILE6)
257+
252258
# Round trip
253259
with InTemporaryDirectory():
254260
gi.write(img6, 'test.gii')

0 commit comments

Comments
 (0)