Files
pkgmgr/tests/integration/test_update_silent_continues.py
Kevin Veen-Birkenbach b4e0594901 style: modernise typing and clean up lint findings
Repository-wide mechanical cleanup so `ruff check src tests` has a chance
of passing; no behavioural changes.

- Add `from __future__ import annotations` where PEP 604 unions are used.
  This has to come first: pyproject declares requires-python >= 3.9, where
  `X | None` is not evaluable at runtime unless annotations are stringified.
- Replace typing.List/Dict/Tuple/Set with the builtin generics and
  Optional[X] with X | None, then drop the imports that became unused.
  The four actions/*/__init__.py files needed this by hand because ruff
  leaves unused imports in __init__.py alone (possible re-exports).
- Strip shebangs from 72 importable modules. None of them are executable
  or invoked directly; the entry points are console_scripts and runpy.
- Flatten nested `with` blocks, collapse needless-bool returns, and apply
  the remaining mechanical ruff fixes (PIE810, FLY002, PERF102, FURB192,
  RUF059, I001).
- Pass check=False explicitly to the four subprocess.run() calls that
  inspect returncode themselves. That is the existing default.

Two rewrites are visible to mocks, so their tests move with them:
subprocess.run(stdout=PIPE, stderr=PIPE) became capture_output=True, and
open(path, "r", ...) lost the redundant mode.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 16:47:13 +02:00

118 lines
4.4 KiB
Python

from __future__ import annotations
import unittest
from unittest.mock import patch
from pkgmgr.actions.update.manager import UpdateManager
class TestUpdateSilentContinues(unittest.TestCase):
def test_update_continues_on_failures_and_silent_controls_exit_code(self) -> None:
"""
Integration test for UpdateManager:
- pull failure on repo A should not stop repo B/C
- install failure on repo B should not stop repo C
- without silent -> SystemExit(1) at end if any failures
- with silent -> no SystemExit even if there are failures
"""
repos = [
{"provider": "github", "account": "example", "repository": "repo-a"},
{"provider": "github", "account": "example", "repository": "repo-b"},
{"provider": "github", "account": "example", "repository": "repo-c"},
]
# We patch the internal calls used by UpdateManager:
# - pull_with_verification is called once per repo
# - install_repos is called once per repo that successfully pulled
#
# We simulate:
# repo-a: pull fails
# repo-b: pull ok, install fails
# repo-c: pull ok, install ok
pull_calls = []
install_calls = []
def pull_side_effect(selected_repos, *_args, **_kwargs):
# selected_repos is a list with exactly one repo in our implementation.
repo = selected_repos[0]
pull_calls.append(repo["repository"])
if repo["repository"] == "repo-a":
raise SystemExit(2)
def install_side_effect(selected_repos, *_args, **kwargs):
repo = selected_repos[0]
install_calls.append(
(repo["repository"], kwargs.get("silent"), kwargs.get("emit_summary"))
)
if repo["repository"] == "repo-b":
raise SystemExit(3)
# Patch at the exact import locations used inside UpdateManager.run()
with (
patch(
"pkgmgr.actions.repository.pull.pull_with_verification",
side_effect=pull_side_effect,
),
patch(
"pkgmgr.actions.install.install_repos", side_effect=install_side_effect
),
):
# 1) silent=True: should NOT raise (even though failures happened)
UpdateManager().run(
selected_repos=repos,
repositories_base_dir="/tmp/repos",
bin_dir="/tmp/bin",
all_repos=repos,
no_verification=True,
system_update=False,
preview=True,
quiet=True,
update_dependencies=False,
clone_mode="shallow",
silent=True,
force_update=True,
)
# Ensure it tried all pulls, and installs happened for B and C only.
self.assertEqual(pull_calls, ["repo-a", "repo-b", "repo-c"])
self.assertEqual(
[r for r, _silent, _emit in install_calls], ["repo-b", "repo-c"]
)
# Ensure UpdateManager suppressed install summary spam by passing emit_summary=False.
for _repo_name, _silent, emit_summary in install_calls:
self.assertFalse(emit_summary)
# Reset tracking for the non-silent run
pull_calls.clear()
install_calls.clear()
# 2) silent=False: should raise SystemExit(1) at end due to failures
with self.assertRaises(SystemExit) as cm:
UpdateManager().run(
selected_repos=repos,
repositories_base_dir="/tmp/repos",
bin_dir="/tmp/bin",
all_repos=repos,
no_verification=True,
system_update=False,
preview=True,
quiet=True,
update_dependencies=False,
clone_mode="shallow",
silent=False,
force_update=True,
)
self.assertEqual(cm.exception.code, 1)
# Still must have processed all repos (continue-on-failure behavior).
self.assertEqual(pull_calls, ["repo-a", "repo-b", "repo-c"])
self.assertEqual(
[r for r, _silent, _emit in install_calls], ["repo-b", "repo-c"]
)
if __name__ == "__main__":
unittest.main()