test(tools): add a pytest suite for check_patches.py#16
Merged
Conversation
tools/check_patches.py gates every PR on patch-set integrity, but the linter itself had no tests. A regression in it could silently start passing bad patches, which is the one thing it exists to prevent. Add tools/tests/test_check_patches.py: each test builds a small fixture patch-set in a temp directory and asserts a given check fails on exactly the violation it targets, with a clean set passing every check. Covers all six checks with a pass case and a fail case each: - series-sync: missing-from-series, extra-in-series (no backing file), duplicate entry, wrong order. - numbering: gap, duplicate number, non-NNNN-*.patch name. - single-surface: a patch touching two files (two diff --git headers). - well-formed: a patch missing a hunk, and one missing file headers. - uxr-only-switches: an added non-uxr HasSwitch(...). - no-brand-literals: an added quoted brand string literal (plus a check that a brand token inside a // comment is allowed). To let the checks run against a fixture directory, thread a patches_dir argument through the check functions and add a run_checks(patches_dir) seam plus a --patches-dir flag. The default resolves to patches/ exactly as before, so behaviour is unchanged. Wire pytest tools/tests into the patch-integrity CI job. Closes tiliondev#11
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
tools/check_patches.pygates every PR on patch-set integrity, but the linter itself had no tests. A regression in it could silently start passing bad patches — the one thing it exists to prevent. This PR adds a focused test suite and gates it in CI.Approach
Each test builds a small fixture patch-set in a temp directory, then asserts that a given check fails on exactly the violation it targets, and that a clean set passes every check. The fixtures are generated by two helpers (
make_patch,write_set) so each case perturbs a single property.Coverage
Every check has a pass case and a fail case:
series-syncnumberingNNNN-*.patchnamesingle-surfacediff --git)well-formeduxr-only-switchesuxr-HasSwitch(...)no-brand-literals//comment is allowed)Refactor (the test seam)
The checks previously read the patch directory from a module global. This threads a
patches_dirargument through the check functions and adds:run_checks(patches_dir)— runs all checks against a given directory and returns theReport; this is what the tests call.--patches-dirCLI flag.The default still resolves to
patches/, sopython tools/check_patches.pybehaves exactly as before.CI
Runs
pytest tools/testsin the existingpatch-integrityjob.Verification
Closes #11