@@ -140,6 +140,23 @@ class RootModel(BaseXmlModel, tag="model"):
140
140
assert_xml_equal (actual_xml , xml )
141
141
142
142
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
+
143
160
def test_attr_list_extraction ():
144
161
class RootModel (BaseXmlModel , tag = "model" ):
145
162
values : List [float ] = attr ()
@@ -155,7 +172,31 @@ class RootModel(BaseXmlModel, tag="model"):
155
172
156
173
actual_obj = RootModel .from_xml (xml )
157
174
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 ]
159
200
)
160
201
161
202
assert actual_obj == expected_obj
0 commit comments