Skip to content

Commit fecd0f2

Browse files
demianweffigies
authored andcommitted
MetaData can be built from a mapping
1 parent 90f2a4c commit fecd0f2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

nibabel/cifti2/cifti2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ class Cifti2MetaData(xml.XmlSerializable, collections.MutableMapping):
109109
----------
110110
data : list of (name, value) tuples
111111
"""
112-
def __init__(self):
112+
def __init__(self, metadata=None):
113113
self.data = collections.OrderedDict()
114+
if metadata is not None:
115+
self.update(metadata)
114116

115117
def __getitem__(self, key):
116118
return self.data[key]

nibabel/cifti2/tests/test_cifti2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def compare_xml_leaf(str1, str2):
2424

2525

2626
def test_cifti2_metadata():
27+
md = ci.Cifti2MetaData(metadata={'a': 'aval'})
28+
assert_equal(len(md), 1)
29+
assert_equal(list(iter(md)), ['a'])
30+
assert_equal(md['a'], 'aval')
31+
assert_equal(md.data, dict([('a', 'aval')]))
32+
2733
md = ci.Cifti2MetaData()
2834
assert_equal(len(md), 0)
2935
assert_equal(list(iter(md)), [])

0 commit comments

Comments
 (0)