Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1305 from strictdoc-project/stan…
Browse files Browse the repository at this point in the history
…islaw/relations

backend/sdoc: recognize REFS/RELATION field in the grammar
  • Loading branch information
stanislaw authored Sep 16, 2023
2 parents 8d5bcd3 + 528f2fb commit 3f83781
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
4 changes: 3 additions & 1 deletion strictdoc/backend/excel/import_/excel_to_sdoc_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ def create_requirement(
comments=comments,
)
if parent_uid is not None:
reference = ParentReqReference(template_requirement, parent_uid)
reference = ParentReqReference(
template_requirement, parent_uid, relation_uid=None
)

requirement_field = RequirementField(
parent=template_requirement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ def create_requirement_from_spec_object(
parent_spec_object_parent.attribute_map[
foreign_key_id_or_none
].value,
relation_uid=None,
)
)
if len(parent_refs) > 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def _p11_create_requirement_from_spec_object(
parent_spec_object_parent.attribute_map[
foreign_key_id_or_none
].value,
relation_uid=None,
)
)
if len(parent_refs) > 0:
Expand Down
1 change: 1 addition & 0 deletions strictdoc/backend/sdoc/grammar/type_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ParentReqReference[noskipws]:
'- TYPE: Parent' '\n'
' VALUE: ' ref_uid = /.*$/ '\n'
(' RELATION: ' relation_uid = /.+$/ '\n')?
;
ChildReqReference[noskipws]:
Expand Down
12 changes: 10 additions & 2 deletions strictdoc/backend/sdoc/models/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ def get_file_format(self) -> Optional[str]:

@auto_described
class ParentReqReference(Reference):
def __init__(self, parent, ref_uid):
def __init__(self, parent, ref_uid: str, relation_uid: Optional[str]):
super().__init__(ReferenceType.PARENT, parent)
self.ref_uid = ref_uid
self.ref_uid: str = ref_uid
# When RELATION: field is not provided for a parent reference, the
# textX still passes relation_uid as an empty string (instead of None
# as one could expect).
self.relation_uid: Optional[str] = (
relation_uid
if relation_uid is not None and len(relation_uid) > 0
else None
)


@auto_described
Expand Down
4 changes: 4 additions & 0 deletions strictdoc/backend/sdoc/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def _print_requirement_fields(
output += " VALUE: "
output += ref.ref_uid
output += "\n"
if reference.relation_uid is not None:
output += " RELATION: "
output += ref.relation_uid
output += "\n"

elif field.field_value is not None:
if len(field.field_value) > 0:
Expand Down
4 changes: 3 additions & 1 deletion strictdoc/server/routers/main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,9 @@ def __init__(self):
for reference_field in form_object.reference_fields:
ref_uid = reference_field.field_value
references.append(
ParentReqReference(parent=requirement, ref_uid=ref_uid)
ParentReqReference(
parent=requirement, ref_uid=ref_uid, relation_uid=None
)
)
if len(references) > 0:
requirement.ordered_fields_lookup[RequirementFieldName.REFS] = [
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/helpers/test_document_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def add_requirement_parent(self, req_id, parent_req_id):
)
assert requirement

reference = ParentReqReference(requirement, parent_req_id)
reference = ParentReqReference(
requirement, parent_req_id, relation_uid=None
)
requirement.references.append(reference)

def build(self):
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/strictdoc/backend/sdoc/test_dsl_passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,32 @@ def test_010_multiple_sections():
assert input_sdoc == output


def test_020_parent_ref_with_relation():
input_sdoc = """
[DOCUMENT]
TITLE: Test Doc
[REQUIREMENT]
REFS:
- TYPE: Parent
VALUE: ID-001
RELATION: Refines
STATEMENT: >>>
This is a statement.
<<<
""".lstrip()

reader = SDReader()

document = reader.read(input_sdoc)
assert isinstance(document, Document)

writer = SDWriter()
output = writer.write(document)

assert input_sdoc == output


def test_030_multiline_statement():
input_sdoc = """
[DOCUMENT]
Expand Down

0 comments on commit 3f83781

Please sign in to comment.