Skip to content

Commit b67e904

Browse files
committed
[#151] Replace to_dict function with xmltodict's dict_constructor
1 parent 0d4013b commit b67e904

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

flattentool/tests/test_roundtrip.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,6 @@ def test_roundtrip_360_rollup(tmpdir, use_titles):
9696
assert original_json == roundtripped_json
9797

9898

99-
def to_dict(x):
100-
''' Converts a nested dictlike objects e.g. OrderedDict's, to a dicts. '''
101-
if hasattr(x, 'items'):
102-
return dict((k, to_dict(v)) for k,v in x.items())
103-
elif isinstance(x, list):
104-
return [to_dict(y) for y in x]
105-
else:
106-
return x
107-
108-
10999
@pytest.mark.parametrize('output_format', ['xlsx', 'csv'])
110100
def test_roundtrip_xml(tmpdir, output_format):
111101
input_name = 'examples/iati/expected.xml'
@@ -126,5 +116,8 @@ def test_roundtrip_xml(tmpdir, output_format):
126116
original_xml = open(input_name, 'rb')
127117
roundtripped_xml = tmpdir.join('roundtrip.xml').open('rb')
128118

129-
# Compare without ordering, by wrapping in to_dict
130-
assert to_dict(xmltodict.parse(original_xml)) == to_dict(xmltodict.parse(roundtripped_xml))
119+
# Compare without ordering, by using dict_constructor=dict instead of
120+
# OrderedDict
121+
original = xmltodict.parse(original_xml, dict_constructor=dict)
122+
roundtripped = xmltodict.parse(roundtripped_xml, dict_constructor=dict)
123+
assert original == roundtripped

0 commit comments

Comments
 (0)