Skip to content

Commit 5788e07

Browse files
committed
Ensure the arguments to the entrypoint are used correctly
Prior to this, arguments for build were passed into Converter instead of into build Fixes #26
1 parent e7823cf commit 5788e07

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ Limitations
137137
Changelog
138138
---------
139139

140+
1.7.6 - TBD
141+
* Fixed the ``dict2xml.dict2xml`` entry point to distribute options
142+
correctly
143+
140144
1.7.5 - 13 February 2024
141145
* Introduced the ``data_sorter`` option
142146

dict2xml/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
from .version import VERSION
44

55

6-
def dict2xml(data, *args, **kwargs):
6+
def dict2xml(
7+
data,
8+
wrap=None,
9+
indent=" ",
10+
newlines=True,
11+
iterables_repeat_wrap=True,
12+
closed_tags_for=None,
13+
data_sorter=None,
14+
):
715
"""Return an XML string of a Python dict object."""
8-
return Converter(*args, **kwargs).build(data)
16+
return Converter(wrap=wrap, indent=indent, newlines=newlines).build(
17+
data,
18+
iterables_repeat_wrap=iterables_repeat_wrap,
19+
closed_tags_for=closed_tags_for,
20+
data_sorter=data_sorter,
21+
)
922

1023

1124
__all__ = ["dict2xml", "Converter", "Node", "VERSION", "DataSorter"]

tests/build_test.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pytest
99

10-
from dict2xml import Converter, dict2xml
10+
from dict2xml import Converter, DataSorter, dict2xml
1111

1212
examples = os.path.join(os.path.dirname(__file__), "examples")
1313

@@ -22,12 +22,26 @@
2222
converter.build.return_value = serialized
2323

2424
FakeConverter = mock.Mock(name="Converter", return_value=converter)
25+
data_sorter = DataSorter.never()
2526

2627
with mock.patch("dict2xml.Converter", FakeConverter):
27-
assert dict2xml(data, 1, 2, 3, a=5, b=8) is serialized
28-
29-
FakeConverter.assert_called_once_with(1, 2, 3, a=5, b=8)
30-
converter.build.assert_called_once_with(data)
28+
assert (
29+
dict2xml(
30+
data,
31+
wrap="wrap",
32+
indent="indent",
33+
newlines=False,
34+
iterables_repeat_wrap=False,
35+
closed_tags_for=["one"],
36+
data_sorter=data_sorter,
37+
)
38+
is serialized
39+
)
40+
41+
FakeConverter.assert_called_once_with(wrap="wrap", indent="indent", newlines=False)
42+
converter.build.assert_called_once_with(
43+
data, iterables_repeat_wrap=False, closed_tags_for=["one"], data_sorter=data_sorter
44+
)
3145

3246
describe "Just Working":
3347

0 commit comments

Comments
 (0)