Files
EvoScientist/tests/test_release_script.py
T

103 lines
3.1 KiB
Python

"""Tests for scripts/release.py (loaded by path, not as a package)."""
import importlib.util
import json
from pathlib import Path
import pytest
SPEC = importlib.util.spec_from_file_location(
"release_script",
str(Path(__file__).resolve().parent.parent / "scripts" / "release.py"),
)
release = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(release)
def test_compute_next_version_bumps():
assert release.compute_next_version("0.2.2", "patch") == "0.2.3"
assert release.compute_next_version("0.2.2", "minor") == "0.3.0"
assert release.compute_next_version("0.2.2", "major") == "1.0.0"
assert release.compute_next_version("0.2.2", "0.5.1") == "0.5.1"
with pytest.raises(ValueError):
release.compute_next_version("0.2.2", "banana")
def test_extract_changelog_sections():
text = (
"# Changelog\n\n## [0.2.3] - 2026-08-12\n\n- Added foo\n- Fixed bar\n\n"
"## [0.2.2] - 2026-08-01\n\n- Old\n"
)
assert release.extract_changelog(text, "0.2.3") == "- Added foo\n- Fixed bar"
assert release.extract_changelog(text, "0.2.2") == "- Old"
assert release.extract_changelog(text, "9.9.9") is None
def test_write_checksums(tmp_path):
a = tmp_path / "a.whl"
a.write_bytes(b"aaa")
b = tmp_path / "b.tgz"
b.write_bytes(b"bbb")
dest = tmp_path / "checksums.txt"
release.write_checksums([a, b], dest)
import hashlib
lines = dest.read_text().splitlines()
assert f"{hashlib.sha256(b'aaa').hexdigest()} a.whl" in lines
assert f"{hashlib.sha256(b'bbb').hexdigest()} b.tgz" in lines
def test_release_state_resume(tmp_path):
state_file = tmp_path / "state.json"
st = release.ReleaseState(state_file)
assert not st.is_done("bump")
st.mark_done("bump")
st2 = release.ReleaseState(state_file)
assert st2.is_done("bump")
assert not st2.is_done("build")
def test_main_dry_run_makes_no_changes(tmp_path):
backend = tmp_path / "backend"
webui = tmp_path / "webui"
backend.mkdir()
webui.mkdir()
(backend / "pyproject.toml").write_text('[project]\nversion = "0.2.2"\n')
calls = []
def fake_run(cmd, **kw):
calls.append(cmd)
class R:
returncode = 0
stdout = "main" if "branch" in cmd else ""
stderr = ""
def check_returncode(self):
pass
return R()
rc = release.main(
["patch", "--webui-repo", str(webui), "--dry-run"],
run=fake_run,
repo_root=backend,
)
assert rc == 0
assert '"0.2.2"' in (backend / "pyproject.toml").read_text() # dry-run changes nothing
def test_main_requires_token_without_dry_run(tmp_path, monkeypatch):
backend = tmp_path / "backend"
webui = tmp_path / "webui"
backend.mkdir()
webui.mkdir()
(backend / "pyproject.toml").write_text('[project]\nversion = "0.2.2"\n')
monkeypatch.delenv("EVOSCIENTIST_RELEASE_TOKEN", raising=False)
rc = release.main(
["patch", "--webui-repo", str(webui)],
run=lambda *a, **k: None,
repo_root=backend,
)
assert rc == 2