askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
test_changelog_check.py · 1.4 KB · 44 lines
| 1 | """scripts/changelog_check.py lists commits the Unreleased section omits.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import subprocess |
| 6 | import sys |
| 7 | from pathlib import Path |
| 8 | |
| 9 | sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) |
| 10 | |
| 11 | import changelog_check # noqa: E402 |
| 12 | |
| 13 | |
| 14 | def git(repo, *args): |
| 15 | return subprocess.run( |
| 16 | ["git", "-C", str(repo), "-c", "user.name=t", "-c", "user.email=t@t", |
| 17 | "-c", "commit.gpgsign=false", "-c", "tag.gpgsign=false", *args], |
| 18 | check=True, capture_output=True, text=True, |
| 19 | ).stdout.strip() |
| 20 | |
| 21 | |
| 22 | def commit(repo, name): |
| 23 | (repo / name).write_text(name) |
| 24 | git(repo, "add", name) |
| 25 | git(repo, "commit", "-m", f"add {name}") |
| 26 | return git(repo, "rev-parse", "--short", "HEAD") |
| 27 | |
| 28 | |
| 29 | def test_reports_missing_and_passes_when_complete(tmp_path, capsys): |
| 30 | git(tmp_path, "init", "-q") |
| 31 | commit(tmp_path, "a") |
| 32 | git(tmp_path, "tag", "v1") |
| 33 | old = commit(tmp_path, "b") |
| 34 | new = commit(tmp_path, "c") |
| 35 | log = tmp_path / "CHANGELOG.md" |
| 36 | |
| 37 | # old hash is only in a released section, so it does not count |
| 38 | log.write_text(f"# Changelog\n\n## Unreleased\n\n- thing `{new}`\n\n## v1\n\n- `{old}`\n") |
| 39 | assert changelog_check.main(["--repo", str(tmp_path)]) == 1 |
| 40 | out = capsys.readouterr().out |
| 41 | assert old in out and new not in out |
| 42 | |
| 43 | log.write_text(f"# Changelog\n\n## Unreleased\n\n- `{old}` `{new}`\n\n## v1\n") |
| 44 | assert changelog_check.main(["--repo", str(tmp_path)]) == 0 |