Files
pkgmgr/tests/unit/pkgmgr/cli/commands/test_release_publish_hook.py
Kevin Veen-Birkenbach f4339a746a
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / lint-shell (push) Has been cancelled
Mark stable commit / lint-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
executet 'ruff format --check .'
2025-12-18 14:04:44 +01:00

79 lines
2.5 KiB
Python

from __future__ import annotations
import tempfile
import unittest
from types import SimpleNamespace
from unittest.mock import patch
class TestCLIReleasePublishHook(unittest.TestCase):
def _ctx(self) -> SimpleNamespace:
# Minimal CLIContext shape used by handle_release
return SimpleNamespace(
repositories_base_dir="/tmp",
all_repositories=[],
)
def test_release_runs_publish_by_default_and_respects_tty(self) -> None:
from pkgmgr.cli.commands.release import handle_release
with tempfile.TemporaryDirectory() as td:
repo = {"directory": td}
args = SimpleNamespace(
list=False,
release_type="patch",
message=None,
preview=False,
force=False,
close=False,
no_publish=False,
)
with (
patch("pkgmgr.cli.commands.release.run_release") as m_release,
patch("pkgmgr.cli.commands.release.run_publish") as m_publish,
patch(
"pkgmgr.cli.commands.release.sys.stdin.isatty", return_value=False
),
):
handle_release(args=args, ctx=self._ctx(), selected=[repo])
m_release.assert_called_once()
m_publish.assert_called_once()
_, kwargs = m_publish.call_args
self.assertEqual(kwargs["repo"], repo)
self.assertEqual(kwargs["repo_dir"], td)
self.assertFalse(kwargs["interactive"])
self.assertFalse(kwargs["allow_prompt"])
def test_release_skips_publish_when_no_publish_flag_set(self) -> None:
from pkgmgr.cli.commands.release import handle_release
with tempfile.TemporaryDirectory() as td:
repo = {"directory": td}
args = SimpleNamespace(
list=False,
release_type="patch",
message=None,
preview=False,
force=False,
close=False,
no_publish=True,
)
with (
patch("pkgmgr.cli.commands.release.run_release") as m_release,
patch("pkgmgr.cli.commands.release.run_publish") as m_publish,
):
handle_release(args=args, ctx=self._ctx(), selected=[repo])
m_release.assert_called_once()
m_publish.assert_not_called()
if __name__ == "__main__":
unittest.main()