-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathcheck_chipstack.py
More file actions
28 lines (20 loc) · 944 Bytes
/
check_chipstack.py
File metadata and controls
28 lines (20 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
from pathlib import Path
TARGET_DIR = Path("src/python_testing/")
# This is a linter that checks for 'except ChipStackError' key words. The idea is to avoid using
# try/except ChipStackError blocks and replace them with 'with' syntax. In case you still want to
# use try/except you have to comment '# chipstack-ok' in the same line and justify it.
def is_exception_line(line):
return ("except ChipStackError" in line) and ("# chipstack-ok" not in line)
failures = []
for py_file in TARGET_DIR.rglob("*.py"):
with open(py_file, encoding="utf-8") as f:
lines = f.readlines()
for i, line in enumerate(lines):
if is_exception_line(line):
failures.append(f"{py_file}: {i+1}: 'except ChipStackError' without # chipstack-ok -> {line.strip()}")
if failures:
print("\n".join(failures))
sys.exit(1)
else:
print("No 'except ChipStackError' found in testing Python files")