diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index f8c5e08..836a34b 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -40,7 +40,7 @@ jobs:
cache: 'pip'
- run: pip install --upgrade mypy types-requests types-urllib3
- name: mypy
- uses: liskin/gh-problem-matcher-wrap@v1
+ uses: liskin/gh-problem-matcher-wrap@v2
with:
linters: mypy
run: |
diff --git a/json2xml/dicttoxml.py b/json2xml/dicttoxml.py
index cb529c9..2ba6af9 100644
--- a/json2xml/dicttoxml.py
+++ b/json2xml/dicttoxml.py
@@ -10,7 +10,6 @@
from defusedxml.minidom import parseString
# Create a safe random number generator
-safe_random = SystemRandom()
# Set up logging
LOG = logging.getLogger("dicttoxml")
@@ -28,6 +27,7 @@ def make_id(element: str, start: int = 100000, end: int = 999999) -> str:
Returns:
str: The generated ID.
"""
+ safe_random = SystemRandom()
return f"{element}_{safe_random.randint(start, end)}"
diff --git a/tests/test_dict2xml.py b/tests/test_dict2xml.py
index 07731a5..7a54ab7 100644
--- a/tests/test_dict2xml.py
+++ b/tests/test_dict2xml.py
@@ -444,3 +444,58 @@ def test_datetime_conversion(self):
data = {"key": datetime.datetime(2023, 2, 15, 12, 30, 45)}
result = dicttoxml.dicttoxml(data, attr_type=False)
assert b"2023-02-15T12:30:45" in result
+
+ def test_list_to_xml_with_primitive_items(self):
+ data = {"items": [1, 2, 3]}
+ result = dicttoxml.dicttoxml(data, root=False, attr_type=False, item_wrap=True)
+ assert result == b"- 1
- 2
- 3
"
+
+ def test_list_to_xml_with_dict_items(self):
+ data = {"items": [{"key1": "value1"}, {"key2": "value2"}]}
+ result = dicttoxml.dicttoxml(data, root=False, attr_type=False, item_wrap=True)
+ assert result == b"- value1
- value2
"
+
+ def test_list_to_xml_with_mixed_items(self):
+ data = {"items": [1, "string", {"key": "value"}]}
+ result = dicttoxml.dicttoxml(data, root=False, attr_type=False, item_wrap=True)
+ assert result == b"- 1
- string
- value
"
+
+ def test_list_to_xml_with_empty_list(self):
+ data = {"items": []}
+ result = dicttoxml.dicttoxml(data, root=False, attr_type=False, item_wrap=True)
+ assert result == b""
+
+ def test_list_to_xml_with_special_characters(self):
+ data = {"items": ["", "&", '"quote"', "'single quote'"]}
+ result = dicttoxml.dicttoxml(data, root=False, attr_type=False, item_wrap=True)
+ assert result == b"- <tag>
- &
- "quote"
- 'single quote'
"
+
+ def test_datetime_conversion_with_isoformat(self):
+ data = {"key": datetime.datetime(2023, 2, 15, 12, 30, 45)}
+ result = dicttoxml.dicttoxml(data, attr_type=False)
+ assert b"2023-02-15T12:30:45" in result
+
+ def test_date_conversion_with_isoformat(self):
+ data = {"key": datetime.date(2023, 2, 15)}
+ result = dicttoxml.dicttoxml(data, attr_type=False)
+ assert b"2023-02-15" in result
+
+ def test_datetime_conversion_with_attr_type(self):
+ data = {"key": datetime.datetime(2023, 2, 15, 12, 30, 45)}
+ result = dicttoxml.dicttoxml(data, attr_type=True)
+ assert b'2023-02-15T12:30:45' in result
+
+ def test_date_conversion_with_attr_type(self):
+ data = {"key": datetime.date(2023, 2, 15)}
+ result = dicttoxml.dicttoxml(data, attr_type=True)
+ assert b'2023-02-15' in result
+
+ def test_datetime_conversion_with_custom_attributes(self):
+ data = {"key": datetime.datetime(2023, 2, 15, 12, 30, 45)}
+ result = dicttoxml.dicttoxml(data, attr_type=False, custom_root="custom")
+ assert b"2023-02-15T12:30:45" in result
+
+ 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