Release version 2.1.0

This commit is contained in:
Kevin Veen-Birkenbach
2025-12-08 20:15:13 +01:00
parent b9b64fed7d
commit bc3ff5b67f
11 changed files with 1401 additions and 200 deletions

View File

@@ -8,33 +8,37 @@ from unittest.mock import patch
class TestIntegrationBranchCommands(unittest.TestCase):
"""
E2E-style tests for the 'pkgmgr branch' CLI wiring.
Integration tests for the `pkgmgr branch` CLI wiring.
We do NOT call real git; instead we patch pkgmgr.branch_commands.open_branch
and verify that the CLI invokes it with the correct parameters.
These tests execute the real entry point (main.py) and mock
the high-level `open_branch` helper to ensure that argument
parsing and dispatch behave as expected.
"""
def _run_pkgmgr(self, argv: list[str]) -> None:
def _run_pkgmgr(self, extra_args: list[str]) -> None:
"""
Helper to run 'pkgmgr' via its entry module with a given argv.
Run the main entry point with the given extra args, as if called via:
pkgmgr <extra_args...>
We explicitly set sys.argv and execute main.py as __main__ using runpy.
"""
original_argv = list(sys.argv)
try:
# argv typically looks like: ["pkgmgr", "branch", ...]
sys.argv = argv
# Run the CLI entry point
runpy.run_module("pkgmgr.cli", run_name="__main__")
# argv[0] is the program name; the rest are CLI arguments.
sys.argv = ["pkgmgr"] + list(extra_args)
runpy.run_module("main", run_name="__main__")
finally:
sys.argv = original_argv
@patch("pkgmgr.branch_commands.open_branch")
@patch("pkgmgr.cli_core.commands.branch.open_branch")
def test_branch_open_with_name_and_base(self, mock_open_branch) -> None:
"""
pkgmgr branch open feature/test --base develop
should invoke open_branch(name='feature/test', base_branch='develop', cwd='.')
`pkgmgr branch open feature/test --base develop` must forward
the name and base branch to open_branch() with cwd=".".
"""
self._run_pkgmgr(
["pkgmgr", "branch", "open", "feature/test", "--base", "develop"]
["branch", "open", "feature/test", "--base", "develop"]
)
mock_open_branch.assert_called_once()
@@ -43,14 +47,16 @@ class TestIntegrationBranchCommands(unittest.TestCase):
self.assertEqual(kwargs.get("base_branch"), "develop")
self.assertEqual(kwargs.get("cwd"), ".")
@patch("pkgmgr.branch_commands.open_branch")
def test_branch_open_without_name_uses_default_base(self, mock_open_branch) -> None:
@patch("pkgmgr.cli_core.commands.branch.open_branch")
def test_branch_open_without_name_uses_default_base(
self,
mock_open_branch,
) -> None:
"""
pkgmgr branch open
should invoke open_branch(name=None, base_branch='main', cwd='.')
(the branch name will be asked interactively inside open_branch).
`pkgmgr branch open` without a name must still call open_branch(),
passing name=None and the default base branch 'main'.
"""
self._run_pkgmgr(["pkgmgr", "branch", "open"])
self._run_pkgmgr(["branch", "open"])
mock_open_branch.assert_called_once()
_, kwargs = mock_open_branch.call_args

View File

@@ -1,63 +1,100 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Integration tests for the `pkgmgr release` command.
We deliberately only test a *negative* path here, to avoid mutating
the real repositories (bumping versions, editing changelogs) during
CI runs.
The test verifies that:
- Calling `pkgmgr release` with a non-existent repository identifier
results in a non-zero exit code and a helpful error.
"""
from __future__ import annotations
import os
import runpy
import sys
import unittest
PROJECT_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..")
)
class TestIntegrationReleaseCommand(unittest.TestCase):
"""
E2E tests for `pkgmgr release`.
"""
def _run_release_expect_failure(self) -> None:
cmd_repr = "pkgmgr release patch does-not-exist-xyz"
def _run_pkgmgr(
self,
argv: list[str],
expect_success: bool,
) -> None:
"""
Run the main entry point with the given argv and assert on success/failure.
argv must include the program name as argv[0], e.g. "":
["", "release", "patch", "pkgmgr", "--preview"]
"""
cmd_repr = " ".join(argv[1:])
original_argv = list(sys.argv)
try:
sys.argv = [
"pkgmgr",
"release",
"patch",
"does-not-exist-xyz",
]
sys.argv = argv
try:
# Execute main.py as if called via `python main.py ...`
runpy.run_module("main", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else str(exc.code)
# Hier wirklich verifizieren:
assert code != 0, f"{cmd_repr!r} unexpectedly succeeded with exit code 0"
print("[TEST] pkgmgr release failed as expected")
print(f"[TEST] Command : {cmd_repr}")
print(f"[TEST] Exit code : {code}")
code = exc.code if isinstance(exc.code, int) else 1
if expect_success and code != 0:
print()
print(f"[TEST] Command : {cmd_repr}")
print(f"[TEST] Exit code : {code}")
raise AssertionError(
f"{cmd_repr!r} failed with exit code {code}. "
"Scroll up to inspect the output printed before failure."
) from exc
if not expect_success and code == 0:
print()
print(f"[TEST] Command : {cmd_repr}")
print(f"[TEST] Exit code : {code}")
raise AssertionError(
f"{cmd_repr!r} unexpectedly succeeded with exit code 0."
) from exc
else:
# Kein SystemExit -> auf jeden Fall falsch
raise AssertionError(
f"{cmd_repr!r} returned normally (expected non-zero exit)."
)
# No SystemExit: treat as success when expect_success is True,
# otherwise as a failure (we expected a non-zero exit).
if not expect_success:
raise AssertionError(
f"{cmd_repr!r} returned normally (expected non-zero exit)."
)
finally:
sys.argv = original_argv
def test_release_for_unknown_repo_fails_cleanly(self) -> None:
self._run_release_expect_failure()
"""
Releasing a non-existent repository identifier must fail
with a non-zero exit code, but without crashing the interpreter.
"""
argv = [
"",
"release",
"patch",
"does-not-exist-xyz",
]
self._run_pkgmgr(argv, expect_success=False)
def test_release_preview_for_pkgmgr_repository(self) -> None:
"""
Sanity-check the happy path for the CLI:
- Runs `pkgmgr release patch pkgmgr --preview`
- Must exit with code 0
- Uses the real configuration + repository selection
- Exercises the new --preview mode end-to-end.
"""
argv = [
"",
"release",
"patch",
"pkgmgr",
"--preview",
]
original_cwd = os.getcwd()
try:
os.chdir(PROJECT_ROOT)
self._run_pkgmgr(argv, expect_success=True)
finally:
os.chdir(original_cwd)
if __name__ == "__main__":
unittest.main()