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>
This commit is contained in:
@@ -10,6 +10,7 @@ def run(cmd, *, cwd=None, env=None, shell=False) -> str:
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False,
|
||||
)
|
||||
|
||||
print("----- BEGIN COMMAND -----")
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Integration tests for the `pkgmgr config` command.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Integration tests for the `pkgmgr make` command.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
E2E test to inspect the Nix environment and build the pkgmgr flake
|
||||
in *every* distro container.
|
||||
@@ -36,6 +34,7 @@ def _run_cmd(cmd: list[str]) -> subprocess.CompletedProcess:
|
||||
cmd,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
)
|
||||
print("[STDOUT]\n", proc.stdout)
|
||||
print("[STDERR]\n", proc.stderr)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
End-to-end tests for the `pkgmgr path` command.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
End-to-end style integration tests for the `pkgmgr release` CLI command.
|
||||
|
||||
@@ -149,9 +147,12 @@ class TestIntegrationReleaseCommand(unittest.TestCase):
|
||||
try:
|
||||
sys.argv = ["pkgmgr", "release", "--help"]
|
||||
# argparse will call sys.exit(), so we expect a SystemExit here.
|
||||
with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf):
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
runpy.run_module("pkgmgr", run_name="__main__")
|
||||
with (
|
||||
contextlib.redirect_stdout(buf),
|
||||
contextlib.redirect_stderr(buf),
|
||||
self.assertRaises(SystemExit) as cm,
|
||||
):
|
||||
runpy.run_module("pkgmgr", run_name="__main__")
|
||||
finally:
|
||||
sys.argv = original_argv
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Integration tests for the "tools" commands:
|
||||
|
||||
|
||||
@@ -15,10 +15,9 @@ from __future__ import annotations
|
||||
import runpy
|
||||
import sys
|
||||
import unittest
|
||||
from typing import List
|
||||
|
||||
|
||||
def _run_main(argv: List[str]) -> None:
|
||||
def _run_main(argv: list[str]) -> None:
|
||||
"""
|
||||
Helper to run main.py with the given argv.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
End-to-end tests for the `pkgmgr version` command.
|
||||
|
||||
@@ -25,7 +23,6 @@ import os
|
||||
import runpy
|
||||
import sys
|
||||
import unittest
|
||||
from typing import List
|
||||
|
||||
from pkgmgr.core.config.load import load_config
|
||||
|
||||
@@ -54,7 +51,7 @@ def _load_pkgmgr_repo_dir() -> str:
|
||||
directories = cfg.get("directories", {})
|
||||
base_repos_dir = os.path.expanduser(directories.get("repositories", ""))
|
||||
|
||||
candidates: List[dict] = cfg.get("repositories", []) or []
|
||||
candidates: list[dict] = cfg.get("repositories", []) or []
|
||||
for repo in candidates:
|
||||
repo_name = (repo.get("repository") or "").strip()
|
||||
alias = (repo.get("alias") or "").strip()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Integration tests for the `pkgmgr branch` CLI wiring.
|
||||
|
||||
|
||||
@@ -67,51 +67,53 @@ class ConfigDefaultsIntegrationTest(unittest.TestCase):
|
||||
# Provide fake pkgmgr module so your functions resolve pkg_root correctly
|
||||
fake_pkgmgr = types.SimpleNamespace(__file__=str(pkg_root / "__init__.py"))
|
||||
|
||||
with patch.dict(sys.modules, {"pkgmgr": fake_pkgmgr}):
|
||||
with patch.dict(os.environ, {"HOME": str(home)}):
|
||||
# A) load_config should fall back to <pkg_root>/config/defaults.yaml
|
||||
merged = load_config(user_config_path)
|
||||
with (
|
||||
patch.dict(sys.modules, {"pkgmgr": fake_pkgmgr}),
|
||||
patch.dict(os.environ, {"HOME": str(home)}),
|
||||
):
|
||||
# A) load_config should fall back to <pkg_root>/config/defaults.yaml
|
||||
merged = load_config(user_config_path)
|
||||
|
||||
self.assertEqual(
|
||||
merged["directories"]["repositories"], "/opt/Repositories"
|
||||
)
|
||||
self.assertEqual(
|
||||
merged["directories"]["binaries"], "/usr/local/bin"
|
||||
)
|
||||
self.assertEqual(
|
||||
merged["directories"]["repositories"], "/opt/Repositories"
|
||||
)
|
||||
self.assertEqual(
|
||||
merged["directories"]["binaries"], "/usr/local/bin"
|
||||
)
|
||||
|
||||
# user-only key must still exist (user config merges over defaults)
|
||||
self.assertEqual(merged["directories"]["user_only"], "/home/user")
|
||||
# user-only key must still exist (user config merges over defaults)
|
||||
self.assertEqual(merged["directories"]["user_only"], "/home/user")
|
||||
|
||||
self.assertIn("repositories", merged)
|
||||
self.assertTrue(
|
||||
any(
|
||||
r.get("provider") == "github"
|
||||
and r.get("account") == "acme"
|
||||
and r.get("repository") == "demo"
|
||||
for r in merged["repositories"]
|
||||
)
|
||||
self.assertIn("repositories", merged)
|
||||
self.assertTrue(
|
||||
any(
|
||||
r.get("provider") == "github"
|
||||
and r.get("account") == "acme"
|
||||
and r.get("repository") == "demo"
|
||||
for r in merged["repositories"]
|
||||
)
|
||||
)
|
||||
|
||||
# B) update_default_configs should copy defaults.yaml to ~/.config/pkgmgr/
|
||||
before_config_yaml = (user_cfg_dir / "config.yaml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
# B) update_default_configs should copy defaults.yaml to ~/.config/pkgmgr/
|
||||
before_config_yaml = (user_cfg_dir / "config.yaml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
config_cmd._update_default_configs(user_config_path)
|
||||
config_cmd._update_default_configs(user_config_path)
|
||||
|
||||
self.assertTrue((user_cfg_dir / "defaults.yaml").is_file())
|
||||
copied_defaults = yaml.safe_load(
|
||||
(user_cfg_dir / "defaults.yaml").read_text(encoding="utf-8")
|
||||
)
|
||||
self.assertEqual(
|
||||
copied_defaults["directories"]["repositories"],
|
||||
"/opt/Repositories",
|
||||
)
|
||||
self.assertTrue((user_cfg_dir / "defaults.yaml").is_file())
|
||||
copied_defaults = yaml.safe_load(
|
||||
(user_cfg_dir / "defaults.yaml").read_text(encoding="utf-8")
|
||||
)
|
||||
self.assertEqual(
|
||||
copied_defaults["directories"]["repositories"],
|
||||
"/opt/Repositories",
|
||||
)
|
||||
|
||||
after_config_yaml = (user_cfg_dir / "config.yaml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
self.assertEqual(after_config_yaml, before_config_yaml)
|
||||
after_config_yaml = (user_cfg_dir / "config.yaml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
self.assertEqual(after_config_yaml, before_config_yaml)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -134,9 +132,7 @@ class TestInstallReposIntegration(unittest.TestCase):
|
||||
Make _ensure_repo_dir() believe that the repo directories
|
||||
already exist so that it does not attempt cloning.
|
||||
"""
|
||||
if path in (repo_system_dir, repo_nix_dir):
|
||||
return True
|
||||
return False
|
||||
return path in (repo_system_dir, repo_nix_dir)
|
||||
|
||||
mock_resolve.side_effect = fake_resolve
|
||||
mock_exists_install.side_effect = fake_exists_install
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
CLI integration tests for `pkgmgr mirror`.
|
||||
|
||||
@@ -21,7 +19,6 @@ import runpy
|
||||
import sys
|
||||
import unittest
|
||||
from contextlib import ExitStack, redirect_stderr, redirect_stdout
|
||||
from typing import Dict, List, Optional
|
||||
from unittest.mock import MagicMock, PropertyMock, patch
|
||||
|
||||
|
||||
@@ -29,7 +26,7 @@ class TestIntegrationMirrorCommands(unittest.TestCase):
|
||||
"""Integration tests for `pkgmgr mirror` commands."""
|
||||
|
||||
def _run_pkgmgr(
|
||||
self, args: List[str], extra_env: Optional[Dict[str, str]] = None
|
||||
self, args: list[str], extra_env: dict[str, str] | None = None
|
||||
) -> str:
|
||||
"""Execute pkgmgr with the given arguments and return captured output."""
|
||||
original_argv = list(sys.argv)
|
||||
@@ -151,8 +148,7 @@ class TestIntegrationMirrorCommands(unittest.TestCase):
|
||||
code = exc.code if isinstance(exc.code, int) else None
|
||||
if code not in (0, None):
|
||||
raise AssertionError(
|
||||
"%r failed with exit code %r.\n\nOutput:\n%s"
|
||||
% (cmd_repr, exc.code, buffer.getvalue())
|
||||
f"{cmd_repr!r} failed with exit code {exc.code!r}.\n\nOutput:\n{buffer.getvalue()}"
|
||||
)
|
||||
|
||||
return buffer.getvalue()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Integration test for mirror probing + provisioning after refactor.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Integration tests for recursive capability resolution and installer shadowing.
|
||||
|
||||
@@ -17,7 +15,6 @@ import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
from collections.abc import Sequence
|
||||
from typing import List, Tuple
|
||||
from unittest.mock import patch
|
||||
|
||||
import pkgmgr.actions.install as install_mod
|
||||
@@ -29,7 +26,7 @@ from pkgmgr.actions.install.installers.os_packages.arch_pkgbuild import (
|
||||
)
|
||||
from pkgmgr.actions.install.installers.python import PythonInstaller
|
||||
|
||||
InstallerSpec = Tuple[str, object]
|
||||
InstallerSpec = tuple[str, object]
|
||||
|
||||
|
||||
class TestRecursiveCapabilitiesIntegration(unittest.TestCase):
|
||||
@@ -54,7 +51,7 @@ class TestRecursiveCapabilitiesIntegration(unittest.TestCase):
|
||||
repo_dir: str,
|
||||
installers: Sequence[InstallerSpec],
|
||||
selected_repos=None,
|
||||
) -> List[str]:
|
||||
) -> list[str]:
|
||||
"""
|
||||
Run install_repos() with a custom INSTALLERS list and capture which
|
||||
installer labels actually run.
|
||||
@@ -69,7 +66,7 @@ class TestRecursiveCapabilitiesIntegration(unittest.TestCase):
|
||||
else:
|
||||
all_repos = selected_repos
|
||||
|
||||
called_installers: List[str] = []
|
||||
called_installers: list[str] = []
|
||||
|
||||
patched_installers = []
|
||||
for label, inst in installers:
|
||||
|
||||
@@ -21,62 +21,46 @@ class TestTokenResolverIntegration(unittest.TestCase):
|
||||
|
||||
resolver = TokenResolver()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 1) ENV: empty
|
||||
# ------------------------------------------------------------------
|
||||
with patch.dict("os.environ", {}, clear=True):
|
||||
# ------------------------------------------------------------------
|
||||
# 2) GH CLI is available
|
||||
# ------------------------------------------------------------------
|
||||
with patch(
|
||||
def validate_side_effect(
|
||||
provider_kind: str,
|
||||
host: str,
|
||||
token: str,
|
||||
) -> bool:
|
||||
return False # gh + keyring invalid
|
||||
|
||||
with (
|
||||
patch.dict("os.environ", {}, clear=True),
|
||||
patch(
|
||||
"pkgmgr.core.credentials.providers.gh.shutil.which",
|
||||
return_value="/usr/bin/gh",
|
||||
):
|
||||
with patch(
|
||||
"pkgmgr.core.credentials.providers.gh.subprocess.check_output",
|
||||
return_value="gh-invalid-token\n",
|
||||
):
|
||||
# ------------------------------------------------------------------
|
||||
# 3) Keyring returns an existing (invalid) token
|
||||
# ------------------------------------------------------------------
|
||||
with patch(
|
||||
"pkgmgr.core.credentials.providers.keyring._import_keyring"
|
||||
) as mock_import_keyring:
|
||||
mock_keyring = mock_import_keyring.return_value
|
||||
mock_keyring.get_password.return_value = "keyring-invalid-token"
|
||||
),
|
||||
patch(
|
||||
"pkgmgr.core.credentials.providers.gh.subprocess.check_output",
|
||||
return_value="gh-invalid-token\n",
|
||||
),
|
||||
patch(
|
||||
"pkgmgr.core.credentials.providers.keyring._import_keyring"
|
||||
) as mock_import_keyring,
|
||||
patch(
|
||||
"pkgmgr.core.credentials.providers.prompt.sys.stdin.isatty",
|
||||
return_value=True,
|
||||
),
|
||||
patch(
|
||||
"pkgmgr.core.credentials.providers.prompt.getpass",
|
||||
return_value="new-valid-token",
|
||||
),
|
||||
patch(
|
||||
"pkgmgr.core.credentials.resolver.validate_token",
|
||||
side_effect=validate_side_effect,
|
||||
) as validate_mock,
|
||||
):
|
||||
mock_keyring = mock_import_keyring.return_value
|
||||
mock_keyring.get_password.return_value = "keyring-invalid-token"
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 4) Prompt is allowed and returns a NEW token
|
||||
# ------------------------------------------------------------------
|
||||
with patch(
|
||||
"pkgmgr.core.credentials.providers.prompt.sys.stdin.isatty",
|
||||
return_value=True,
|
||||
):
|
||||
with patch(
|
||||
"pkgmgr.core.credentials.providers.prompt.getpass",
|
||||
return_value="new-valid-token",
|
||||
):
|
||||
# ------------------------------------------------------------------
|
||||
# 5) Validation logic:
|
||||
# - gh token invalid
|
||||
# - keyring token invalid
|
||||
# - prompt token is NOT validated (by design)
|
||||
# ------------------------------------------------------------------
|
||||
def validate_side_effect(
|
||||
provider_kind: str,
|
||||
host: str,
|
||||
token: str,
|
||||
) -> bool:
|
||||
return False # gh + keyring invalid
|
||||
|
||||
with patch(
|
||||
"pkgmgr.core.credentials.resolver.validate_token",
|
||||
side_effect=validate_side_effect,
|
||||
) as validate_mock:
|
||||
result = resolver.get_token(
|
||||
provider_kind="github",
|
||||
host="github.com",
|
||||
)
|
||||
result = resolver.get_token(
|
||||
provider_kind="github",
|
||||
host="github.com",
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Assertions
|
||||
@@ -93,7 +77,7 @@ class TestTokenResolverIntegration(unittest.TestCase):
|
||||
|
||||
# Keyring must be overwritten with the new token
|
||||
mock_keyring.set_password.assert_called_once()
|
||||
service, username, stored_token = mock_keyring.set_password.call_args.args
|
||||
_service, _username, stored_token = mock_keyring.set_password.call_args.args
|
||||
self.assertEqual(stored_token, "new-valid-token")
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -7,14 +7,14 @@ import tempfile
|
||||
import types
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
from pkgmgr.actions.mirror.setup_cmd import setup_mirrors
|
||||
from pkgmgr.actions.mirror.visibility_cmd import set_mirror_visibility
|
||||
from pkgmgr.core.remote_provisioning.types import RepoSpec
|
||||
|
||||
Repository = Dict[str, Any]
|
||||
Repository = dict[str, Any]
|
||||
|
||||
|
||||
class _FakeRegistry:
|
||||
@@ -45,13 +45,13 @@ class FakeProvider:
|
||||
|
||||
def __init__(self) -> None:
|
||||
# maps (host, owner, name) -> private(bool)
|
||||
self.privacy: Dict[Tuple[str, str, str], bool] = {}
|
||||
self.calls: List[Tuple[str, Any]] = []
|
||||
self.privacy: dict[tuple[str, str, str], bool] = {}
|
||||
self.calls: list[tuple[str, Any]] = []
|
||||
|
||||
def can_handle(self, host: str) -> bool:
|
||||
return True
|
||||
|
||||
def _candidate_hosts(self, host: str) -> List[str]:
|
||||
def _candidate_hosts(self, host: str) -> list[str]:
|
||||
"""
|
||||
Be tolerant against host normalization differences:
|
||||
- may contain scheme (https://...)
|
||||
@@ -75,7 +75,7 @@ class FakeProvider:
|
||||
candidates.append(c.split(":", 1)[0])
|
||||
|
||||
# de-dup
|
||||
out: List[str] = []
|
||||
out: list[str] = []
|
||||
for c in candidates:
|
||||
if c not in out:
|
||||
out.append(c)
|
||||
@@ -94,7 +94,7 @@ class FakeProvider:
|
||||
self.privacy[(spec.host, spec.owner, spec.name)] = bool(spec.private)
|
||||
return types.SimpleNamespace(status="created", message="created", url=None)
|
||||
|
||||
def get_repo_private(self, token: str, spec: RepoSpec) -> Optional[bool]:
|
||||
def get_repo_private(self, token: str, spec: RepoSpec) -> bool | None:
|
||||
self.calls.append(("get_repo_private", (token, spec)))
|
||||
for h in self._candidate_hosts(spec.host):
|
||||
key = (h, spec.owner, spec.name)
|
||||
@@ -113,7 +113,7 @@ class FakeProvider:
|
||||
self.privacy[(spec.host, spec.owner, spec.name)] = bool(private)
|
||||
|
||||
|
||||
def _mk_ctx(*, identifier: str, repo_dir: str, mirrors: Dict[str, str]) -> Any:
|
||||
def _mk_ctx(*, identifier: str, repo_dir: str, mirrors: dict[str, str]) -> Any:
|
||||
return types.SimpleNamespace(
|
||||
identifier=identifier,
|
||||
repo_dir=repo_dir,
|
||||
|
||||
@@ -54,9 +54,11 @@ class TestOpenBranch(unittest.TestCase):
|
||||
push_upstream.assert_called_once_with("origin", "auto-branch", cwd=".")
|
||||
|
||||
def test_open_branch_rejects_empty_name(self) -> None:
|
||||
with patch("builtins.input", return_value=""):
|
||||
with self.assertRaises(RuntimeError):
|
||||
open_branch(None)
|
||||
with (
|
||||
patch("builtins.input", return_value=""),
|
||||
self.assertRaises(RuntimeError),
|
||||
):
|
||||
open_branch(None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -87,9 +87,11 @@ class TestDownloadCodeScanning(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_errors_when_gh_missing(self) -> None:
|
||||
with mock.patch("pkgmgr.actions.code_scanning.shutil.which", return_value=None):
|
||||
with self.assertRaises(CodeScanningError):
|
||||
download_code_scanning(output_dir="/tmp/should-not-be-created")
|
||||
with (
|
||||
mock.patch("pkgmgr.actions.code_scanning.shutil.which", return_value=None),
|
||||
self.assertRaises(CodeScanningError),
|
||||
):
|
||||
download_code_scanning(output_dir="/tmp/should-not-be-created")
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -18,7 +18,7 @@ class FakeRunner:
|
||||
- Generic runner.run(ctx, cmd, allow_failure=...)
|
||||
"""
|
||||
|
||||
def __init__(self, mapping: Optional[dict[str, Any]] = None, default: Any = None):
|
||||
def __init__(self, mapping: dict[str, Any] | None = None, default: Any = None):
|
||||
self.mapping = mapping or {}
|
||||
self.default = default if default is not None else FakeRunResult(0, "", "")
|
||||
self.calls: list[tuple[Any, str, bool]] = []
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Unit tests for NixFlakeInstaller using unittest (no pytest).
|
||||
|
||||
@@ -19,7 +17,6 @@ import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from typing import List
|
||||
from unittest.mock import patch
|
||||
|
||||
from pkgmgr.actions.install.installers.nix import NixFlakeInstaller
|
||||
@@ -73,8 +70,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
|
||||
which_patch.return_value = "/usr/bin/nix"
|
||||
|
||||
@staticmethod
|
||||
def _install_cmds_from_calls(call_args_list) -> List[str]:
|
||||
cmds: List[str] = []
|
||||
def _install_cmds_from_calls(call_args_list) -> list[str]:
|
||||
cmds: list[str] = []
|
||||
for c in call_args_list:
|
||||
if not c.args:
|
||||
continue
|
||||
|
||||
@@ -50,7 +50,6 @@ class TestMakefileInstaller(unittest.TestCase):
|
||||
# Ensure we checked the Makefile and then called make install.
|
||||
mock_file.assert_called_once_with(
|
||||
os.path.join(self.ctx.repo_dir, "Makefile"),
|
||||
"r",
|
||||
encoding="utf-8",
|
||||
errors="ignore",
|
||||
)
|
||||
@@ -77,7 +76,6 @@ class TestMakefileInstaller(unittest.TestCase):
|
||||
# We should have read the Makefile, but not called run_command().
|
||||
mock_file.assert_called_once_with(
|
||||
os.path.join(self.ctx.repo_dir, "Makefile"),
|
||||
"r",
|
||||
encoding="utf-8",
|
||||
errors="ignore",
|
||||
)
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import unittest
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from pkgmgr.actions.install import install_repos
|
||||
|
||||
Repository = Dict[str, Any]
|
||||
Repository = dict[str, Any]
|
||||
|
||||
|
||||
class TestInstallReposOrchestration(unittest.TestCase):
|
||||
@@ -27,7 +25,7 @@ class TestInstallReposOrchestration(unittest.TestCase):
|
||||
"alias": "repo-two",
|
||||
"verified": {"gpg_keys": ["FAKEKEY"]},
|
||||
}
|
||||
self.all_repos: List[Repository] = [self.repo1, self.repo2]
|
||||
self.all_repos: list[Repository] = [self.repo1, self.repo2]
|
||||
|
||||
@patch("pkgmgr.actions.install.InstallationPipeline")
|
||||
@patch("pkgmgr.actions.install.clone_repos")
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
@@ -61,13 +59,7 @@ class TestMirrorIO(unittest.TestCase):
|
||||
p = os.path.join(tmpdir, "MIRRORS")
|
||||
with open(p, "w", encoding="utf-8") as fh:
|
||||
fh.write(
|
||||
"\n".join(
|
||||
[
|
||||
"https://github.com/alice/repo1",
|
||||
"https://github.com/alice/repo2",
|
||||
"ssh://git@git.veen.world:2201/alice/repo3.git",
|
||||
]
|
||||
)
|
||||
"https://github.com/alice/repo1\nhttps://github.com/alice/repo2\nssh://git@git.veen.world:2201/alice/repo3.git"
|
||||
+ "\n"
|
||||
)
|
||||
|
||||
@@ -99,7 +91,7 @@ class TestMirrorIO(unittest.TestCase):
|
||||
p = os.path.join(tmpdir, "MIRRORS")
|
||||
self.assertTrue(os.path.exists(p))
|
||||
|
||||
with open(p, "r", encoding="utf-8") as fh:
|
||||
with open(p, encoding="utf-8") as fh:
|
||||
content = fh.read()
|
||||
|
||||
self.assertEqual(
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -37,7 +37,7 @@ class TestUpdatePyprojectVersion(unittest.TestCase):
|
||||
|
||||
update_pyproject_version(path, "1.2.3", preview=False)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn('version = "1.2.3"', content)
|
||||
@@ -62,7 +62,7 @@ class TestUpdatePyprojectVersion(unittest.TestCase):
|
||||
|
||||
update_pyproject_version(path, "1.2.3", preview=True)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertEqual(content, original)
|
||||
@@ -129,7 +129,7 @@ class TestUpdateFlakeVersion(unittest.TestCase):
|
||||
|
||||
update_flake_version(path, "1.2.3", preview=False)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn('version = "1.2.3";', content)
|
||||
@@ -144,7 +144,7 @@ class TestUpdateFlakeVersion(unittest.TestCase):
|
||||
|
||||
update_flake_version(path, "1.2.3", preview=True)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertEqual(content, original)
|
||||
@@ -170,7 +170,7 @@ class TestUpdatePkgbuildVersion(unittest.TestCase):
|
||||
|
||||
update_pkgbuild_version(path, "1.2.3", preview=False)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn("pkgver=1.2.3", content)
|
||||
@@ -196,7 +196,7 @@ class TestUpdatePkgbuildVersion(unittest.TestCase):
|
||||
|
||||
update_pkgbuild_version(path, "1.2.3", preview=True)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertEqual(content, original)
|
||||
@@ -222,7 +222,7 @@ class TestUpdateSpecVersion(unittest.TestCase):
|
||||
|
||||
update_spec_version(path, "1.2.3", preview=False)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn("Version: 1.2.3", content)
|
||||
@@ -249,7 +249,7 @@ class TestUpdateSpecVersion(unittest.TestCase):
|
||||
|
||||
update_spec_version(path, "1.2.3", preview=True)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertEqual(content, original)
|
||||
@@ -264,7 +264,7 @@ class TestUpdateChangelog(unittest.TestCase):
|
||||
update_changelog(path, "1.2.3", message="First release", preview=False)
|
||||
|
||||
self.assertTrue(os.path.exists(path))
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
# New file must lead with an H1 so markdownlint MD041 is happy.
|
||||
@@ -280,7 +280,7 @@ class TestUpdateChangelog(unittest.TestCase):
|
||||
|
||||
update_changelog(path, "1.0.0", message="Second release", preview=False)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
# H1 still on top, new entry above the existing one.
|
||||
@@ -303,7 +303,7 @@ class TestUpdateChangelog(unittest.TestCase):
|
||||
|
||||
update_changelog(path, "1.0.0", message=None, preview=False)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
# An H1 is added so MD041 is satisfied even for legacy files.
|
||||
@@ -315,7 +315,7 @@ class TestUpdateChangelog(unittest.TestCase):
|
||||
path = os.path.join(tmpdir, "CHANGELOG.md")
|
||||
update_changelog(path, "1.2.3", message="* Provided bullet", preview=False)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn("\n\n* Provided bullet\n", content)
|
||||
@@ -331,7 +331,7 @@ class TestUpdateChangelog(unittest.TestCase):
|
||||
preview=False,
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn("**Summary**", content)
|
||||
@@ -348,7 +348,7 @@ class TestUpdateChangelog(unittest.TestCase):
|
||||
|
||||
update_changelog(path, "1.0.0", message="Preview only", preview=True)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertEqual(content, original)
|
||||
@@ -374,7 +374,7 @@ class TestUpdateDebianChangelog(unittest.TestCase):
|
||||
preview=False,
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn("package-manager (1.2.3-1) unstable; urgency=medium", content)
|
||||
@@ -402,7 +402,7 @@ class TestUpdateDebianChangelog(unittest.TestCase):
|
||||
preview=True,
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertEqual(content, original)
|
||||
@@ -428,7 +428,7 @@ class TestUpdateDebianChangelog(unittest.TestCase):
|
||||
preview=False,
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn(" * First bullet", content)
|
||||
@@ -484,7 +484,7 @@ class TestUpdateSpecChangelog(unittest.TestCase):
|
||||
preview=False,
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn("%changelog", content)
|
||||
@@ -526,7 +526,7 @@ class TestUpdateSpecChangelog(unittest.TestCase):
|
||||
preview=True,
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertEqual(content, original)
|
||||
@@ -567,7 +567,7 @@ class TestUpdateSpecChangelog(unittest.TestCase):
|
||||
preview=False,
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
self.assertIn("- * First bullet", content)
|
||||
|
||||
@@ -11,7 +11,6 @@ import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from pkgmgr.actions.release.package_name import resolve_package_name
|
||||
from pkgmgr.core.repository.paths import RepoPaths
|
||||
@@ -20,9 +19,9 @@ from pkgmgr.core.repository.paths import RepoPaths
|
||||
def _paths(
|
||||
repo_dir: str,
|
||||
*,
|
||||
debian_control: Optional[str] = None,
|
||||
arch_pkgbuild: Optional[str] = None,
|
||||
rpm_spec: Optional[str] = None,
|
||||
debian_control: str | None = None,
|
||||
arch_pkgbuild: str | None = None,
|
||||
rpm_spec: str | None = None,
|
||||
) -> RepoPaths:
|
||||
return RepoPaths(
|
||||
repo_dir=repo_dir,
|
||||
|
||||
@@ -36,9 +36,7 @@ class TestDeinstallRepos(unittest.TestCase):
|
||||
def exists_side_effect(path):
|
||||
if path == "/home/u/.local/bin/demo":
|
||||
return True
|
||||
if path == "/repos/github.com/alice/demo/Makefile":
|
||||
return True
|
||||
return False
|
||||
return path == "/repos/github.com/alice/demo/Makefile"
|
||||
|
||||
mock_exists.side_effect = exists_side_effect
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Unit tests for pkgmgr.cli.commands.release.
|
||||
|
||||
@@ -16,7 +14,6 @@ from __future__ import annotations
|
||||
import argparse
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from typing import List
|
||||
from unittest.mock import call, patch
|
||||
|
||||
|
||||
@@ -25,7 +22,7 @@ class TestReleaseCommand(unittest.TestCase):
|
||||
Tests for the `pkgmgr release` CLI wiring.
|
||||
"""
|
||||
|
||||
def _make_ctx(self, all_repos: List[dict]) -> SimpleNamespace:
|
||||
def _make_ctx(self, all_repos: list[dict]) -> SimpleNamespace:
|
||||
"""
|
||||
Create a minimal CLIContext-like object for tests.
|
||||
|
||||
@@ -39,7 +36,7 @@ class TestReleaseCommand(unittest.TestCase):
|
||||
user_config_path="/tmp/config.yaml",
|
||||
)
|
||||
|
||||
def _parse_release_args(self, argv: List[str]) -> argparse.Namespace:
|
||||
def _parse_release_args(self, argv: list[str]) -> argparse.Namespace:
|
||||
"""
|
||||
Build a real top-level parser and parse the given argv list
|
||||
to obtain the Namespace for the `release` command.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Unit tests for pkgmgr.cli.commands.repos
|
||||
|
||||
@@ -26,17 +24,17 @@ import io
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from types import SimpleNamespace
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
from pkgmgr.cli.commands.repos import handle_repos_command
|
||||
from pkgmgr.cli.context import CLIContext
|
||||
|
||||
Repository = Dict[str, Any]
|
||||
Repository = dict[str, Any]
|
||||
|
||||
|
||||
class TestReposCommand(unittest.TestCase):
|
||||
def _make_ctx(self, repositories: List[Repository]) -> CLIContext:
|
||||
def _make_ctx(self, repositories: list[Repository]) -> CLIContext:
|
||||
"""
|
||||
Helper to build a minimal CLIContext for tests.
|
||||
"""
|
||||
@@ -57,7 +55,7 @@ class TestReposCommand(unittest.TestCase):
|
||||
When repository["directory"] is present, handle_repos_command("path")
|
||||
should print this value directly without calling get_repo_dir().
|
||||
"""
|
||||
repos: List[Repository] = [
|
||||
repos: list[Repository] = [
|
||||
{
|
||||
"provider": "github.com",
|
||||
"account": "kevinveenbirkenbach",
|
||||
@@ -93,7 +91,7 @@ class TestReposCommand(unittest.TestCase):
|
||||
should call get_repo_dir(ctx.repositories_base_dir, repo) and print
|
||||
the returned value.
|
||||
"""
|
||||
repos: List[Repository] = [
|
||||
repos: list[Repository] = [
|
||||
{
|
||||
"provider": "github.com",
|
||||
"account": "kevinveenbirkenbach",
|
||||
@@ -155,7 +153,7 @@ class TestReposCommand(unittest.TestCase):
|
||||
'shell' should resolve the repository directory and pass it as cwd
|
||||
to run_command(), along with the full shell command string.
|
||||
"""
|
||||
repos: List[Repository] = [
|
||||
repos: list[Repository] = [
|
||||
{
|
||||
"provider": "github.com",
|
||||
"account": "kevinveenbirkenbach",
|
||||
@@ -196,7 +194,7 @@ class TestReposCommand(unittest.TestCase):
|
||||
"""
|
||||
'shell' without -c/--command should print an error and exit with code 2.
|
||||
"""
|
||||
repos: List[Repository] = []
|
||||
repos: list[Repository] = []
|
||||
ctx = self._make_ctx(repos)
|
||||
|
||||
args = SimpleNamespace(
|
||||
|
||||
@@ -2,12 +2,12 @@ from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any
|
||||
from unittest.mock import call, patch
|
||||
|
||||
from pkgmgr.cli.commands.tools import handle_tools_command
|
||||
|
||||
Repository = Dict[str, Any]
|
||||
Repository = dict[str, Any]
|
||||
|
||||
|
||||
class _Args:
|
||||
@@ -29,7 +29,7 @@ class TestHandleToolsCommand(unittest.TestCase):
|
||||
"""
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.repos: List[Repository] = [
|
||||
self.repos: list[Repository] = [
|
||||
{"alias": "repo1", "directory": "/tmp/repo1"},
|
||||
{"alias": "repo2", "directory": "/tmp/repo2"},
|
||||
]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Unit tests for the pkgmgr CLI (version command).
|
||||
|
||||
@@ -23,13 +21,13 @@ import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any
|
||||
from unittest import mock
|
||||
|
||||
from pkgmgr import cli
|
||||
|
||||
|
||||
def _fake_config() -> Dict[str, Any]:
|
||||
def _fake_config() -> dict[str, Any]:
|
||||
"""
|
||||
Provide a minimal configuration dict sufficient for cli.main()
|
||||
to start without touching real config files.
|
||||
@@ -132,7 +130,7 @@ class TestCliVersion(unittest.TestCase):
|
||||
|
||||
def _run_cli_version_and_capture(
|
||||
self,
|
||||
extra_args: List[str] | None = None,
|
||||
extra_args: list[str] | None = None,
|
||||
) -> str:
|
||||
"""
|
||||
Run 'pkgmgr version [extra_args]' via cli.main() and return captured stdout.
|
||||
|
||||
@@ -45,7 +45,7 @@ class TestCliBranch(unittest.TestCase):
|
||||
handle_branch(args, ctx)
|
||||
|
||||
mock_open_branch.assert_called_once()
|
||||
call_args, call_kwargs = mock_open_branch.call_args
|
||||
_call_args, call_kwargs = mock_open_branch.call_args
|
||||
self.assertEqual(call_kwargs.get("name"), "feature/cli-test")
|
||||
self.assertEqual(call_kwargs.get("base_branch"), "develop")
|
||||
self.assertEqual(call_kwargs.get("cwd"), ".")
|
||||
|
||||
@@ -5,10 +5,10 @@ import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
Repository = Dict[str, Any]
|
||||
Repository = dict[str, Any]
|
||||
|
||||
|
||||
class TestOpenVSCodeWorkspace(unittest.TestCase):
|
||||
@@ -27,13 +27,15 @@ class TestOpenVSCodeWorkspace(unittest.TestCase):
|
||||
from pkgmgr.cli.tools.vscode import open_vscode_workspace
|
||||
|
||||
ctx = SimpleNamespace(config_merged={}, all_repositories=[])
|
||||
selected: List[Repository] = [
|
||||
selected: list[Repository] = [
|
||||
{"provider": "github.com", "account": "x", "repository": "y"}
|
||||
]
|
||||
|
||||
with patch("pkgmgr.cli.tools.vscode.shutil.which", return_value=None):
|
||||
with self.assertRaises(RuntimeError) as cm:
|
||||
open_vscode_workspace(ctx, selected)
|
||||
with (
|
||||
patch("pkgmgr.cli.tools.vscode.shutil.which", return_value=None),
|
||||
self.assertRaises(RuntimeError) as cm,
|
||||
):
|
||||
open_vscode_workspace(ctx, selected)
|
||||
|
||||
self.assertIn("VS Code CLI ('code') not found", str(cm.exception))
|
||||
|
||||
@@ -44,7 +46,7 @@ class TestOpenVSCodeWorkspace(unittest.TestCase):
|
||||
config_merged={"directories": {"workspaces": "~/Workspaces"}},
|
||||
all_repositories=[],
|
||||
)
|
||||
selected: List[Repository] = [
|
||||
selected: list[Repository] = [
|
||||
{"provider": "github.com", "account": "x", "repository": "y"}
|
||||
]
|
||||
|
||||
@@ -74,7 +76,7 @@ class TestOpenVSCodeWorkspace(unittest.TestCase):
|
||||
all_repositories=[],
|
||||
repositories_base_dir=os.path.join(tmp, "Repos"),
|
||||
)
|
||||
selected: List[Repository] = [
|
||||
selected: list[Repository] = [
|
||||
{
|
||||
"provider": "github.com",
|
||||
"account": "kevin",
|
||||
@@ -101,7 +103,7 @@ class TestOpenVSCodeWorkspace(unittest.TestCase):
|
||||
workspace_file = os.path.join(workspaces_dir, "dotlinker.code-workspace")
|
||||
self.assertTrue(os.path.exists(workspace_file))
|
||||
|
||||
with open(workspace_file, "r", encoding="utf-8") as f:
|
||||
with open(workspace_file, encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
self.assertEqual(data["folders"], [{"path": repo_path}])
|
||||
@@ -125,7 +127,7 @@ class TestOpenVSCodeWorkspace(unittest.TestCase):
|
||||
config_merged={"directories": {"workspaces": workspaces_dir}},
|
||||
all_repositories=[],
|
||||
)
|
||||
selected: List[Repository] = [
|
||||
selected: list[Repository] = [
|
||||
{
|
||||
"provider": "github.com",
|
||||
"account": "kevin",
|
||||
@@ -149,7 +151,7 @@ class TestOpenVSCodeWorkspace(unittest.TestCase):
|
||||
):
|
||||
open_vscode_workspace(ctx, selected)
|
||||
|
||||
with open(workspace_file, "r", encoding="utf-8") as f:
|
||||
with open(workspace_file, encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
self.assertEqual(data, original)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import stat
|
||||
|
||||
@@ -33,9 +33,11 @@ class TestRunCommand(unittest.TestCase):
|
||||
"import sys; print('oops', file=sys.stderr); sys.exit(2)",
|
||||
]
|
||||
|
||||
with patch.object(run_mod.sys, "exit", side_effect=SystemExit(2)) as exit_mock:
|
||||
with self.assertRaises(SystemExit) as ctx:
|
||||
run_mod.run_command(cmd, allow_failure=False)
|
||||
with (
|
||||
patch.object(run_mod.sys, "exit", side_effect=SystemExit(2)) as exit_mock,
|
||||
self.assertRaises(SystemExit) as ctx,
|
||||
):
|
||||
run_mod.run_command(cmd, allow_failure=False)
|
||||
|
||||
self.assertEqual(ctx.exception.code, 2)
|
||||
exit_mock.assert_called_once_with(2)
|
||||
|
||||
@@ -256,9 +256,11 @@ class LoadConfigIntegrationUnitTests(unittest.TestCase):
|
||||
)
|
||||
|
||||
fake_pkgmgr = types.SimpleNamespace(__file__=str(pkg_root / "__init__.py"))
|
||||
with patch.dict(sys.modules, {"pkgmgr": fake_pkgmgr}):
|
||||
with patch.dict(os.environ, {"HOME": str(home)}):
|
||||
merged = load_config(user_config_path)
|
||||
with (
|
||||
patch.dict(sys.modules, {"pkgmgr": fake_pkgmgr}),
|
||||
patch.dict(os.environ, {"HOME": str(home)}),
|
||||
):
|
||||
merged = load_config(user_config_path)
|
||||
|
||||
# directories are merged: defaults then user
|
||||
self.assertEqual(merged["directories"]["repositories"], "/PKG/Repos")
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -38,9 +38,7 @@ class TestGitRun(unittest.TestCase):
|
||||
self.assertEqual(kwargs["cwd"], "/repo")
|
||||
self.assertTrue(kwargs["check"])
|
||||
self.assertTrue(kwargs["text"])
|
||||
# ensure pipes are used (matches implementation intent)
|
||||
self.assertIsNotNone(kwargs["stdout"])
|
||||
self.assertIsNotNone(kwargs["stderr"])
|
||||
self.assertTrue(kwargs["capture_output"])
|
||||
|
||||
def test_failure_raises_giterror_with_details(self) -> None:
|
||||
# Build a CalledProcessError with stdout/stderr populated
|
||||
@@ -57,9 +55,11 @@ class TestGitRun(unittest.TestCase):
|
||||
exc.stdout = "OUT!"
|
||||
exc.stderr = "ERR!"
|
||||
|
||||
with patch("pkgmgr.core.git.run.subprocess.run", side_effect=exc):
|
||||
with self.assertRaises(GitRunError) as ctx:
|
||||
run(["status"], cwd="/bad/repo", preview=False)
|
||||
with (
|
||||
patch("pkgmgr.core.git.run.subprocess.run", side_effect=exc),
|
||||
self.assertRaises(GitRunError) as ctx,
|
||||
):
|
||||
run(["status"], cwd="/bad/repo", preview=False)
|
||||
|
||||
msg = str(ctx.exception)
|
||||
self.assertIn("Git command failed in '/bad/repo': git status", msg)
|
||||
|
||||
@@ -132,7 +132,7 @@ class TestSetRepoVisibility(unittest.TestCase):
|
||||
|
||||
self.assertEqual(res.status, "updated")
|
||||
provider.set_repo_private.assert_called_once()
|
||||
args, kwargs = provider.set_repo_private.call_args
|
||||
_args, kwargs = provider.set_repo_private.call_args
|
||||
self.assertEqual(kwargs.get("private"), False)
|
||||
|
||||
def test_provider_hint_overrides_registry_resolution(self) -> None:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
from pkgmgr.core.repository.ignored import filter_ignored
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
from pkgmgr.core.version.semver import (
|
||||
|
||||
Reference in New Issue
Block a user