Skip to content

Commit fdec48b

Browse files
committed
TEST: Test default types for parsed Gifti files
1 parent 32271df commit fdec48b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

nibabel/gifti/tests/test_parse_gifti_fast.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,44 @@
9999
DATA_FILE6_darr1 = np.array([9182740, 9182740, 9182740], dtype=np.float32)
100100

101101

102+
def assert_default_types(loaded):
103+
default = loaded.__class__()
104+
for attr in dir(default):
105+
defaulttype = type(getattr(default, attr))
106+
# Optional elements may have default of None
107+
if defaulttype is type(None):
108+
continue
109+
loadedtype = type(getattr(loaded, attr))
110+
assert loadedtype == defaulttype, \
111+
"Type mismatch for attribute: {} ({!s} != {!s})".format(
112+
attr, loadedtype, defaulttype)
113+
114+
115+
def test_default_types():
116+
for fname in datafiles:
117+
img = load(fname)
118+
# GiftiImage
119+
assert_default_types(img)
120+
# GiftiMetaData
121+
assert_default_types(img.meta)
122+
# GiftiNVPairs
123+
for nvpair in img.meta.data:
124+
assert_default_types(nvpair)
125+
# GiftiLabelTable
126+
assert_default_types(img.labeltable)
127+
# GiftiLabel elements can be None or float; skip
128+
# GiftiDataArray
129+
for darray in img.darrays:
130+
assert_default_types(darray)
131+
# GiftiCoordSystem
132+
assert_default_types(darray.coordsys)
133+
# GiftiMetaData
134+
assert_default_types(darray.meta)
135+
# GiftiNVPairs
136+
for nvpair in darray.meta.data:
137+
assert_default_types(nvpair)
138+
139+
102140
def test_read_ordering():
103141
# DATA_FILE1 has an expected darray[0].data shape of (3,3). However if we
104142
# read another image first (DATA_FILE2) then the shape is wrong

0 commit comments

Comments
 (0)