Repository navigation
test: REUSE gate tests clean up on setUp failure and cover a subdirectory run - #88
Merged
Merged
Conversation
… run Two follow-ups from PR 87 review r3: P3-A: in both test classes, setUp now registers self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True) before calling _init_repo, so a half-failed setUp cannot leak the temp directory. shutil is imported at the top; the now-redundant tearDown blocks are dropped. P3-B: MainSubprocessCheck now also runs the gate with cwd set to a subdirectory of the throwaway repo and a headerless .go file at the repo root; the assertion proves exit 1 and that the summary names that file. This is the automated check for the git-root scan in main(). Mutation: swapping main()'s git-root lookup for os.getcwd() (and restoring via git checkout -- .github/scripts/reuse_gate.py) makes the new subdir test fail with exit 0 and 'REUSE gate **passed**' against an empty cwd, then the suite is green again with the original lookup restored. Signed-off-by: colton <colton@futurebuild.ai>
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.
Two follow-ups from the PR 87 review r3, neither blocking.
P3-A: temp dir cleanup runs even if
setUpraisesBoth test classes of
.github/scripts/test_reuse_gate.py(InlineHeaderCheck and MainSubprocessCheck) used to calltempfile.mkdtempinsetUpand then_init_repostraight after, with the cleanup intearDown. If_init_reporaised for any reason (for example git is missing on PATH),tearDownwould not execute and the temp directory would leak on disk.This change registers
self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True)immediately aftermkdtemp, before_init_repois called.addCleanupruns even whensetUpitself fails partway through, so the directory is gone regardless.shutilis imported at the top of the module now and the now-redundanttearDownblocks are dropped (their only job was the rmtree call).P3-B: a subdirectory run is covered
MainSubprocessChecknow also has atest_main_from_subdirectory_still_finds_root_headerless_filecase. It puts a headerless.gofile at the throwaway repo's root and runs the gate withcwdset to a subdirectory (tmp/deep/nested). The assertion is exit 1 and that the summary names the file. Without a git-root scan inmain()(for example if the lookup fell back toos.getcwd()), the empty subdirectory would produce zero missing files, the gate would printREUSE gate **passed**, exit 0, and this test would fail.Mutation proof:
reuse_gate.pymain()'s git-root lookup fromgit rev-parse --show-topleveltoos.getcwd()and run:git checkout -- .github/scripts/reuse_gate.py, rerun the suite, the same case is green again and the full 9-test run is OK:Exit tests
python3 -m unittest discover -s .github/scripts -p test_reuse_gate.py: 9 tests, OKpython3 .github/scripts/reuse_gate.pyagainst this checkout:REUSE gate **passed**., exit 0 (uses the installed reuse 6.2.0)🤖 Generated with Claude Code