Skip to content

Commit c2d611a

Browse files
committedSep 10, 2024
YAML linter: Add check for manual steps, remove known bad unit tests
1 parent 3f0f242 commit c2d611a

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed
 

‎scripts/tests/matter_yaml_linter.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@
1616
import os
1717
import re
1818
import sys
19+
import subprocess
1920
from pathlib import Path
2021

2122
from chiptest import AllChipToolYamlTests
2223

2324
DEFAULT_CHIP_ROOT = os.path.abspath(
2425
os.path.join(os.path.dirname(__file__), '..', '..'))
2526

26-
# TODO: These tests need to be re-written. Please see https://github.com/project-chip/connectedhomeip/issues/32620
27-
KNOWN_BAD_UNIT_TESTING = set(('Test_TC_S_2_2.yaml', 'Test_TC_S_2_3.yaml'))
28-
2927

3028
def _is_cert_test(path):
3129
return "certification" in os.path.dirname(path)
3230

3331

34-
def main():
32+
def check_unit_testing():
3533
bad_tests = set()
3634
for test in AllChipToolYamlTests(use_short_run_name=False):
3735
with open(test.run_name, "r") as f:
@@ -47,10 +45,31 @@ def main():
4745
print(f'\t{line+1}: {val}')
4846
bad_tests.add(Path(test.run_name).name)
4947

50-
if bad_tests - KNOWN_BAD_UNIT_TESTING:
48+
if bad_tests:
5149
return 1
5250
return 0
5351

5452

53+
def check_manual_steps():
54+
# Doing this on a test-by-test basis so the log message is more obvious
55+
bad_tests = set()
56+
for test in AllChipToolYamlTests(use_short_run_name=False):
57+
cmd = ['git', 'diff', 'HEAD^..HEAD', '--unified=0', '--', test.run_name]
58+
output = subprocess.check_output(cmd).decode().splitlines()
59+
user_prompt_added = [line for line in output if re.search('^\+.*UserPrompt.*', line)]
60+
user_prompt_removed = [line for line in output if re.search('^\-.*UserPrompt.*', line)]
61+
if len(user_prompt_added) > len(user_prompt_removed):
62+
print(f'Found YAML test with additional manual steps: {test.name}')
63+
if bad_tests:
64+
return 1
65+
return 0
66+
67+
68+
def main():
69+
ret = check_unit_testing()
70+
ret += check_manual_steps()
71+
return ret
72+
73+
5574
if __name__ == '__main__':
5675
sys.exit(main())

0 commit comments

Comments
 (0)
Please sign in to comment.