From 34bf7964332987984245f74d8c93dc9ab350cbe5 Mon Sep 17 00:00:00 2001 From: Vinit kumar Date: Sat, 22 Feb 2025 00:50:08 +0530 Subject: [PATCH 1/3] fix: add tests for the uncovered lines --- .coverage | Bin 53248 -> 53248 bytes tests/test_dict2xml.py | 98 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/.coverage b/.coverage index 06eb5026daf59b081377921eafe724049945fe2d..2b84bae4c6224f8992c4b00beb45474ee3053a94 100644 GIT binary patch delta 91 zcmV-h0HptbpaX!Q1F!{v5f1(U5BU$K51tP`4;l{)4*s(d5af<-?RCT2S7ULCm{d; delta 79 zcmV-V0I>gnpaX!Q1F!{v5f2Ig5BU$W52_DJ4<-*74+^sp5cCd{{*GP&pp#vX8x6?+ lw%PvUj{y9C001D9g^wWzMFIr@34scet&cweJ+t|b2S7(K9B=>t diff --git a/tests/test_dict2xml.py b/tests/test_dict2xml.py index 7a54ab7..33b02bf 100644 --- a/tests/test_dict2xml.py +++ b/tests/test_dict2xml.py @@ -499,3 +499,101 @@ def test_date_conversion_with_custom_attributes(self): data = {"key": datetime.date(2023, 2, 15)} result = dicttoxml.dicttoxml(data, attr_type=False, custom_root="custom") assert b"2023-02-15" in result + + def test_get_xml_type_unsupported(self): + """Test get_xml_type with unsupported type.""" + class CustomClass: + pass + + # Should return the class name for unsupported types + result = dicttoxml.get_xml_type(CustomClass()) + assert result == "CustomClass" + + def test_make_valid_xml_name_invalid_chars(self): + """Test make_valid_xml_name with invalid XML characters.""" + key = "key" + attr = {} + new_key, new_attr = dicttoxml.make_valid_xml_name(key, attr) + assert new_key == "key" + assert new_attr == {"name": "<invalid>key"} + + def test_dict2xml_str_invalid_type(self): + """Test dict2xml_str with invalid type.""" + class CustomClass: + pass + + item = {"key": CustomClass()} + with pytest.raises(TypeError, match="Unsupported data type:"): + dicttoxml.dict2xml_str( + attr_type=False, + attr={}, + item=item, + item_func=lambda x: "item", + cdata=False, + item_name="test", + item_wrap=False, + parentIsList=False + ) + + def test_convert_dict_invalid_type(self): + """Test convert_dict with invalid type.""" + class CustomClass: + pass + + obj = {"key": CustomClass()} + with pytest.raises(TypeError, match="Unsupported data type:"): + dicttoxml.convert_dict( + obj=obj, + ids=[], + parent="root", + attr_type=False, + item_func=lambda x: "item", + cdata=False, + item_wrap=False + ) + + def test_convert_list_invalid_type(self): + """Test convert_list with invalid type.""" + class CustomClass: + pass + + items = [CustomClass()] + with pytest.raises(TypeError, match="Unsupported data type:"): + dicttoxml.convert_list( + items=items, + ids=None, + parent="root", + attr_type=False, + item_func=lambda x: "item", + cdata=False, + item_wrap=False + ) + + def test_convert_list_with_none(self): + """Test convert_list with None values.""" + items = [None] + result = dicttoxml.convert_list( + items=items, + ids=None, + parent="root", + attr_type=True, + item_func=lambda x: "item", + cdata=False, + item_wrap=True + ) + assert result == '' + + def test_convert_list_with_custom_ids(self): + """Test convert_list with custom IDs.""" + items = ["test"] + result = dicttoxml.convert_list( + items=items, + ids=["custom_id"], + parent="root", + attr_type=False, + item_func=lambda x: "item", + cdata=False, + item_wrap=True + ) + assert 'id="root_' in result + assert '>test<' in result From 0f881f797cc97323d28d954154b020e92ae99f0a Mon Sep 17 00:00:00 2001 From: Vinit kumar Date: Sat, 22 Feb 2025 00:56:25 +0530 Subject: [PATCH 2/3] fix: lint issues with ruff --- 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 33b02bf..c162d83 100644 --- a/tests/test_dict2xml.py +++ b/tests/test_dict2xml.py @@ -504,7 +504,7 @@ def test_get_xml_type_unsupported(self): """Test get_xml_type with unsupported type.""" class CustomClass: pass - + # Should return the class name for unsupported types result = dicttoxml.get_xml_type(CustomClass()) assert result == "CustomClass" From 6d16860cea92567226c0759e72b5894e7adc05bd Mon Sep 17 00:00:00 2001 From: Vinit kumar Date: Sat, 22 Feb 2025 00:59:22 +0530 Subject: [PATCH 3/3] tests: implement code suggestions by sourcery --- .coverage | Bin 53248 -> 53248 bytes tests/test_dict2xml.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/.coverage b/.coverage index 2b84bae4c6224f8992c4b00beb45474ee3053a94..80c2a68fb078d0d4503bedb5f4bd59af098a1e0e 100644 GIT binary patch delta 55 zcmV-70LcG