@@ -444,3 +444,58 @@ def test_datetime_conversion(self):
444444 data = {"key" : datetime .datetime (2023 , 2 , 15 , 12 , 30 , 45 )}
445445 result = dicttoxml .dicttoxml (data , attr_type = False )
446446 assert b"<key>2023-02-15T12:30:45</key>" in result
447+
448+ def test_list_to_xml_with_primitive_items (self ):
449+ data = {"items" : [1 , 2 , 3 ]}
450+ result = dicttoxml .dicttoxml (data , root = False , attr_type = False , item_wrap = True )
451+ assert result == b"<items><item>1</item><item>2</item><item>3</item></items>"
452+
453+ def test_list_to_xml_with_dict_items (self ):
454+ data = {"items" : [{"key1" : "value1" }, {"key2" : "value2" }]}
455+ result = dicttoxml .dicttoxml (data , root = False , attr_type = False , item_wrap = True )
456+ assert result == b"<items><item><key1>value1</key1></item><item><key2>value2</key2></item></items>"
457+
458+ def test_list_to_xml_with_mixed_items (self ):
459+ data = {"items" : [1 , "string" , {"key" : "value" }]}
460+ result = dicttoxml .dicttoxml (data , root = False , attr_type = False , item_wrap = True )
461+ assert result == b"<items><item>1</item><item>string</item><item><key>value</key></item></items>"
462+
463+ def test_list_to_xml_with_empty_list (self ):
464+ data = {"items" : []}
465+ result = dicttoxml .dicttoxml (data , root = False , attr_type = False , item_wrap = True )
466+ assert result == b"<items></items>"
467+
468+ def test_list_to_xml_with_special_characters (self ):
469+ data = {"items" : ["<tag>" , "&" , '"quote"' , "'single quote'" ]}
470+ result = dicttoxml .dicttoxml (data , root = False , attr_type = False , item_wrap = True )
471+ assert result == b"<items><item><tag></item><item>&</item><item>"quote"</item><item>'single quote'</item></items>"
472+
473+ def test_datetime_conversion_with_isoformat (self ):
474+ data = {"key" : datetime .datetime (2023 , 2 , 15 , 12 , 30 , 45 )}
475+ result = dicttoxml .dicttoxml (data , attr_type = False )
476+ assert b"<key>2023-02-15T12:30:45</key>" in result
477+
478+ def test_date_conversion_with_isoformat (self ):
479+ data = {"key" : datetime .date (2023 , 2 , 15 )}
480+ result = dicttoxml .dicttoxml (data , attr_type = False )
481+ assert b"<key>2023-02-15</key>" in result
482+
483+ def test_datetime_conversion_with_attr_type (self ):
484+ data = {"key" : datetime .datetime (2023 , 2 , 15 , 12 , 30 , 45 )}
485+ result = dicttoxml .dicttoxml (data , attr_type = True )
486+ assert b'<key type="str">2023-02-15T12:30:45</key>' in result
487+
488+ def test_date_conversion_with_attr_type (self ):
489+ data = {"key" : datetime .date (2023 , 2 , 15 )}
490+ result = dicttoxml .dicttoxml (data , attr_type = True )
491+ assert b'<key type="str">2023-02-15</key>' in result
492+
493+ def test_datetime_conversion_with_custom_attributes (self ):
494+ data = {"key" : datetime .datetime (2023 , 2 , 15 , 12 , 30 , 45 )}
495+ result = dicttoxml .dicttoxml (data , attr_type = False , custom_root = "custom" )
496+ assert b"<custom><key>2023-02-15T12:30:45</key></custom>" in result
497+
498+ def test_date_conversion_with_custom_attributes (self ):
499+ data = {"key" : datetime .date (2023 , 2 , 15 )}
500+ result = dicttoxml .dicttoxml (data , attr_type = False , custom_root = "custom" )
501+ assert b"<custom><key>2023-02-15</key></custom>" in result
0 commit comments