26
26
from numpy .testing import assert_array_almost_equal
27
27
28
28
import pytest
29
- from ...testing import clear_and_catch_warnings
29
+ from ...testing import clear_and_catch_warnings , suppress_warnings
30
30
31
31
32
32
IO_DATA_PATH = pjoin (dirname (__file__ ), 'data' )
126
126
def assert_default_types (loaded ):
127
127
default = loaded .__class__ ()
128
128
for attr in dir (default ):
129
- defaulttype = type (getattr (default , attr ))
129
+ with suppress_warnings ():
130
+ defaulttype = type (getattr (default , attr ))
130
131
# Optional elements may have default of None
131
132
if defaulttype is type (None ):
132
133
continue
133
- loadedtype = type (getattr (loaded , attr ))
134
+ with suppress_warnings ():
135
+ loadedtype = type (getattr (loaded , attr ))
134
136
assert loadedtype == defaulttype , (
135
137
f"Type mismatch for attribute: { attr } ({ loadedtype } != { defaulttype } )" )
136
138
@@ -143,9 +145,10 @@ def test_default_types():
143
145
assert_default_types (img )
144
146
# GiftiMetaData
145
147
assert_default_types (img .meta )
146
- # GiftiNVPairs
147
- for nvpair in img .meta .data :
148
- assert_default_types (nvpair )
148
+ # GiftiNVPairs - Remove in NIB6
149
+ with pytest .warns (FutureWarning ):
150
+ for nvpair in img .meta .data :
151
+ assert_default_types (nvpair )
149
152
# GiftiLabelTable
150
153
assert_default_types (img .labeltable )
151
154
# GiftiLabel elements can be None or float; skip
@@ -156,9 +159,10 @@ def test_default_types():
156
159
assert_default_types (darray .coordsys )
157
160
# GiftiMetaData
158
161
assert_default_types (darray .meta )
159
- # GiftiNVPairs
160
- for nvpair in darray .meta .data :
161
- assert_default_types (nvpair )
162
+ # GiftiNVPairs - Remove in NIB6
163
+ with pytest .warns (FutureWarning ):
164
+ for nvpair in darray .meta .data :
165
+ assert_default_types (nvpair )
162
166
163
167
164
168
def test_read_ordering ():
@@ -204,7 +208,7 @@ def test_load_dataarray1():
204
208
for img in (img1 , bimg ):
205
209
assert_array_almost_equal (img .darrays [0 ].data , DATA_FILE1_darr1 )
206
210
assert_array_almost_equal (img .darrays [1 ].data , DATA_FILE1_darr2 )
207
- me = img .darrays [0 ].meta . metadata
211
+ me = img .darrays [0 ].meta
208
212
assert 'AnatomicalStructurePrimary' in me
209
213
assert 'AnatomicalStructureSecondary' in me
210
214
me ['AnatomicalStructurePrimary' ] == 'CortexLeft'
@@ -301,14 +305,13 @@ def test_modify_darray():
301
305
302
306
def test_write_newmetadata ():
303
307
img = gi .GiftiImage ()
304
- attr = gi .GiftiNVPairs (name = 'mykey' , value = 'val1' )
305
- newmeta = gi .GiftiMetaData (attr )
308
+ newmeta = gi .GiftiMetaData (mykey = 'val1' )
306
309
img .meta = newmeta
307
- myme = img .meta . metadata
310
+ myme = img .meta
308
311
assert 'mykey' in myme
309
- newmeta = gi .GiftiMetaData . from_dict ({'mykey1' : 'val2' })
312
+ newmeta = gi .GiftiMetaData ({'mykey1' : 'val2' })
310
313
img .meta = newmeta
311
- myme = img .meta . metadata
314
+ myme = img .meta
312
315
assert 'mykey1' in myme
313
316
assert 'mykey' not in myme
314
317
0 commit comments