Skip to content

Commit b303485

Browse files
DirkRichterVinit Kumar
andauthored
fix #138 and #151 + 2 new unit tests (#154)
* fix #138 and #151: pass correct list_headers arguments + 2 new unit tests * added whitespaces for flake8 Co-authored-by: Vinit Kumar <[email protected]>
1 parent 92bccda commit b303485

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

json2xml/dicttoxml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def dict2xml_str(
253253
else:
254254
# we can not use convert_dict, because rawitem could be non-dict
255255
subtree = convert(
256-
rawitem, ids, attr_type, item_func, cdata, item_wrap, item_name, list_headers=True
256+
rawitem, ids, attr_type, item_func, cdata, item_wrap, item_name, list_headers=list_headers
257257
)
258258
if parentIsList and list_headers:
259259
return f"<{parent}>{subtree}</{parent}>"
@@ -365,7 +365,7 @@ def convert_dict(
365365
dict2xml_str(
366366
attr_type, attr, val, item_func, cdata, key, item_wrap,
367367
False,
368-
list_headers=True
368+
list_headers=list_headers
369369
)
370370
)
371371

tests/test_dict2xml.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,15 @@ def test_dict2xml_with_item_func(self):
211211
assert b'<?xml version="1.0" encoding="UTF-8" ?>' \
212212
b'<root><a>1</a><a>2</a><a>3</a><non_flat_list><a>4</a><a>5</a><a>6</a></non_flat_list>' \
213213
b'</root>' == result
214+
215+
def test_dict2xml_with_item_func_issue_151(self):
216+
data = [{'x': [1]}]
217+
result = dicttoxml.dicttoxml(data, root=False, attr_type=False, item_func=lambda y: y+'item')
218+
print(result)
219+
assert b'<item><x><xitem>1</xitem></x></item>' == result
220+
221+
def test_dict2xml_issue_151(self):
222+
data = [{'x': [1]}]
223+
result = dicttoxml.dicttoxml(data, root=False, attr_type=False)
224+
print(result)
225+
assert b'<item><x><item>1</item></x></item>' == result

0 commit comments

Comments
 (0)