Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions reqif/models/reqif_spec_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def __init__( # pylint: disable=too-many-arguments
self,
attribute_type: SpecObjectAttributeType,
definition_ref: str,
value: Union[str, List[str]],
value: Union[bool, float, int, str, List[str]],
value_stripped_xhtml: Optional[str] = None,
xml_node: Optional[Any] = None,
):
self.attribute_type: SpecObjectAttributeType = attribute_type
self.definition_ref: str = definition_ref
self.value: Union[str, List[str]] = value
self.value: Union[bool, float, int, str, List[str]] = value
# Only for XHTML attributes: A value stripped of the
# <xhtml:...> namespace. <xhtml:div> becomes <div>...
self.value_stripped_xhtml: Optional[str] = value_stripped_xhtml
Expand Down
46 changes: 39 additions & 7 deletions tests/integration/examples/01_create_reqif_objects/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ExampleIdentifiers:
# For example, 550e8400-e29b-41d4-a716-446655440000 or similar.
# For this example, we keep it as strings.
STRING_DATATYPE_ID = create_uuid()
SPEC_ATTRIBUTE_ID = create_uuid()
SPEC_ATTRIBUTE_IDs = list(map(create_uuid, range(9)))
SPEC_OBJECT_TYPE_ID = create_uuid()
SPEC_OBJECT_ID = create_uuid()
SPEC_HIERARCHY_ID = create_uuid()
Expand Down Expand Up @@ -63,15 +63,47 @@ class ExampleIdentifiers:
attribute_definitions=[requirement_text_attribute],
)

spec_object_attribute = SpecObjectAttribute(
attribute_type=SpecObjectAttributeType.STRING,
definition_ref=ExampleIdentifiers.SPEC_ATTRIBUTE_ID,
value="System ABC shall do XYQ.",
)
spec_object_attributes = [
SpecObjectAttribute(
attribute_type=SpecObjectAttributeType.STRING,
definition_ref=ExampleIdentifiers.SPEC_ATTRIBUTE_IDs[0],
value="System ABC shall do XYQ.",
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for showing it with a test. This could be a useful change for the use case that you described.

Let's also add a validation inside the init method: if an int value is provided than the type should be INTEGER and similar for all other types. If these is a type mismatch, let's through a TypeError.

SpecObjectAttribute(
attribute_type=SpecObjectAttributeType.INTEGER,
definition_ref=ExampleIdentifiers.SPEC_ATTRIBUTE_IDs[1],
value="1",
),
SpecObjectAttribute(
attribute_type=SpecObjectAttributeType.INTEGER,
definition_ref=ExampleIdentifiers.SPEC_ATTRIBUTE_IDs[2],
value=1,
),
SpecObjectAttribute(
attribute_type=SpecObjectAttributeType.REAL,
definition_ref=ExampleIdentifiers.SPEC_ATTRIBUTE_IDs[3],
value="1.0",
),
SpecObjectAttribute(
attribute_type=SpecObjectAttributeType.REAL,
definition_ref=ExampleIdentifiers.SPEC_ATTRIBUTE_IDs[4],
value=1.0,
),
SpecObjectAttribute(
attribute_type=SpecObjectAttributeType.BOOLEAN,
definition_ref=ExampleIdentifiers.SPEC_ATTRIBUTE_IDs[5],
value=False,
),
SpecObjectAttribute(
attribute_type=SpecObjectAttributeType.BOOLEAN,
definition_ref=ExampleIdentifiers.SPEC_ATTRIBUTE_IDs[6],
value=True,
),
]

spec_object = ReqIFSpecObject(
identifier=ExampleIdentifiers.SPEC_OBJECT_ID,
attributes=[spec_object_attribute],
attributes=spec_object_attributes,
spec_object_type=spec_object_type.identifier,
last_change=date_now,
)
Expand Down