From 56c9f2110e1abda4f9e17c0916ed6fd08da91c70 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Fri, 20 Oct 2023 22:13:51 +0200 Subject: [PATCH] backend/sdoc: print deprecation warnings when REFS/RELATIONS field is not the last among all fields --- strictdoc/__init__.py | 2 +- strictdoc/backend/sdoc/models/requirement.py | 18 +++++++++++++++++ .../expected_output/document.sdoc | 2 +- .../expected_output/document.sdoc | 2 +- .../expected_output/document2.sdoc | 2 +- .../expected_output/document.sdoc | 2 +- .../expected_output/document.sdoc | 2 +- .../expected_output/document.sdoc | 2 +- .../expected_output/document.sdoc | 2 +- .../test_case.py | 2 +- .../input.sdoc | 13 ++++++++++++ .../test.itest | 8 ++++++++ .../input.sdoc | 20 +++++++++++++++++++ .../test.itest | 8 ++++++++ 14 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 tests/integration/deprecations/refs_replaced_with_relations/20_show_warning_when_refs_or_relations_are_not_last/input.sdoc create mode 100644 tests/integration/deprecations/refs_replaced_with_relations/20_show_warning_when_refs_or_relations_are_not_last/test.itest create mode 100644 tests/integration/deprecations/refs_replaced_with_relations/21_do_not_show_warning_when_refs_or_relations_are_last/input.sdoc create mode 100644 tests/integration/deprecations/refs_replaced_with_relations/21_do_not_show_warning_when_refs_or_relations_are_last/test.itest diff --git a/strictdoc/__init__.py b/strictdoc/__init__.py index 486cfcb8f..4a70a4cee 100644 --- a/strictdoc/__init__.py +++ b/strictdoc/__init__.py @@ -1,6 +1,6 @@ from strictdoc.core.environment import SDocRuntimeEnvironment -__version__ = "0.0.44a16" +__version__ = "0.0.44a17" environment = SDocRuntimeEnvironment(__file__) diff --git a/strictdoc/backend/sdoc/models/requirement.py b/strictdoc/backend/sdoc/models/requirement.py index fd10dc385..fc84adcf1 100644 --- a/strictdoc/backend/sdoc/models/requirement.py +++ b/strictdoc/backend/sdoc/models/requirement.py @@ -142,6 +142,24 @@ def __init__( # pylint: disable=too-many-arguments ordered_fields_lookup.setdefault(field.field_name, []).append(field) if RequirementFieldName.REFS in ordered_fields_lookup: + refs_field: RequirementField = ordered_fields_lookup[ + RequirementFieldName.REFS + ][0] + if fields.index(refs_field) != (len(fields) - 1): + print( # noqa: T201 + "warning: RELATIONS (previously REFS) requirement field " + "should be the last field, after all other fields. " + 'See the section "Relations" in the user guide for ' + "more details. " + "Correct requirement example:\n" + "[REQUIREMENT]\n" + "UID: REQ-2\n" + "STATEMENT: When Z, the system X shall do Y.\n" + "RELATIONS:\n" + "- TYPE: Parent\n" + " VALUE: REQ-1" + ) + references_opt: Optional[List[Reference]] = ordered_fields_lookup[ RequirementFieldName.REFS ][0].field_value_references diff --git a/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_and_role_to_existing_requirement/expected_output/document.sdoc b/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_and_role_to_existing_requirement/expected_output/document.sdoc index 78c622baa..dfe24ee3b 100644 --- a/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_and_role_to_existing_requirement/expected_output/document.sdoc +++ b/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_and_role_to_existing_requirement/expected_output/document.sdoc @@ -29,7 +29,7 @@ TITLE: Requirement #2 title STATEMENT: >>> Requirement #2 statement. <<< -REFS: +RELATIONS: - TYPE: Parent VALUE: REQ-001 ROLE: Refines diff --git a/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_to_existing_requirement/expected_output/document.sdoc b/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_to_existing_requirement/expected_output/document.sdoc index 5e4500acb..d9560c51d 100644 --- a/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_to_existing_requirement/expected_output/document.sdoc +++ b/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_to_existing_requirement/expected_output/document.sdoc @@ -12,6 +12,6 @@ TITLE: Requirement #2 title STATEMENT: >>> Requirement #2 statement. <<< -REFS: +RELATIONS: - TYPE: Parent VALUE: REQ-001 diff --git a/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_to_existing_requirement_in_another_document/expected_output/document2.sdoc b/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_to_existing_requirement_in_another_document/expected_output/document2.sdoc index 4ebaa695f..a392604af 100644 --- a/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_to_existing_requirement_in_another_document/expected_output/document2.sdoc +++ b/tests/end2end/screens/document/create_requirement/_relations/create_requirement_with_relation_to_existing_requirement_in_another_document/expected_output/document2.sdoc @@ -24,7 +24,7 @@ TITLE: Requirement #2 title STATEMENT: >>> Requirement #2 statement. <<< -REFS: +RELATIONS: - TYPE: Parent VALUE: REQ-001 ROLE: Refines diff --git a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_child_link_with_role/expected_output/document.sdoc b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_child_link_with_role/expected_output/document.sdoc index edcdff06e..13d2fe037 100644 --- a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_child_link_with_role/expected_output/document.sdoc +++ b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_child_link_with_role/expected_output/document.sdoc @@ -35,7 +35,7 @@ TITLE: Requirement title #2 STATEMENT: >>> Requirement statement #2. <<< -REFS: +RELATIONS: - TYPE: Child VALUE: REQ-001 ROLE: Refines diff --git a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_link/expected_output/document.sdoc b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_link/expected_output/document.sdoc index f763d8f92..683977460 100644 --- a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_link/expected_output/document.sdoc +++ b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_link/expected_output/document.sdoc @@ -18,6 +18,6 @@ TITLE: Requirement title #2 STATEMENT: >>> Requirement statement #2. <<< -REFS: +RELATIONS: - TYPE: Parent VALUE: REQ-001 diff --git a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_parent_link_with_role/expected_output/document.sdoc b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_parent_link_with_role/expected_output/document.sdoc index d81a27645..9d45ab88d 100644 --- a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_parent_link_with_role/expected_output/document.sdoc +++ b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_one_parent_link_with_role/expected_output/document.sdoc @@ -35,7 +35,7 @@ TITLE: Requirement title #2 STATEMENT: >>> Requirement statement #2. <<< -REFS: +RELATIONS: - TYPE: Parent VALUE: REQ-001 ROLE: Refines diff --git a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_three_links/expected_output/document.sdoc b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_three_links/expected_output/document.sdoc index 21e83a27a..03593ba4d 100644 --- a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_three_links/expected_output/document.sdoc +++ b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_three_links/expected_output/document.sdoc @@ -11,7 +11,7 @@ TITLE: Requirement title #1 STATEMENT: >>> Requirement statement #1. <<< -REFS: +RELATIONS: - TYPE: Parent VALUE: REQ-002 - TYPE: Parent diff --git a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_three_links/test_case.py b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_three_links/test_case.py index 33287b151..bd84c0c04 100644 --- a/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_three_links/test_case.py +++ b/tests/end2end/screens/document/update_requirement/_requirement_relations/update_requirement_add_three_links/test_case.py @@ -9,7 +9,7 @@ from tests.end2end.server import SDocTestServer -class Test_UC07_G1_T02_AddThreeLinks(E2ECase): +class Test(E2ECase): def test(self): test_setup = End2EndTestSetup(path_to_test_file=__file__) diff --git a/tests/integration/deprecations/refs_replaced_with_relations/20_show_warning_when_refs_or_relations_are_not_last/input.sdoc b/tests/integration/deprecations/refs_replaced_with_relations/20_show_warning_when_refs_or_relations_are_not_last/input.sdoc new file mode 100644 index 000000000..4ede80073 --- /dev/null +++ b/tests/integration/deprecations/refs_replaced_with_relations/20_show_warning_when_refs_or_relations_are_not_last/input.sdoc @@ -0,0 +1,13 @@ +[DOCUMENT] +TITLE: Hello world doc + +[REQUIREMENT] +UID: REQ-1 +STATEMENT: Shall do 1. + +[REQUIREMENT] +UID: REQ-2 +REFS: +- TYPE: Parent + VALUE: REQ-1 +STATEMENT: Shall do 1. diff --git a/tests/integration/deprecations/refs_replaced_with_relations/20_show_warning_when_refs_or_relations_are_not_last/test.itest b/tests/integration/deprecations/refs_replaced_with_relations/20_show_warning_when_refs_or_relations_are_not_last/test.itest new file mode 100644 index 000000000..39904234f --- /dev/null +++ b/tests/integration/deprecations/refs_replaced_with_relations/20_show_warning_when_refs_or_relations_are_not_last/test.itest @@ -0,0 +1,8 @@ +RUN: %strictdoc export %S --output-dir Output | filecheck %s --dump-input=fail + +CHECK: warning: RELATIONS (previously REFS) requirement field should be the last field, after all other fields. See the section "Relations" in the user guide for more details. Correct requirement example: +CHECK: Published: Hello world doc + +RUN: %cat %S/Output/html/index.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML +CHECK-HTML: Hello world doc +CHECK-HTML: input.sdoc diff --git a/tests/integration/deprecations/refs_replaced_with_relations/21_do_not_show_warning_when_refs_or_relations_are_last/input.sdoc b/tests/integration/deprecations/refs_replaced_with_relations/21_do_not_show_warning_when_refs_or_relations_are_last/input.sdoc new file mode 100644 index 000000000..2b76e5279 --- /dev/null +++ b/tests/integration/deprecations/refs_replaced_with_relations/21_do_not_show_warning_when_refs_or_relations_are_last/input.sdoc @@ -0,0 +1,20 @@ +[DOCUMENT] +TITLE: Hello world doc + +[REQUIREMENT] +UID: REQ-1 +STATEMENT: Shall do 1. + +[REQUIREMENT] +UID: REQ-2 +STATEMENT: Shall do 1. +REFS: +- TYPE: Parent + VALUE: REQ-1 + +[REQUIREMENT] +UID: REQ-3 +STATEMENT: Shall do 1. +RELATIONS: +- TYPE: Parent + VALUE: REQ-1 diff --git a/tests/integration/deprecations/refs_replaced_with_relations/21_do_not_show_warning_when_refs_or_relations_are_last/test.itest b/tests/integration/deprecations/refs_replaced_with_relations/21_do_not_show_warning_when_refs_or_relations_are_last/test.itest new file mode 100644 index 000000000..e048e6213 --- /dev/null +++ b/tests/integration/deprecations/refs_replaced_with_relations/21_do_not_show_warning_when_refs_or_relations_are_last/test.itest @@ -0,0 +1,8 @@ +RUN: %strictdoc export %S --output-dir Output | filecheck %s --dump-input=fail + +CHECK-NOT: warning: RELATIONS (previously REFS) requirement field should be the last field +CHECK: Published: Hello world doc + +RUN: %cat %S/Output/html/index.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML +CHECK-HTML: Hello world doc +CHECK-HTML: input.sdoc