Skip to content

Commit d075694

Browse files
committed
Add inline lists support for Attributes.
Added new tests and updated old tests as this addition is a regression/backwards incompatibility.
1 parent d6c038c commit d075694

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/test_homogeneous_collections.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,31 @@ class RootModel(BaseXmlModel, tag="model"):
140140
assert_xml_equal(actual_xml, xml)
141141

142142

143+
def test_attr_list_extraction():
144+
class RootModel(BaseXmlModel, tag="model"):
145+
values: List[float] = attr()
146+
147+
xml = '''
148+
<model values="3.14 -1.0 300.0"/>
149+
'''
150+
# This will fail if scientific notation is used
151+
# i.e. if 300 is replaced with 3e2 or 300, the deserializer
152+
# will always use the standard notation with the added `.0`.
153+
# While this behaviour fails the tests, it shouldn't
154+
# matter in practice.
155+
156+
actual_obj = RootModel.from_xml(xml)
157+
expected_obj = RootModel(
158+
values = [3.14, -1.0, 3e2]
159+
)
160+
161+
assert actual_obj == expected_obj
162+
163+
actual_xml = actual_obj.to_xml()
164+
assert_xml_equal(actual_xml, xml)
165+
166+
143167
def test_homogeneous_definition_errors():
144-
breakpoint()
145168
with pytest.raises(errors.ModelFieldError):
146169
class TestModel(BaseXmlModel):
147170
attr1: List[Tuple[int, ...]]
@@ -179,3 +202,4 @@ class TestSubModel(BaseXmlModel):
179202

180203
class TestModel(BaseXmlModel):
181204
text: List[TestSubModel]
205+

0 commit comments

Comments
 (0)