@@ -228,15 +228,16 @@ def test_labeltable():
228228def test_metadata ():
229229 md = GiftiMetaData (key = 'value' )
230230 # Old initialization methods
231- nvpair = GiftiNVPairs ('key' , 'value' )
231+ with pytest .warns (DeprecationWarning ) as w :
232+ nvpair = GiftiNVPairs ('key' , 'value' )
232233 with pytest .warns (FutureWarning ) as w :
233234 md2 = GiftiMetaData (nvpair = nvpair )
234235 assert len (w ) == 1
235236 with pytest .warns (DeprecationWarning ) as w :
236237 md3 = GiftiMetaData .from_dict ({'key' : 'value' })
237238 assert md == md2 == md3 == {'key' : 'value' }
238239 # .data as a list of NVPairs is going away
239- with pytest .warns (FutureWarning ) as w :
240+ with pytest .warns (DeprecationWarning ) as w :
240241 assert md .data [0 ].name == 'key'
241242 assert md .data [0 ].value == 'value'
242243 assert len (w ) == 2
@@ -245,6 +246,85 @@ def test_metadata():
245246 md .get_metadata ()
246247
247248
249+ def test_metadata_list_interface ():
250+ md = GiftiMetaData (key = 'value' )
251+ with pytest .warns (DeprecationWarning ):
252+ mdlist = md .data
253+ assert len (mdlist ) == 1
254+ assert mdlist [0 ].name == 'key'
255+ assert mdlist [0 ].value == 'value'
256+
257+ # Modify elements in-place
258+ mdlist [0 ].name = 'foo'
259+ assert mdlist [0 ].name == 'foo'
260+ assert 'foo' in md
261+ assert 'key' not in md
262+ assert md ['foo' ] == 'value'
263+ mdlist [0 ].value = 'bar'
264+ assert mdlist [0 ].value == 'bar'
265+ assert md ['foo' ] == 'bar'
266+
267+ # Append new NVPair
268+ with pytest .warns (DeprecationWarning ) as w :
269+ nvpair = GiftiNVPairs ('key' , 'value' )
270+ mdlist .append (nvpair )
271+ assert len (mdlist ) == 2
272+ assert mdlist [1 ].name == 'key'
273+ assert mdlist [1 ].value == 'value'
274+ assert len (md ) == 2
275+ assert md == {'foo' : 'bar' , 'key' : 'value' }
276+
277+ # Clearing empties both
278+ mdlist .clear ()
279+ assert len (mdlist ) == 0
280+ assert len (md ) == 0
281+
282+ # Extension adds multiple keys
283+ with pytest .warns (DeprecationWarning ) as w :
284+ foobar = GiftiNVPairs ('foo' , 'bar' )
285+ mdlist .extend ([nvpair , foobar ])
286+ assert len (mdlist ) == 2
287+ assert len (md ) == 2
288+ assert md == {'key' : 'value' , 'foo' : 'bar' }
289+
290+ # Insertion updates list order, though we don't attempt to preserve it in the dict
291+ with pytest .warns (DeprecationWarning ) as w :
292+ lastone = GiftiNVPairs ('last' , 'one' )
293+ mdlist .insert (1 , lastone )
294+ assert len (mdlist ) == 3
295+ assert len (md ) == 3
296+ assert mdlist [1 ].name == 'last'
297+ assert mdlist [1 ].value == 'one'
298+ assert md == {'key' : 'value' , 'foo' : 'bar' , 'last' : 'one' }
299+
300+ # Popping returns a pair
301+ mypair = mdlist .pop (0 )
302+ assert isinstance (mypair , GiftiNVPairs )
303+ assert mypair .name == 'key'
304+ assert mypair .value == 'value'
305+ assert len (mdlist ) == 2
306+ assert len (md ) == 2
307+ assert 'key' not in md
308+ assert md == {'foo' : 'bar' , 'last' : 'one' }
309+ # Modifying the pair now does not affect md
310+ mypair .name = 'completelynew'
311+ mypair .value = 'strings'
312+ assert 'completelynew' not in md
313+ assert md == {'foo' : 'bar' , 'last' : 'one' }
314+ # Check popping from the end (lastone inserted before foobar)
315+ lastpair = mdlist .pop ()
316+ assert len (mdlist ) == 1
317+ assert len (md ) == 1
318+ assert md == {'last' : 'one' }
319+
320+ # And let's remove an old pair with a new object
321+ with pytest .warns (DeprecationWarning ) as w :
322+ lastoneagain = GiftiNVPairs ('last' , 'one' )
323+ mdlist .remove (lastoneagain )
324+ assert len (mdlist ) == 0
325+ assert len (md ) == 0
326+
327+
248328def test_gifti_label_rgba ():
249329 rgba = np .random .rand (4 )
250330 kwargs = dict (zip (['red' , 'green' , 'blue' , 'alpha' ], rgba ))
0 commit comments