@@ -499,3 +499,118 @@ def test_date_conversion_with_custom_attributes(self):
499499 data = {"key" : datetime .date (2023 , 2 , 15 )}
500500 result = dicttoxml .dicttoxml (data , attr_type = False , custom_root = "custom" )
501501 assert b"<custom><key>2023-02-15</key></custom>" in result
502+
503+ def test_get_xml_type_unsupported (self ):
504+ """Test get_xml_type with unsupported type."""
505+ class CustomClass :
506+ pass
507+
508+ # Should return the class name for unsupported types
509+ result = dicttoxml .get_xml_type (CustomClass ())
510+ assert result == "CustomClass"
511+
512+ def test_make_valid_xml_name_invalid_chars (self ):
513+ """Test make_valid_xml_name with invalid XML characters."""
514+ key = "<invalid>key"
515+ attr = {}
516+ new_key , new_attr = dicttoxml .make_valid_xml_name (key , attr )
517+ assert new_key == "key"
518+ assert new_attr == {"name" : "<invalid>key" }
519+
520+ def test_dict2xml_str_invalid_type (self ):
521+ """Test dict2xml_str with invalid type."""
522+ class CustomClass :
523+ pass
524+
525+ item = {"key" : CustomClass ()}
526+ with pytest .raises (TypeError , match = "Unsupported data type:" ):
527+ dicttoxml .dict2xml_str (
528+ attr_type = False ,
529+ attr = {},
530+ item = item ,
531+ item_func = lambda x : "item" ,
532+ cdata = False ,
533+ item_name = "test" ,
534+ item_wrap = False ,
535+ parentIsList = False
536+ )
537+
538+ def test_convert_dict_invalid_type (self ):
539+ """Test convert_dict with invalid type."""
540+ class CustomClass :
541+ pass
542+
543+ obj = {"key" : CustomClass ()}
544+ with pytest .raises (TypeError , match = "Unsupported data type:" ):
545+ dicttoxml .convert_dict (
546+ obj = obj ,
547+ ids = [],
548+ parent = "root" ,
549+ attr_type = False ,
550+ item_func = lambda x : "item" ,
551+ cdata = False ,
552+ item_wrap = False
553+ )
554+
555+ def test_convert_list_invalid_type (self ):
556+ """Test convert_list with invalid type."""
557+ class CustomClass :
558+ pass
559+
560+ items = [CustomClass ()]
561+ with pytest .raises (TypeError , match = "Unsupported data type:" ):
562+ dicttoxml .convert_list (
563+ items = items ,
564+ ids = None ,
565+ parent = "root" ,
566+ attr_type = False ,
567+ item_func = lambda x : "item" ,
568+ cdata = False ,
569+ item_wrap = False
570+ )
571+
572+ def test_convert_list_with_none (self ):
573+ """Test convert_list with None values."""
574+ items = [None ]
575+ result = dicttoxml .convert_list (
576+ items = items ,
577+ ids = None ,
578+ parent = "root" ,
579+ attr_type = True ,
580+ item_func = lambda x : "item" ,
581+ cdata = False ,
582+ item_wrap = True
583+ )
584+ assert result == '<item type="null"></item>'
585+
586+ def test_convert_list_with_custom_ids (self ):
587+ """Test convert_list with custom IDs."""
588+ items = ["test" ]
589+ result = dicttoxml .convert_list (
590+ items = items ,
591+ ids = ["custom_id" ],
592+ parent = "root" ,
593+ attr_type = False ,
594+ item_func = lambda x : "item" ,
595+ cdata = False ,
596+ item_wrap = True
597+ )
598+ assert 'id="root_' in result
599+ assert '>test<' in result
600+
601+ def test_convert_list_mixed_types (self ):
602+ """Test convert_list with a mix of valid and invalid types."""
603+ class CustomClass :
604+ pass
605+
606+ items = ["valid string" , 100 , {"a" : "b" }, CustomClass ()]
607+ with pytest .raises (TypeError , match = "Unsupported data type:" ):
608+ dicttoxml .convert_list (
609+ items = items ,
610+ ids = None ,
611+ parent = "root" ,
612+ attr_type = False ,
613+ item_func = lambda x : "item" ,
614+ cdata = False ,
615+ item_wrap = False
616+ )
0 commit comments