@@ -96,16 +96,6 @@ def test_roundtrip_360_rollup(tmpdir, use_titles):
96
96
assert original_json == roundtripped_json
97
97
98
98
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
-
109
99
@pytest .mark .parametrize ('output_format' , ['xlsx' , 'csv' ])
110
100
def test_roundtrip_xml (tmpdir , output_format ):
111
101
input_name = 'examples/iati/expected.xml'
@@ -126,5 +116,8 @@ def test_roundtrip_xml(tmpdir, output_format):
126
116
original_xml = open (input_name , 'rb' )
127
117
roundtripped_xml = tmpdir .join ('roundtrip.xml' ).open ('rb' )
128
118
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