-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add CI step for checking redundant test patches #7126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7dfac3
Basic script to detect leftover patches
ShaharNaveh f0e5abb
Add CI step
ShaharNaveh 7bdefc5
Checkout code
ShaharNaveh 3fa7178
Merge remote-tracking branch 'upstream/main' into lint-script-patches
ShaharNaveh 9e179aa
Merge remote-tracking branch 'upstream/main' into lint-script-patches
ShaharNaveh 0da173a
coderabbit review
ShaharNaveh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -456,10 +456,17 @@ jobs: | |
| 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 | ||
|
|
||
| lint: | ||
| name: Check Rust code with clippy | ||
| name: Lint Rust & Python code | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/[email protected] | ||
| - uses: actions/[email protected] | ||
| with: | ||
| python-version: ${{ env.PYTHON_VERSION }} | ||
|
|
||
| - name: Check for redundant test patches | ||
| run: python scripts/check_redundant_patches.py | ||
|
|
||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| components: clippy | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/usr/bin/env python | ||
| import ast | ||
| import pathlib | ||
| import sys | ||
|
|
||
| ROOT = pathlib.Path(__file__).parents[1] | ||
| TEST_DIR = ROOT / "Lib" / "test" | ||
|
|
||
|
|
||
| def main(): | ||
| exit_status = 0 | ||
| for file in TEST_DIR.rglob("**/*.py"): | ||
| try: | ||
| contents = file.read_text(encoding="utf-8") | ||
| except UnicodeDecodeError: | ||
| continue | ||
|
|
||
| try: | ||
| tree = ast.parse(contents) | ||
| except SyntaxError: | ||
| continue | ||
|
|
||
| for node in ast.walk(tree): | ||
| if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): | ||
| continue | ||
|
|
||
| name = node.name | ||
| if not name.startswith("test"): | ||
| continue | ||
|
|
||
| if node.decorator_list: | ||
| continue | ||
|
|
||
| func_code = ast.unparse(node.body) | ||
| if func_code in ( | ||
| f"await super().{name}()", | ||
| f"return await super().{name}()", | ||
| f"return super().{name}()", | ||
| f"super().{name}()", | ||
| ): | ||
| exit_status += 1 | ||
| rel = file.relative_to(ROOT) | ||
| lineno = node.lineno | ||
| print( | ||
| f"{rel}:{name}:{lineno} is a test patch that can be safely removed", | ||
| file=sys.stderr, | ||
| ) | ||
| return exit_status | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| exit(main()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.