Skip to content

Commit 3aabf92

Browse files
committed
Add tests for homogeneous tuple.
1 parent c12b065 commit 3aabf92

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

tests/test_homogeneous_collections.py

+43-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class RootModel(BaseXmlModel, tag="model"):
131131

132132
actual_obj = RootModel.from_xml(xml)
133133
expected_obj = RootModel(
134-
values = [1, 2, 70, -34]
134+
values=[1, 2, 70, -34]
135135
)
136136

137137
assert actual_obj == expected_obj
@@ -140,6 +140,23 @@ class RootModel(BaseXmlModel, tag="model"):
140140
assert_xml_equal(actual_xml, xml)
141141

142142

143+
def test_text_tuple_extraction():
144+
class RootModel(BaseXmlModel, tag="model"):
145+
values: Tuple[int, ...]
146+
147+
xml = '''
148+
<model>1 2 70 -34</model>
149+
'''
150+
151+
actual_obj = RootModel.from_xml(xml)
152+
expected_obj = RootModel(
153+
values=[1, 2, 70, -34]
154+
)
155+
156+
actual_xml = actual_obj.to_xml()
157+
assert_xml_equal(actual_xml, xml)
158+
159+
143160
def test_attr_list_extraction():
144161
class RootModel(BaseXmlModel, tag="model"):
145162
values: List[float] = attr()
@@ -155,7 +172,31 @@ class RootModel(BaseXmlModel, tag="model"):
155172

156173
actual_obj = RootModel.from_xml(xml)
157174
expected_obj = RootModel(
158-
values = [3.14, -1.0, 3e2]
175+
values=[3.14, -1.0, 3e2]
176+
)
177+
178+
assert actual_obj == expected_obj
179+
180+
actual_xml = actual_obj.to_xml()
181+
assert_xml_equal(actual_xml, xml)
182+
183+
184+
def test_attr_tuple_extraction():
185+
class RootModel(BaseXmlModel, tag="model"):
186+
values: List[float] = attr()
187+
188+
xml = '''
189+
<model values="3.14 -1.0 300.0"/>
190+
'''
191+
# This will fail if scientific notation is used
192+
# i.e. if 300 is replaced with 3e2 or 300, the deserializer
193+
# will always use the standard notation with the added `.0`.
194+
# While this behaviour fails the tests, it shouldn't
195+
# matter in practice.
196+
197+
actual_obj = RootModel.from_xml(xml)
198+
expected_obj = RootModel(
199+
values=[3.14, -1.0, 3e2]
159200
)
160201

161202
assert actual_obj == expected_obj

0 commit comments

Comments
 (0)