GeezerVison is showing github.com — Add CI step for checking redundant test patches (#7126) · RustPython/RustPython@64088bb
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: .github/workflows/ci.yaml +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -456,10 +456,17 @@ jobs: |
456 | 456 | 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 |
457 | 457 |
|
458 | 458 | lint: |
459 | | - name: Check Rust code with clippy |
| 459 | + name: Lint Rust & Python code |
460 | 460 | runs-on: ubuntu-latest |
461 | 461 | steps: |
462 | 462 | |
| 463 | + |
| 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 | + |
463 | 470 | - uses: dtolnay/rust-toolchain@stable |
464 | 471 | with: |
465 | 472 | components: clippy |
|
Collapse file
Copy file name to clipboard +52Lines changed: 52 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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()) |