Skip to content

Commit bbf7c34

Browse files
author
Vinit Kumar
committed
tests (json2xml): add test for encoding
Pretty printing didn't have encoding information in it. This test ensures that the latest fix done in #213 has tests to verify the fix and there is no regression in the future.
1 parent 2920d71 commit bbf7c34

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_json2xml.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,19 @@ def test_dict_attr_crash(self):
213213
dict_from_xml = xmltodict.parse(result)
214214
assert dict_from_xml["all"]["product"]["@attr_name"] == "attr_value"
215215
assert dict_from_xml["all"]["product"]["@a"] == "b"
216+
217+
def test_encoding_pretty_print(self) -> None:
218+
data = readfromstring(
219+
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
220+
)
221+
xmldata = json2xml.Json2xml(data, pretty=True).to_xml()
222+
if xmldata:
223+
assert 'encoding="UTF-8"' in xmldata
224+
225+
def test_encoding_without_pretty_print(self) -> None:
226+
data = readfromstring(
227+
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
228+
)
229+
xmldata = json2xml.Json2xml(data, pretty=False).to_xml()
230+
if xmldata:
231+
assert b'encoding="UTF-8"' in xmldata

0 commit comments

Comments
 (0)