diff --git a/src/extensions/score_metamodel/tests/rst/attributes/test_prohibited_words.rst b/src/extensions/score_metamodel/tests/rst/attributes/test_prohibited_words.rst index 4a470ecaf..506bad566 100644 --- a/src/extensions/score_metamodel/tests/rst/attributes/test_prohibited_words.rst +++ b/src/extensions/score_metamodel/tests/rst/attributes/test_prohibited_words.rst @@ -23,7 +23,7 @@ .. Title contains no stop word -#EXPECT-NOT: feat_req__test__title_good: contains a weak word: `must` in option: `title`. Please revise the wording. +#EXPECT-NOT: title .. feat_req:: This is a test :id: feat_req__test__title_good @@ -38,7 +38,7 @@ -#EXPECT-NOT: stkh_req__test_title_good: contains a weak word: `must` in option: `title`. Please revise the wording. +#EXPECT-NOT: title .. stkh_req:: This is a test :id: stkh_req__test_title_good @@ -67,7 +67,7 @@ .. Description of architecture view of type feat_arc_sta is not checked for weak words -#EXPECT-NOT: feat_arc_sta_desc_good: contains a weak word: `really` in option: `content`. Please revise the wording. +#EXPECT-NOT: content .. feat_arc_sta:: This is a test :id: feat_arc_sta_desc_good diff --git a/src/extensions/score_metamodel/tests/rst/graph/test_metamodel_graph.rst b/src/extensions/score_metamodel/tests/rst/graph/test_metamodel_graph.rst index b93561e0e..3f44a28a2 100644 --- a/src/extensions/score_metamodel/tests/rst/graph/test_metamodel_graph.rst +++ b/src/extensions/score_metamodel/tests/rst/graph/test_metamodel_graph.rst @@ -31,7 +31,7 @@ .. Positive Test: Child requirement QM. Parent requirement has the correct related safety level. Parent requirement is `QM`. -#EXPECT-NOT: feat_req__child__1: Parent need `feat_req__parent__QM` does not fulfill condition `safety == QM`. Explanation: An ASIL requirement must link at least one parent/upstream ASIL requirement for correct decomposition. Please ensure the parent’s safety level is QM and its status is valid. +#EXPECT-NOT: safety .. feat_req:: Child requirement 1 :id: feat_req__child__1 @@ -41,7 +41,7 @@ .. Positive Test: Child requirement ASIL B. Parent requirement has the correct related safety level. Parent requirement is `QM`. -#EXPECT-NOT: feat_req__child__2: Parent need `feat_req__parent__ASIL_B` does not fulfill condition `safety == QM`. Explanation: An ASIL requirement must link at least one parent/upstream ASIL requirement for correct decomposition. Please ensure the parent’s safety level is QM and its status is valid. +#EXPECT-NOT: safety .. feat_req:: Child requirement 2 :id: feat_req__child__2 @@ -62,17 +62,6 @@ -.. Parent requirement does not exist -#EXPECT: unknown outgoing link - -.. feat_req:: Child requirement 4 - :id: feat_req__linking_to_unknown_parent - :safety: ASIL_B - :status: valid - :satisfies: feat_req__parent0__abcd - - - .. Mitigation of Safety Analysis (FMEA and DFA) shall be checked. Mitigation shall have the same or higher safety level than the analysed item. .. Negative Test: Linked to a mitigation that is lower than the safety level of the analysed item. #EXPECT: feat_saf_dfa__child__5: Parent need `feat_req__parent__QM` does not fulfill condition `safety != QM`. Explanation: An ASIL_B safety requirement must link to a ASIL_B requirement. Please ensure that the linked requirements safety level is not QM and it's status is valid. @@ -85,7 +74,7 @@ .. Positive Test: Linked to a mitigation that is equal to the safety level of the analysed item. -#EXPECT-NOT: feat_saf_dfa__child__6: Parent need `feat_req__parent__ASIL_B` does not fulfill condition `safety != QM`. Explanation: An ASIL_B safety requirement must link to a ASIL_B requirement. Please ensure that the linked requirements safety level is not QM and it's status is valid. +#EXPECT-NOT: safety .. feat_saf_dfa:: Child requirement 6 :id: feat_saf_dfa__child__6 @@ -106,7 +95,7 @@ .. Positive Test: Linked to a mitigation that is equal to the safety level of the analysed item. -#EXPECT-NOT: comp_saf_dfa__child__8: Parent need `feat_req__parent__ASIL_B` does not fulfill condition `safety != QM`. Explanation: An ASIL_B safety requirement must link to a ASIL_B requirement. Please ensure that the linked requirements safety level is not QM and it's status is valid. +#EXPECT-NOT: safety .. comp_saf_dfa:: Child requirement 8 :id: comp_saf_dfa__child__8 @@ -127,7 +116,7 @@ .. Positive Test: Linked to a mitigation that is equal to the safety level of the analysed item. -#EXPECT-NOT: feat_saf_dfa__child__10: Parent need `feat_req__parent__ASIL_B` does not fulfill condition `safety != QM`. Explanation: An ASIL_B safety requirement must link to a ASIL_B requirement. Please ensure that the linked requirements safety level is not QM and it's status is valid. +#EXPECT-NOT: safety .. feat_saf_dfa:: Child requirement 10 :id: feat_saf_dfa__child__10 @@ -148,7 +137,7 @@ .. Positive Test: Linked to a mitigation that is equal to the safety level of the analysed item. -#EXPECT-NOT: feat_saf_fmea__child__12: Parent need `feat_req__parent__ASIL_B` does not fulfill condition `safety != QM`. Explanation: An ASIL_B safety requirement must link to a ASIL_B requirement. Please ensure that the linked requirements safety level is not QM and it's status is valid. +#EXPECT-NOT: safety .. feat_saf_fmea:: Child requirement 12 :id: feat_saf_fmea__child__12 @@ -159,7 +148,7 @@ .. Positive Test: Linked to a mitigation that is higher to the safety level of the analysed item. -#EXPECT-NOT: feat_saf_fmea__child__13: Parent need `feat_req__parent__ASIL_B` does not fulfill condition `safety != QM`. Explanation: An ASIL_B safety requirement must link to a ASIL_B requirement. Please ensure that the linked requirements safety level is not QM and it's status is valid. +#EXPECT-NOT: safety .. feat_saf_fmea:: Child requirement 13 :id: feat_saf_fmea__child__13 @@ -179,8 +168,7 @@ .. Positive Test: Linked to a mitigation that is equal to the safety level of the analysed item. -#EXPECT-NOT: comp_saf_fmea__child__15: Parent need `feat_req__parent__ASIL_B` does not fulfill condition `safety != QM`. Explanation: An ASIL_B safety requirement must link to a ASIL_B requirement. Please ensure that the linked requirements safety level is not QM and it's status is valid. - +#EXPECT-NOT: safety .. comp_saf_fmea:: Child requirement 15 :id: comp_saf_fmea__child__15 :safety: ASIL_B diff --git a/src/extensions/score_metamodel/tests/rst/id_contains_feature/test_id_contains_feature.rst b/src/extensions/score_metamodel/tests/rst/id_contains_feature/test_id_contains_feature.rst index 5b6aa74ad..b8ea0f11c 100644 --- a/src/extensions/score_metamodel/tests/rst/id_contains_feature/test_id_contains_feature.rst +++ b/src/extensions/score_metamodel/tests/rst/id_contains_feature/test_id_contains_feature.rst @@ -13,13 +13,6 @@ # ******************************************************************************* #CHECK: id_contains_feature -.. Feature is deeper in the path of the RST file -.. This is now explicitly allowed -#EXPECT-NOT: std_wp__test__abcd.id (std_wp__test__abcd): Feature 'test' not in path - -.. std_wp:: This is a test - :id: std_wp__test__abcd - .. Feature is in the path of the RST file #EXPECT-NOT: Feature 'id_contains_feature' not in path diff --git a/src/extensions/score_metamodel/tests/rst/options/test_options_options.rst b/src/extensions/score_metamodel/tests/rst/options/test_options_options.rst index fdad574c7..014e1e25d 100644 --- a/src/extensions/score_metamodel/tests/rst/options/test_options_options.rst +++ b/src/extensions/score_metamodel/tests/rst/options/test_options_options.rst @@ -24,7 +24,7 @@ .. All required options are present -#EXPECT-NOT: std_wp__test__abcd: is missing required attribute +#EXPECT-NOT: attribute .. std_wp:: This is a test :id: std_wp__test__abce @@ -61,14 +61,14 @@ :sufficient: QM -#EXPECT-NOT: feat_saf_fmea__test__good_2.sufficient (yes): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. feat_saf_fmea:: This is a test :id: feat_saf_fmea__test__2 :sufficient: yes -#EXPECT-NOT: feat_saf_fmea__test__good_3.sufficient (no): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. feat_saf_fmea:: This is a test :id: feat_saf_fmea__test__3 @@ -82,14 +82,14 @@ :sufficient: QM -#EXPECT-NOT: comp_saf_fmea__test__good_5.sufficient (yes): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. comp_saf_fmea:: This is a test :id: comp_saf_fmea__test__5 :sufficient: yes -#EXPECT-NOT: comp_saf_fmea__test__good_6.sufficient (no): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. comp_saf_fmea:: This is a test :id: comp_saf_fmea__test__6 @@ -103,14 +103,14 @@ :sufficient: QM -#EXPECT-NOT: feat_saf_dfa__test__good_8.sufficient (yes): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. feat_saf_dfa:: This is a test :id: feat_saf_dfa__test__8 :sufficient: yes -#EXPECT-NOT: feat_saf_dfa__test__good_9.sufficient (no): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. feat_saf_dfa:: This is a test :id: feat_saf_dfa__test__9 @@ -124,14 +124,14 @@ :sufficient: QM -#EXPECT-NOT: feat_saf_dfa__test__good_11.sufficient (yes): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. feat_saf_dfa:: This is a test :id: feat_saf_dfa__test__11 :sufficient: yes -#EXPECT-NOT: feat_saf_dfa__test__good_12.sufficient (no): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. feat_saf_dfa:: This is a test :id: feat_saf_dfa__test__12 @@ -145,14 +145,14 @@ :sufficient: QM -#EXPECT-NOT: comp_saf_dfa__test__good_14.sufficient (yes): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. comp_saf_dfa:: This is a test :id: comp_saf_dfa__test__14 :sufficient: yes -#EXPECT-NOT: comp_saf_dfa__test__good_15.sufficient (no): does not follow pattern `^(yes|no)$`. +#EXPECT-NOT: pattern .. comp_saf_dfa:: This is a test :id: comp_saf_dfa__test__15 @@ -220,7 +220,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n .. Tests if the attribute `safety` follows the pattern `^(QM|ASIL_B)$` -#EXPECT-NOT: doc__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. document:: This is a test document :id: doc__test_good_1 @@ -228,7 +228,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: doc__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. document:: This is a test document :id: doc__test_good_2 @@ -236,7 +236,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: stkh_req__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. stkh_req:: This is a test :id: stkh_req__test_good_1 @@ -244,7 +244,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: stkh_req__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. stkh_req:: This is a test :id: stkh_req__test_good_2 @@ -252,7 +252,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: feat_req__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. feat_req:: This is a test :id: feat_req__test_good_1 @@ -260,7 +260,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: feat_req__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. feat_req:: This is a test :id: feat_req__test_good_2 @@ -268,7 +268,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: comp_req__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. comp_req:: This is a test :id: comp_req__test_good_1 @@ -276,7 +276,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: comp_req__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. comp_req:: This is a test :id: comp_req__test_good_2 @@ -284,7 +284,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: tool_req__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. tool_req:: This is a test :id: tool_req__test_good_1 @@ -293,7 +293,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n -#EXPECT-NOT: tool_req__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. tool_req:: This is a test :id: tool_req__test_good_2 @@ -301,15 +301,14 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: aou_req__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. - +#EXPECT-NOT: pattern .. aou_req:: This is a test :id: aou_req__test_good_1 :status: valid :safety: QM -#EXPECT-NOT: aou_req__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. aou_req:: This is a test :id: aou_req__test_good_2 @@ -317,7 +316,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: feat_arc_sta__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. feat_arc_sta:: This is a test :id: feat_arc_sta__test_good_1 @@ -325,7 +324,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: feat_arc_sta__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. feat_arc_sta:: This is a test :id: feat_arc_sta__test_good_2 @@ -333,7 +332,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: feat_arc_dyn__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. feat_arc_dyn:: This is a test :id: feat_arc_dyn__test_good_1 @@ -342,7 +341,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n -#EXPECT-NOT: feat_arc_dyn__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. feat_arc_dyn:: This is a test :id: feat_arc_dyn__test_good_2 @@ -350,7 +349,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: logic_arc_int__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. logic_arc_int:: This is a test :id: logic_arc_int__test_good_1 @@ -359,7 +358,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n -#EXPECT-NOT: logic_arc_int__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. logic_arc_int:: This is a test :id: logic_arc_int__test_good_2 @@ -367,7 +366,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: logic_arc_int_op__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. logic_arc_int_op:: This is a test :id: logic_arc_int_op__test_good_1 @@ -375,7 +374,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: logic_arc_int_op__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. logic_arc_int_op:: This is a test :id: logic_arc_int_op__test_good_2 @@ -383,7 +382,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: comp_arc_sta__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. comp_arc_sta:: This is a test :id: comp_arc_sta__test_good_1 @@ -391,7 +390,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: comp_arc_sta__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. comp_arc_sta:: This is a test :id: comp_arc_sta__test_good_2 @@ -399,7 +398,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: comp_arc_dyn__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. comp_arc_dyn:: This is a test :id: comp_arc_dyn__test_good_1 @@ -407,7 +406,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: comp_arc_dyn__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. comp_arc_dyn:: This is a test :id: comp_arc_dyn__test_good_2 @@ -416,7 +415,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n -#EXPECT-NOT: real_arc_int__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. real_arc_int:: This is a test :id: real_arc_int__test_good_1 @@ -424,7 +423,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: real_arc_int__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. real_arc_int:: This is a test :id: real_arc_int__test_good_2 @@ -432,14 +431,14 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: real_arc_int_op__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. real_arc_int_op:: This is a test :id: real_arc_int_op__test_good_1 :status: valid :safety: QM -#EXPECT-NOT: real_arc_int_op__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. real_arc_int_op:: This is a test :id: real_arc_int_op__test_good_2 @@ -447,14 +446,14 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: dd_sta__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. dd_sta:: This is a test :id: dd_sta__test_good_1 :status: valid :safety: QM -#EXPECT-NOT: dd_sta__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. dd_sta:: This is a test :id: dd_sta__test_good_2 @@ -462,14 +461,14 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: dd_dyn__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. dd_dyn:: This is a test :id: dd_dyn__test_good_1 :status: valid :safety: QM -#EXPECT-NOT: dd_dyn__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. dd_dyn:: This is a test :id: dd_dyn__test_good_2 @@ -477,7 +476,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: ASIL_B -#EXPECT-NOT: sw_unit__test_good_1.safety (QM): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. sw_unit:: This is a test :id: sw_unit__test_good_1 @@ -485,7 +484,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n :safety: QM -#EXPECT-NOT: sw_unit__test_good_2.safety (ASIL_B): does not follow pattern `^(QM|ASIL_B)$`. +#EXPECT-NOT: pattern .. sw_unit:: This is a test :id: sw_unit__test_good_2 @@ -506,7 +505,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n .. Ensuring that non empty content is detected correctly -#EXPECT-NOT: stkh_req__test_content: is missing required attribute: `content` +#EXPECT-NOT: attribute: `content` .. stkh_req:: This is a test :id: stkh_req__test_content @@ -518,7 +517,7 @@ Expect no errors related to "violates" field. We need to be generic for expect-n .. This should not trigger, as 'std_wp' is not checked for content -#EXPECT-NOT: std_wp__test_content: is missing required attribute: `content` +#EXPECT-NOT: attribute: `content` .. std_wp:: This is a test :id: std_wp__test_content diff --git a/src/extensions/score_metamodel/tests/test_rules_file_based.py b/src/extensions/score_metamodel/tests/test_rules_file_based.py index 13d3ace5f..73a65962c 100644 --- a/src/extensions/score_metamodel/tests/test_rules_file_based.py +++ b/src/extensions/score_metamodel/tests/test_rules_file_based.py @@ -12,6 +12,7 @@ # ******************************************************************************* import os +import re import shutil from collections.abc import Callable from dataclasses import dataclass, field @@ -116,7 +117,7 @@ def extract_test_data(rst_file: Path) -> RstData | None: # The function returns a list of WarningInfo objects # containing the line number and the expected and not expected warnings. # If no test data is found, it returns None. - rst_data = RstData(filename=rst_file.name) + rst_data = RstData(filename=str(rst_file.relative_to(RST_DIR))) with open(rst_file) as f: test_info: WarningInfo | None = None for no, line in enumerate(f, start=1): @@ -150,10 +151,17 @@ def filter_warnings_by_position( warning_info: WarningInfo, warnings: list[str], ) -> list[str]: + """ + Filtering only warnings that belong to this file & line. But also deleting the prefix. + Filter out the filepath:linenr prefix from warning. So that the 'expect-not' can be generic + Without having to pay attention to the filename for example 'EXPECT-NOT: test' then matching + a random warning because 'test' is in the filename of 'graph/test_graph_checks.rst' + """ + prefix = f"{rst_data.filename}:{warning_info.lineno}: WARNING:" return [ - warning + warning.removeprefix(prefix) for warning in warnings - if (f"{rst_data.filename}:{str(warning_info.lineno)}" in warning) + if warning.startswith(prefix) ] @@ -165,12 +173,19 @@ def warning_matches( ) -> str | None: ### Checks if any element of the warning list is includes the given warning info. # It returns the matched warning or None if no match is found. + for warning in filter_warnings_by_position(rst_data, warning_info, warnings): if expected_message in warning: return warning return None +def strip_ansi_codes(text: str) -> str: + """Remove ANSI escape sequences from text""" + ansi_escape = re.compile(r"\x1b\[[0-9;]*m") + return ansi_escape.sub("", text) + + @pytest.mark.parametrize("rst_file", RST_FILES) def test_rst_files( rst_file: str, sphinx_app_setup: Callable[[Path], SphinxTestApp] @@ -192,8 +207,13 @@ def test_rst_files( app.build() # Collect the warnings - warnings = app.warning.getvalue().splitlines() - print("\n".join(w for w in warnings if "score_metamodel" in w)) + raw_warnings = app.warning.getvalue().splitlines() + warnings = [strip_ansi_codes(w) for w in raw_warnings if "score_metamodel" in w] + + # Enable this if you need to see errors for debugging purposes + # print( + # "\n".join(strip_ansi_codes(w) for w in raw_warnings if "score_metamodel" in w) + # ) # Check if the expected warnings are present for warning_info in rst_data.warning_infos: