|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Policy scenarios for prune_releases.py. Run: python3 test_prune_releases.py |
| 3 | +
|
| 4 | +Each case: (pushed_tag, existing_release_tags, tags_that_must_be_deleted). |
| 5 | +""" |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | +SCRIPT = Path(__file__).with_name("prune_releases.py") |
| 11 | + |
| 12 | +CASES = [ |
| 13 | + # patch replaces its whole X.Y line |
| 14 | + ("v1.2.3", "v1.2.1 v1.2.2 v1.2.3 v1.3.0", "v1.2.1 v1.2.2"), |
| 15 | + # minor is additive |
| 16 | + ("v1.3.0", "v1.2.3 v1.3.0", ""), |
| 17 | + # patch removes the .0 of its line too |
| 18 | + ("v1.3.1", "v1.2.3 v1.3.0 v1.3.1", "v1.3.0"), |
| 19 | + # major keeps only the previous major's top minor line |
| 20 | + ("v2.0.0", "v1.2.3 v1.3.1 v2.0.0", "v1.2.3"), |
| 21 | + # each previous major keeps its own top minor line |
| 22 | + ("v3.0.0", "v1.3.1 v2.5.2 v3.0.0", ""), |
| 23 | + ("v2.0.0", "v1.1.5 v1.2.0 v1.3.1 v2.0.0", "v1.1.5 v1.2.0"), |
| 24 | + # only one RC survives; stable untouched by a new RC |
| 25 | + ("v0.0.2-rc.3", "v0.0.1 v0.0.2-rc.1 v0.0.2-rc.2 v0.0.2-rc.3", "v0.0.2-rc.1 v0.0.2-rc.2"), |
| 26 | + ("v1.4.0-rc", "v1.2.3 v1.3.1 v1.4.0-rc", ""), |
| 27 | + ("v0.0.2-rc", "v0.0.2-rc.1 v0.0.2-rc", "v0.0.2-rc.1"), |
| 28 | + # a stable release clears all RCs (and its own lower-patch line members) |
| 29 | + ("v0.0.2", "v0.0.1 v0.0.2-rc.3 v0.0.2", "v0.0.1 v0.0.2-rc.3"), |
| 30 | +] |
| 31 | + |
| 32 | + |
| 33 | +def run(current, existing): |
| 34 | + out = subprocess.run( |
| 35 | + [sys.executable, str(SCRIPT), current], |
| 36 | + input="\n".join(existing.split()), |
| 37 | + capture_output=True, text=True, check=True, |
| 38 | + ).stdout |
| 39 | + return " ".join(sorted(t for t in out.split() if t)) |
| 40 | + |
| 41 | + |
| 42 | +def main(): |
| 43 | + failures = 0 |
| 44 | + for current, existing, expected in CASES: |
| 45 | + got = run(current, existing) |
| 46 | + want = " ".join(sorted(expected.split())) |
| 47 | + ok = got == want |
| 48 | + failures += not ok |
| 49 | + print(f"{'PASS' if ok else 'FAIL'} push {current:14s} del:[{got}]" |
| 50 | + + ("" if ok else f" expected:[{want}]")) |
| 51 | + if failures: |
| 52 | + print(f"\n{failures} failure(s)") |
| 53 | + sys.exit(1) |
| 54 | + print(f"\nall {len(CASES)} scenarios passed") |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + main() |
0 commit comments