Skip to content

Commit 48cc773

Browse files
authored
tooling: Add new test files for check rule tests (#980)
* Add new test files * Comment test files * Optimize check of enabled checks
1 parent ed1c53c commit 48cc773

10 files changed

Lines changed: 119 additions & 12 deletions

tooling/docs/_tooling/extensions/score_metamodel/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ def _run_checks(app: Sphinx, exception: Exception | None) -> None:
8686
def is_check_enabled(check: local_check_function | graph_check_function):
8787
return not checks_filter or check.__name__ in checks_filter
8888

89+
enabled_local_checks = [c for c in local_checks if is_check_enabled(c)]
90+
8991
# Need-Local checks: checks which can be checked file-local, without a
9092
# graph of other needs.
9193
for need in needs_all_needs.values():
92-
for check in [c for c in local_checks if is_check_enabled(c)]:
94+
for check in enabled_local_checks:
9395
logger.info(f"Running local check {check} for need {need['id']}")
9496
check(app, need, log)
9597

tooling/docs/_tooling/extensions/score_metamodel/tests/rst/attributes/test_attributes_format_description.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,28 @@
1111
#
1212
# SPDX-License-Identifier: Apache-2.0
1313
# *******************************************************************************
14+
#CHECK: check_description
1415

15-
.. Test xy
16+
.. Description contains a weak word
1617
#EXPECT: stkh_req__test__abcd.content (This should really work): contains a weak word: `really`.
1718

1819
.. stkh_req:: This is a test
1920
:id: stkh_req__test__abcd
2021

2122
This should really work
2223

23-
#EXPECT-NOT: stkh_req__test__abce.title (This should work): contains a weak word
24+
.. Description contains no weak word
25+
#EXPECT-NOT: contains a weak word
2426

2527
.. stkh_req:: This is a test
2628
:id: stkh_req__test__abce
2729

2830
This should work
31+
32+
.. Description of requirement of type std_wp is not checked for weak words
33+
#EXPECT-NOT: contains a weak word
34+
35+
.. std_wp:: This is a test
36+
:id: stdwp__test__abce
37+
38+
This should really work

tooling/docs/_tooling/extensions/score_metamodel/tests/rst/attributes/test_attributes_format_id_format.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@
1111
#
1212
# SPDX-License-Identifier: Apache-2.0
1313
# *******************************************************************************
14+
#CHECK: check_id_format
1415

16+
.. Id does not consists of 3 parts
1517
#EXPECT: std_wp__test__test__abcd.id (std_wp__test__test__abcd): expected to consisting of this format: `<Req Type>__<Abbreviations>__<Architectural Element>`.
1618

1719
.. std_wp:: This is a test
1820
:id: std_wp__test__test__abcd
1921

20-
#EXPECT-NOT: std_wp__test__abce.id (std_wp__test__abce): expected to consisting of this format: `<Req Type>__<Abbreviations>__<Architectural Element>`.
22+
.. Id follows pattern
23+
#EXPECT-NOT: expected to consisting of this format: `<Req Type>__<Abbreviations>__<Architectural Element>`.
2124

2225
.. std_wp:: This is a test
2326
:id: std_wp__test__abce
2427

28+
.. Id starts with wp and number of parth is neither 2 nor 3
2529
#EXPECT: wp__test__test__abcd.id (wp__test__test__abcd): expected to consisting of one of these 2 formats:`<Req Type>__<Abbreviations>` or `<Req Type>__<Abbreviations>__<Architectural Element>`.
2630

2731
.. std_wp:: This is a test
2832
:id: wp__test__test__abcd
2933

30-
#EXPECT-NOT: wp__test__abce.id (wp__test__abce): expected to consisting of one of these 2 formats:`<Req Type>__<Abbreviations>` or `<Req Type>__<Abbreviations>__<Architectural Element>`.
34+
.. Id is valid, because it starts with wp and contains 3 parts
35+
#EXPECT-NOT: expected to consisting of one of these 2 formats:`<Req Type>__<Abbreviations>` or `<Req Type>__<Abbreviations>__<Architectural Element>`.
3136

3237
.. std_wp:: This is a test
3338
:id: wp__test__abce

tooling/docs/_tooling/extensions/score_metamodel/tests/rst/attributes/test_attributes_format_id_length.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
#
1212
# SPDX-License-Identifier: Apache-2.0
1313
# *******************************************************************************
14+
#CHECK: check_id_length
1415

16+
.. Id contains too many characters
1517
#EXPECT: std_wp__testabcdefghijklmnopqrstuvwxyz123__abcd.id (std_wp__testabcdefghijklmnopqrstuvwxyz123__abcd): exceeds the maximum allowed length of 45 characters (current length: 47).
1618

1719
.. std_wp:: This is a test
1820
:id: std_wp__testabcdefghijklmnopqrstuvwxyz123__abcd
1921

20-
#EXPECT-NOT: std_wp__test__abce.id (std_wp__test__abce): exceeds the maximum allowed length of 45 characters
22+
.. Id has correct length
23+
#EXPECT-NOT: exceeds the maximum allowed length of 45 characters
2124

2225
.. std_wp:: This is a test
2326
:id: std_wp__test__abce

tooling/docs/_tooling/extensions/score_metamodel/tests/rst/attributes/test_attributes_format_title.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@
1111
#
1212
# SPDX-License-Identifier: Apache-2.0
1313
# *******************************************************************************
14+
#CHECK: check_title
1415

16+
.. Title contains a stop word
1517
#EXPECT: feat_req__test__abcd.title (This must work): contains a stop word: `must`.
1618

1719
.. feat_req:: This must work
1820
:id: feat_req__test__abcd
1921

22+
.. Title contains no stop word
2023
#EXPECT-NOT: feat_req__test__abce.title (This is a test): contains a stop word
2124

2225
.. feat_req:: This is a test
2326
:id: feat_req__test__abce
27+
28+
.. Title of requirement of type std_wp is not checked for stop words
29+
#EXPECT-NOT: std_wp__test__abce.title (This must work): contains a stop word: `must`.
30+
31+
.. std_wp:: This must work
32+
:id: std_wp__test__abce

tooling/docs/_tooling/extensions/score_metamodel/tests/rst/graph/test_metamodel_graph.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
:safety: QM
1919
:status: valid
2020

21+
.. Parent requirement has not the correct safety level
2122
#EXPECT: feat_req__child__abce: parent need `feat_req__parent__abcd` does not fulfill condition `{'and': ['safety != QM', 'status == valid']}`.
2223

2324
.. feat_req:: Child requirement
@@ -26,16 +27,37 @@
2627
:status: valid
2728
:satisfies: feat_req__parent__abcd
2829

29-
3030
.. feat_req:: Parent requirement 2
3131
:id: feat_req__parent2__abcd
3232
:safety: ASIL_B
3333
:status: valid
3434

35+
.. Parent requirement has the correct safety level
3536
#EXPECT-NOT: feat_req__child2__abce: parent need `feat_req__parent2__abcd` does not fulfill condition
3637

3738
.. feat_req:: Child requirement 2
3839
:id: feat_req__child2__abce
3940
:safety: ASIL_B
4041
:status: valid
4142
:satisfies: feat_req__parent__abcd
43+
44+
.. Parent requirement does not exist
45+
#EXPECT: feat_req__child3__abce: Parent need `feat_req__parent0__abcd` not found in needs_dict.
46+
47+
.. feat_req:: Child requirement 3
48+
:id: feat_req__child3__abce
49+
:safety: ASIL_B
50+
:status: valid
51+
:satisfies: feat_req__parent0__abcd
52+
53+
.. feat_req:: Parent requirement 3
54+
:id: feat_req__parent3__abcd
55+
:status: invalid
56+
57+
.. Graph check without combined condition (no and or or)
58+
#EXPECT: comp_req__parent4__abcd: parent need `feat_req__parent3__abcd` does not fulfill condition `status == valid`.
59+
60+
.. comp_req:: Child requirement 4
61+
:id: comp_req__parent4__abcd
62+
:status: valid
63+
:satisfies: feat_req__parent3__abcd
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
..
2+
# *******************************************************************************
3+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
# *******************************************************************************
14+
#CHECK: id_contains_feature
15+
16+
.. Feature is not in the path of the RST file
17+
#EXPECT: std_wp__test__abcd.id (std_wp__test__abcd): Feature 'test' not in path
18+
19+
.. std_wp:: This is a test
20+
:id: std_wp__test__abcd
21+
22+
.. Feature is in the path of the RST file
23+
#EXPECT-NOT: Feature 'id_contains_feature' not in path
24+
25+
.. std_wp:: This is a test
26+
:id: std_wp__id_contains_feature__abce
27+
28+
.. Check if the feature is in the path of the RST file is skipped,
29+
because the id contains 4 parts
30+
#EXPECT-NOT: not in path
31+
32+
.. std_wp:: This is a test
33+
:id: std_wp__test1__test2__abce
34+
35+
.. Check if the feature is in the path of the RST file is skipped,
36+
because the requirement type is stkh_req
37+
#EXPECT-NOT: Feature 'test' not in path
38+
39+
.. stkh_req:: This is a test
40+
:id: stkh_req__test__abce

tooling/docs/_tooling/extensions/score_metamodel/tests/rst/options/test_options_extra_option.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
# *******************************************************************************
1414
#CHECK: check_extra_options
1515

16+
.. Invalid option: `safety` is not allowed
1617
#EXPECT: std_wp__test__abcd: has these extra options: `safety`.
1718

1819
.. std_wp:: This is a test
1920
:id: std_wp__test__abcd
2021
:safety: QM
2122

22-
#EXPECT-NOT: std_wp__test__abce: has these extra options
23+
.. No invalid extra options are present
24+
#EXPECT-NOT: has these extra options
2325

2426
.. std_wp:: This is a test
2527
:id: std_wp__test__abce

tooling/docs/_tooling/extensions/score_metamodel/tests/rst/options/test_options_options.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@
1313
# *******************************************************************************
1414
#CHECK: check_options
1515

16+
.. Required option: `status` is missing
1617
#EXPECT: std_wp__test__abcd: is missing required option: `status`.
1718

1819
.. std_wp:: This is a test
1920
:id: std_wp__test__abcd
2021

21-
#EXPECT-NOT: std_wp__test__abce: is missing required option: `status`.
22+
.. All required options are present
23+
#EXPECT-NOT: is missing required option
2224

2325
.. std_wp:: This is a test
2426
:id: std_wp__test__abce
2527
:status: active
28+
29+
.. Satisfies link refers to wrong requirement type
30+
#EXPECT: feat_req__abce.satisfies (['std_wp__test__abce']): does not follow pattern `^stkh_req__.*$`.
31+
32+
.. feat_req:: Child requirement
33+
:id: feat_req__abce
34+
:satisfies: std_wp__test__abce

tooling/docs/_tooling/extensions/score_metamodel/tests/test_rules_file_based.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _create_rst_file(rst_file: Path) -> str:
5555
# that refers to the given rst file.
5656
index_rst: str = f"""
5757
.. toctree::
58-
{rst_file.stem}
58+
{rst_file.relative_to(RST_DIR)}
5959
"""
6060
return index_rst
6161

@@ -70,7 +70,11 @@ def sphinx_app_setup(
7070
def _create_app(rst_file: Path) -> SphinxTestApp:
7171
### Create a SphinxTestApp instance.
7272
# The source directory is set to the temporary directory.
73-
shutil.copy(rst_file, sphinx_base_dir)
73+
# Create folder structure of rst file in the temporary directory.
74+
rst_folder = sphinx_base_dir / rst_file.parent.relative_to(RST_DIR)
75+
rst_folder.mkdir(parents=True, exist_ok=True)
76+
# Copy the rst file to the temporary directory.
77+
shutil.copy(str(rst_file), rst_folder)
7478
index_context: str = index_file(rst_file)
7579
(sphinx_base_dir / "index.rst").write_text(index_context)
7680
app: SphinxTestApp = SphinxTestApp(
@@ -174,7 +178,7 @@ def test_rst_files(
174178
"Unable to extract test data from the rst file: "
175179
f"{rst_file}. Please check the file for the correct format."
176180
)
177-
181+
print(f"RST Data: {rst_data}")
178182
app: SphinxTestApp = sphinx_app_setup(RST_DIR / rst_file)
179183
os.chdir(app.srcdir) # Change working directory to the source directory
180184

@@ -184,6 +188,7 @@ def test_rst_files(
184188

185189
# Collect the warnings
186190
warnings = app.warning.getvalue().splitlines()
191+
print(f"Warnings: {warnings}")
187192

188193
# Check if the expected warnings are present
189194
for warning_info in rst_data.warning_infos:

0 commit comments

Comments
 (0)