Skip to content

Commit 42bb3a4

Browse files
authored
Add CI step for checking redundant test patches (RustPython#7126)
1 parent 16ff258 commit 42bb3a4

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

.github/workflows/ci.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,17 @@ jobs:
456456
run: python -I scripts/whats_left.py --no-default-features --features "$(sed -e 's/--[^ ]*//g' <<< "${{ env.CARGO_ARGS }}" | tr -d '[:space:]'),threading" # no jit on macOS for now
457457

458458
lint:
459-
name: Check Rust code with clippy
459+
name: Lint Rust & Python code
460460
runs-on: ubuntu-latest
461461
steps:
462462
- uses: actions/checkout@v6.0.2
463+
- uses: actions/setup-python@v6.2.0
464+
with:
465+
python-version: ${{ env.PYTHON_VERSION }}
466+
467+
- name: Check for redundant test patches
468+
run: python scripts/check_redundant_patches.py
469+
463470
- uses: dtolnay/rust-toolchain@stable
464471
with:
465472
components: clippy

scripts/check_redundant_patches.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
import ast
3+
import pathlib
4+
import sys
5+
6+
ROOT = pathlib.Path(__file__).parents[1]
7+
TEST_DIR = ROOT / "Lib" / "test"
8+
9+
10+
def main():
11+
exit_status = 0
12+
for file in TEST_DIR.rglob("**/*.py"):
13+
try:
14+
contents = file.read_text(encoding="utf-8")
15+
except UnicodeDecodeError:
16+
continue
17+
18+
try:
19+
tree = ast.parse(contents)
20+
except SyntaxError:
21+
continue
22+
23+
for node in ast.walk(tree):
24+
if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
25+
continue
26+
27+
name = node.name
28+
if not name.startswith("test"):
29+
continue
30+
31+
if node.decorator_list:
32+
continue
33+
34+
func_code = ast.unparse(node.body)
35+
if func_code in (
36+
f"await super().{name}()",
37+
f"return await super().{name}()",
38+
f"return super().{name}()",
39+
f"super().{name}()",
40+
):
41+
exit_status += 1
42+
rel = file.relative_to(ROOT)
43+
lineno = node.lineno
44+
print(
45+
f"{rel}:{name}:{lineno} is a test patch that can be safely removed",
46+
file=sys.stderr,
47+
)
48+
return exit_status
49+
50+
51+
if __name__ == "__main__":
52+
exit(main())

0 commit comments

Comments
 (0)