Skip to content

Commit

Permalink
tests (json2xml): add test for encoding
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vinit Kumar committed Aug 31, 2024
1 parent 2920d71 commit bbf7c34
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_json2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,19 @@ def test_dict_attr_crash(self):
dict_from_xml = xmltodict.parse(result)
assert dict_from_xml["all"]["product"]["@attr_name"] == "attr_value"
assert dict_from_xml["all"]["product"]["@a"] == "b"

def test_encoding_pretty_print(self) -> None:
data = readfromstring(
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
)
xmldata = json2xml.Json2xml(data, pretty=True).to_xml()
if xmldata:
assert 'encoding="UTF-8"' in xmldata

def test_encoding_without_pretty_print(self) -> None:
data = readfromstring(
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
)
xmldata = json2xml.Json2xml(data, pretty=False).to_xml()
if xmldata:
assert b'encoding="UTF-8"' in xmldata

0 comments on commit bbf7c34

Please sign in to comment.