Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/pr_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ def main(argv: list[str] | None = None) -> int:
for flag in ("--repo", "--checkout", "--min-age-hours"):
pre.add_argument(flag)
if pre.parse_known_args(args)[0].first == "cleanup":
sys.modules.setdefault("pr_review", sys.modules[__name__])
import pr_cleanup

rest = list(args)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_pr_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,22 @@ def test_a_develop_held_by_another_worktree_stops_the_primary_leaving(self) -> N
self.assertIn(CLEANUP_BRANCH, self.branches())


class TestCleanupLoadsOneGate(unittest.TestCase):
def test_the_gate_run_as_a_script_is_not_imported_again_by_cleanup(self) -> None:
"""`pr_review.py cleanup` runs the gate as `__main__`, and `pr_cleanup` must reuse it."""
script = Path(__file__).resolve().parent.parent / "scripts" / "pr_review.py"
result = subprocess.run(
[sys.executable, "-X", "importtime", str(script), "cleanup", "--help"],
capture_output=True,
text=True,
encoding="utf-8",
check=True,
)
imported = [ln.rpartition("|")[2].strip() for ln in result.stderr.splitlines()]
self.assertIn("pr_cleanup", imported)
self.assertNotIn("pr_review", imported)


class TestCleanupOriginParsing(unittest.TestCase):
def test_https_and_ssh_forms_name_the_repository_case_insensitively(self) -> None:
for url in (
Expand Down
Loading