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:
@@ -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