Skip to content

Commit 3bbb322

Browse files
authored
feat: add some new tests (#216)
* feat: add some new tests * fix: ruff lint issue
1 parent f01cccf commit 3bbb322

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

tests/test_dict2xml.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,52 @@ def test_valid_key(self):
390390
xml = dicttoxml.convert_bool('valid_key', False, False)
391391
assert xml == '<valid_key type="bool">false</valid_key>'
392392

393-
def test_invalid_key(self):
394-
xml = dicttoxml.convert_bool('invalid<key>', True, False)
395-
assert xml == '<key type="bool" name="invalid&lt;key&gt;">true</key>'
393+
def test_convert_kv_with_cdata(self):
394+
result = dicttoxml.convert_kv("key", "value", attr_type=False, cdata=True)
395+
assert result == "<key><![CDATA[value]]></key>"
396+
397+
def test_convert_kv_with_attr_type(self):
398+
result = dicttoxml.convert_kv("key", 123, attr_type=True)
399+
assert result == '<key type="int">123</key>'
400+
401+
def test_make_valid_xml_name_with_invalid_key(self):
402+
key, attr = dicttoxml.make_valid_xml_name("invalid key", {})
403+
assert key == "invalid_key"
404+
assert attr == {}
405+
406+
def test_convert_bool_with_attr_type(self):
407+
result = dicttoxml.convert_bool("key", True, attr_type=True)
408+
assert result == '<key type="bool">true</key>'
409+
410+
def test_convert_none_with_attr_type(self):
411+
result = dicttoxml.convert_none("key", attr_type=True)
412+
assert result == '<key type="null"></key>'
413+
414+
415+
def test_make_valid_xml_name_with_numeric_key(self):
416+
key, attr = dicttoxml.make_valid_xml_name("123", {})
417+
assert key == "n123"
418+
assert attr == {}
419+
420+
def test_escape_xml_with_special_chars(self):
421+
result = dicttoxml.escape_xml('This & that < those > these "quotes" \'single quotes\'')
422+
assert result == "This &amp; that &lt; those &gt; these &quot;quotes&quot; &apos;single quotes&apos;"
423+
424+
def test_get_xml_type_with_sequence(self):
425+
result = dicttoxml.get_xml_type(["item1", "item2"])
426+
assert result == "list"
427+
428+
def test_get_xml_type_with_none(self):
429+
result = dicttoxml.get_xml_type(None)
430+
assert result == "null"
431+
432+
def dicttoxml_with_custom_root(self):
433+
data = {"key": "value"}
434+
result = dicttoxml.dicttoxml(data, custom_root="custom")
435+
assert b"<custom><key>value</key></custom>" in result
436+
437+
def test_dicttoxml_with_xml_namespaces(self):
438+
data = {"key": "value"}
439+
namespaces = {"xmlns": "http://example.com"}
440+
result = dicttoxml.dicttoxml(data, xml_namespaces=namespaces)
441+
assert b'xmlns="http://example.com"' in result

0 commit comments

Comments
 (0)