40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Test that version.py matches pyproject.toml version.
|
|
|
|
Catches: version bump in one place but not the other.
|
|
"""
|
|
|
|
import os
|
|
import re
|
|
import tomllib
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
def _read_version_py():
|
|
path = os.path.join(ROOT, "src", "version.py")
|
|
with open(path) as f:
|
|
content = f.read()
|
|
m = re.search(r"__version__\s*=\s*'([^']+)'", content)
|
|
return m.group(1) if m else None
|
|
|
|
|
|
def _read_pyproject_version():
|
|
path = os.path.join(ROOT, "pyproject.toml")
|
|
with open(path, "rb") as f:
|
|
data = tomllib.load(f)
|
|
return data.get("project", {}).get("version")
|
|
|
|
|
|
class TestVersionConsistency:
|
|
def test_version_py_matches_pyproject(self):
|
|
v_py = _read_version_py()
|
|
v_proj = _read_pyproject_version()
|
|
assert v_py is not None, "Could not read __version__ from src/version.py"
|
|
assert v_proj is not None, "Could not read version from pyproject.toml"
|
|
assert v_py == v_proj, (
|
|
f"Version mismatch: version.py={v_py}, pyproject.toml={v_proj}"
|
|
)
|
|
|
|
def test_version_is_semver(self):
|
|
v = _read_version_py()
|
|
assert re.match(r"^\d+\.\d+\.\d+", v), f"Version '{v}' is not semver" |