Skip to content

Commit 8008c88

Browse files
authored
Merge pull request #210 from simonas-drauksas-sensmetry/fix/real-default-as-integer
Fix: parsing ATTRIBUTE-DEFINITION-REAL default values
2 parents 9bfbd21 + e53b2f1 commit 8008c88

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

reqif/parsers/attribute_definition_parser.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ def parse_attribute_definitions(
105105

106106
xml_default_value = attribute_definition.find("DEFAULT-VALUE")
107107
if xml_default_value is not None:
108-
xml_attribute_value = xml_default_value.find(
109-
"ATTRIBUTE-VALUE-INTEGER"
110-
)
108+
xml_attribute_value = xml_default_value.find("ATTRIBUTE-VALUE-REAL")
111109
assert xml_attribute_value is not None
112110
default_value = xml_attribute_value.attrib["THE-VALUE"]
113111

tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def lint_mypy(context):
141141
--disable-error-code=type-arg
142142
--disable-error-code=union-attr
143143
--strict
144+
--no-site-packages
144145
--python-version=3.9
145146
""",
146147
)

tests/unit/reqif/parsers/test_spec_type_parser.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,33 @@ def test_06_string_attribute_default_value() -> None:
172172
== "TEST_STRING_ATTRIBUTE_LONG_NAME"
173173
)
174174
assert reqif_spec_object_type.attribute_definitions[0].default_value == "TBD"
175+
176+
177+
def test_07_real_attribute_definition_with_default_value() -> None:
178+
spec_type_string = """
179+
<SPEC-OBJECT-TYPE IDENTIFIER="TEST_SPEC_OBJECT_TYPE_ID" LAST-CHANGE="2021-02-08T16:37:07.454+01:00" LONG-NAME="TEST_SPEC_OBJECT_TYPE_LONG_NAME">
180+
<SPEC-ATTRIBUTES>
181+
<ATTRIBUTE-DEFINITION-REAL IDENTIFIER="TEST_REAL_ATTRIBUTE_ID" LONG-NAME="TEST_REAL_ATTRIBUTE_LONG_NAME" IS-EDITABLE="false">
182+
<DEFAULT-VALUE>
183+
<ATTRIBUTE-VALUE-REAL THE-VALUE="3.14"/>
184+
</DEFAULT-VALUE>
185+
<TYPE>
186+
<DATATYPE-DEFINITION-REAL-REF>TEST_REAL_TYPE</DATATYPE-DEFINITION-REAL-REF>
187+
</TYPE>
188+
</ATTRIBUTE-DEFINITION-REAL>
189+
</SPEC-ATTRIBUTES>
190+
</SPEC-OBJECT-TYPE>
191+
""" # noqa: E501
192+
spec_type_xml = etree.fromstring(spec_type_string)
193+
194+
reqif_spec_object_type = SpecObjectTypeParser.parse(spec_type_xml)
195+
assert isinstance(reqif_spec_object_type, ReqIFSpecObjectType)
196+
assert reqif_spec_object_type.identifier == "TEST_SPEC_OBJECT_TYPE_ID"
197+
assert reqif_spec_object_type.long_name == "TEST_SPEC_OBJECT_TYPE_LONG_NAME"
198+
attribute_map = reqif_spec_object_type.attribute_map
199+
assert len(attribute_map) == 1
200+
assert (
201+
attribute_map.get("TEST_REAL_ATTRIBUTE_ID").long_name
202+
== "TEST_REAL_ATTRIBUTE_LONG_NAME"
203+
)
204+
assert reqif_spec_object_type.attribute_definitions[0].default_value == "3.14"

0 commit comments

Comments
 (0)