File: test_version.py

package info (click to toggle)
python-logistro 2.0.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 204 kB
  • sloc: python: 350; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import importlib.metadata
import re
import pathlib

import logistro


def test_version_matches_debian_package(project_root):
    """
    Test that logistro version metadata matches the Debian package version.

    This is a check that the maintainer remembered to update the version in debian/patches/pyproject-add-version.diff when releasing a new version.
    The patch is needed becaue upstream depends on setuptools-git-versioning, which is not available in Debian.
    """
    # Get version from python
    version_from_python = importlib.metadata.version("logistro")

    # Read debian/changelog and extract the version
    if project_root is not None:
        changelog_path = pathlib.Path(project_root) / "debian" / "changelog"
    else:
        changelog_path = pathlib.Path(__file__).parent.parent / "debian" / "changelog"
    changelog_content = changelog_path.read_text()
    match = re.search(r"python-logistro \(([^)]+)\)", changelog_content)
    assert match, "Could not find version in debian/changelog"
    version_from_debian, _ = match.group(1).split("+")

    # Compare the two versions
    assert version_from_python == version_from_debian, (
        f"Version in pyproject.toml ({version_from_python}) does not match "
        f"Debian version ({version_from_debian}). Please update debian/patches/pyproject-add-version.diff to set the correct version."
    )