From 0bf7bd0961c811c58c3e260a5e874686b6a3f208 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Mon, 16 Sep 2024 16:49:04 +0530 Subject: [PATCH 1/2] feat: add some new tests --- tests/test_dict2xml.py | 52 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/test_dict2xml.py b/tests/test_dict2xml.py index cd3bd264..b46a6b7e 100644 --- a/tests/test_dict2xml.py +++ b/tests/test_dict2xml.py @@ -390,6 +390,52 @@ def test_valid_key(self): xml = dicttoxml.convert_bool('valid_key', False, False) assert xml == 'false' - def test_invalid_key(self): - xml = dicttoxml.convert_bool('invalid', True, False) - assert xml == 'true' + def test_convert_kv_with_cdata(self): + result = dicttoxml.convert_kv("key", "value", attr_type=False, cdata=True) + assert result == "" + + def test_convert_kv_with_attr_type(self): + result = dicttoxml.convert_kv("key", 123, attr_type=True) + assert result == '123' + + def test_make_valid_xml_name_with_invalid_key(self): + key, attr = dicttoxml.make_valid_xml_name("invalid key", {}) + assert key == "invalid_key" + assert attr == {} + + def test_convert_bool_with_attr_type(self): + result = dicttoxml.convert_bool("key", True, attr_type=True) + assert result == 'true' + + def test_convert_none_with_attr_type(self): + result = dicttoxml.convert_none("key", attr_type=True) + assert result == '' + + + def test_make_valid_xml_name_with_numeric_key(self): + key, attr = dicttoxml.make_valid_xml_name("123", {}) + assert key == "n123" + assert attr == {} + + def test_escape_xml_with_special_chars(self): + result = dicttoxml.escape_xml('This & that < those > these "quotes" \'single quotes\'') + assert result == "This & that < those > these "quotes" 'single quotes'" + + def test_get_xml_type_with_sequence(self): + result = dicttoxml.get_xml_type(["item1", "item2"]) + assert result == "list" + + def test_get_xml_type_with_none(self): + result = dicttoxml.get_xml_type(None) + assert result == "null" + + def dicttoxml_with_custom_root(self): + data = {"key": "value"} + result = dicttoxml.dicttoxml(data, custom_root="custom") + assert b"value" in result + + def test_dicttoxml_with_xml_namespaces(self): + data = {"key": "value"} + namespaces = {"xmlns": "http://example.com"} + result = dicttoxml.dicttoxml(data, xml_namespaces=namespaces) + assert b'xmlns="http://example.com"' in result \ No newline at end of file From 17f4b081a53f1ee436a1dee5fed1eef3a33662c4 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Mon, 16 Sep 2024 16:53:37 +0530 Subject: [PATCH 2/2] fix: ruff lint issue --- tests/test_dict2xml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_dict2xml.py b/tests/test_dict2xml.py index b46a6b7e..c2c68a66 100644 --- a/tests/test_dict2xml.py +++ b/tests/test_dict2xml.py @@ -438,4 +438,4 @@ def test_dicttoxml_with_xml_namespaces(self): data = {"key": "value"} namespaces = {"xmlns": "http://example.com"} result = dicttoxml.dicttoxml(data, xml_namespaces=namespaces) - assert b'xmlns="http://example.com"' in result \ No newline at end of file + assert b'xmlns="http://example.com"' in result