style: autoformat src and tests

Repository-wide formatting pass over src/ and tests/: sorted imports and
__all__ entries, dropped redundant `# -*- coding: utf-8 -*-` headers,
unquoted forward-reference annotations (safe under
`from __future__ import annotations`), merged nested `with` statements,
moved `Iterable` and friends from `typing` to `collections.abc`, and
removed `# noqa: F401` markers that no longer suppress anything.

No behavioural changes. Unit and integration suites show the same four
pre-existing failures before and after the pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-Birkenbach
2026-07-27 15:17:35 +02:00
parent f1517963a5
commit 8294bce436
185 changed files with 378 additions and 445 deletions

View File

@@ -4,7 +4,7 @@ import io
import runpy
import sys
import unittest
from contextlib import redirect_stdout, redirect_stderr
from contextlib import redirect_stderr, redirect_stdout
def _run_pkgmgr_help(argv_tail: list[str]) -> str:

View File

@@ -6,8 +6,8 @@ import sys
import unittest
from test_version_commands import (
_load_pkgmgr_repo_dir,
PROJECT_ROOT,
_load_pkgmgr_repo_dir,
)

View File

@@ -16,8 +16,8 @@ import unittest
from test_install_pkgmgr_shallow import (
nix_profile_list_debug,
remove_pkgmgr_from_nix_profile,
pkgmgr_help_debug,
remove_pkgmgr_from_nix_profile,
)

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Integration tests for the `pkgmgr config` command.

View File

@@ -1,8 +1,9 @@
from tests.e2e._util import run
import tempfile
import unittest
from pathlib import Path
from tests.e2e._util import run
class TestMakefileThreeTimes(unittest.TestCase):
def test_make_install_three_times(self):

View File

@@ -1,8 +1,8 @@
import runpy
import sys
import os
import unittest
import runpy
import subprocess
import sys
import unittest
def nix_profile_list_debug(label: str) -> None:

View File

@@ -1,9 +1,10 @@
import os
from tests.e2e._util import run
import tempfile
import unittest
from pathlib import Path
from tests.e2e._util import run
class TestPkgmgrInstallThreeTimesNix(unittest.TestCase):
def test_three_times_install_nix(self):

View File

@@ -1,8 +1,9 @@
from tests.e2e._util import run
import os
import tempfile
import unittest
from pathlib import Path
import os
from tests.e2e._util import run
class TestPkgmgrInstallThreeTimesVenv(unittest.TestCase):

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Integration tests for the `pkgmgr make` command.

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
E2E test to inspect the Nix environment and build the pkgmgr flake
@@ -22,7 +21,6 @@ import os
import subprocess
import unittest
# Resolve project root (the repo where flake.nix lives, e.g. /src)
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
End-to-end tests for the `pkgmgr path` command.

View File

@@ -5,7 +5,6 @@ import shutil
import subprocess
import unittest
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
End-to-end style integration tests for the `pkgmgr release` CLI command.
@@ -141,8 +140,8 @@ class TestIntegrationReleaseCommand(unittest.TestCase):
This test intentionally does not mock anything to exercise the real
CLI parser wiring in main.py.
"""
import io
import contextlib
import io
original_argv = list(sys.argv)
buf = io.StringIO()

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Integration tests for the "tools" commands:

View File

@@ -22,8 +22,8 @@ from pathlib import Path
from test_install_pkgmgr_shallow import (
nix_profile_list_debug,
remove_pkgmgr_from_nix_profile,
pkgmgr_help_debug,
remove_pkgmgr_from_nix_profile,
)

View File

@@ -21,8 +21,8 @@ from pathlib import Path
from test_install_pkgmgr_shallow import (
nix_profile_list_debug,
remove_pkgmgr_from_nix_profile,
pkgmgr_help_debug,
remove_pkgmgr_from_nix_profile,
)

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
End-to-end tests for the `pkgmgr version` command.

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Integration tests for the `pkgmgr branch` CLI wiring.
@@ -16,8 +15,8 @@ from __future__ import annotations
import unittest
from unittest.mock import patch
from pkgmgr.cli.parser import create_parser
from pkgmgr.cli.commands.branch import handle_branch
from pkgmgr.cli.parser import create_parser
class TestBranchCLI(unittest.TestCase):

View File

@@ -11,8 +11,8 @@ from unittest.mock import patch
import yaml
from pkgmgr.core.config.load import load_config
from pkgmgr.cli.commands import config as config_cmd
from pkgmgr.core.config.load import load_config
class ConfigDefaultsIntegrationTest(unittest.TestCase):

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import tempfile

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
CLI integration tests for `pkgmgr mirror`.

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Integration test for mirror probing + provisioning after refactor.

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Integration tests for recursive capability resolution and installer shadowing.
@@ -17,7 +16,8 @@ import os
import shutil
import tempfile
import unittest
from typing import List, Sequence, Tuple
from collections.abc import Sequence
from typing import List, Tuple
from unittest.mock import patch
import pkgmgr.actions.install as install_mod
@@ -29,7 +29,6 @@ from pkgmgr.actions.install.installers.os_packages.arch_pkgbuild import (
)
from pkgmgr.actions.install.installers.python import PythonInstaller
InstallerSpec = Tuple[str, object]

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
@@ -42,7 +41,6 @@ class TestUpdateSilentContinues(unittest.TestCase):
pull_calls.append(repo["repository"])
if repo["repository"] == "repo-a":
raise SystemExit(2)
return None
def install_side_effect(selected_repos, *_args, **kwargs):
repo = selected_repos[0]
@@ -51,7 +49,6 @@ class TestUpdateSilentContinues(unittest.TestCase):
)
if repo["repository"] == "repo-b":
raise SystemExit(3)
return None
# Patch at the exact import locations used inside UpdateManager.run()
with (

View File

@@ -14,7 +14,6 @@ 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]

View File

@@ -2,8 +2,8 @@ import unittest
from unittest.mock import patch
from pkgmgr.actions.branch.close_branch import close_branch
from pkgmgr.core.git.errors import GitRunError
from pkgmgr.core.git.commands import GitDeleteRemoteBranchError
from pkgmgr.core.git.errors import GitRunError
class TestCloseBranch(unittest.TestCase):

View File

@@ -2,8 +2,8 @@ import unittest
from unittest.mock import patch
from pkgmgr.actions.branch.drop_branch import drop_branch
from pkgmgr.core.git.errors import GitRunError
from pkgmgr.core.git.commands import GitDeleteRemoteBranchError
from pkgmgr.core.git.errors import GitRunError
class TestDropBranch(unittest.TestCase):

View File

@@ -3,7 +3,8 @@ from __future__ import annotations
import unittest
from pkgmgr.actions.install.installers.nix.conflicts import NixConflictResolver
from ._fakes import FakeRunResult, FakeRunner, FakeRetry
from ._fakes import FakeRetry, FakeRunner, FakeRunResult
class DummyCtx:

View File

@@ -4,7 +4,8 @@ import json
import unittest
from pkgmgr.actions.install.installers.nix.profile import NixProfileInspector
from ._fakes import FakeRunResult, FakeRunner
from ._fakes import FakeRunner, FakeRunResult
class TestNixProfileInspector(unittest.TestCase):

View File

@@ -4,6 +4,7 @@ import unittest
from unittest.mock import MagicMock
from pkgmgr.actions.install.installers.nix.installer import NixFlakeInstaller
from ._fakes import FakeRunResult

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Unit tests for NixFlakeInstaller using unittest (no pytest).

View File

@@ -2,11 +2,11 @@ from __future__ import annotations
import unittest
from pkgmgr.actions.install.installers.nix.profile.models import NixProfileEntry
from pkgmgr.actions.install.installers.nix.profile.matcher import (
entry_matches_output,
entry_matches_store_path,
)
from pkgmgr.actions.install.installers.nix.profile.models import NixProfileEntry
class TestMatcher(unittest.TestCase):

View File

@@ -3,7 +3,8 @@ from __future__ import annotations
import unittest
from pkgmgr.actions.install.installers.nix.profile_list import NixProfileListReader
from ._fakes import FakeRunResult, FakeRunner
from ._fakes import FakeRunner, FakeRunResult
class TestNixProfileListReader(unittest.TestCase):

View File

@@ -1,8 +1,9 @@
# tests/unit/pkgmgr/installers/test_base.py
import unittest
from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.base import BaseInstaller
class DummyInstaller(BaseInstaller):

View File

@@ -2,7 +2,7 @@
import os
import unittest
from unittest.mock import patch, mock_open
from unittest.mock import mock_open, patch
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.makefile import MakefileInstaller

View File

@@ -1,16 +1,16 @@
# tests/unit/pkgmgr/test_capabilities.py
import unittest
from unittest.mock import patch, mock_open
from unittest.mock import mock_open, patch
from pkgmgr.actions.install.capabilities import (
PythonRuntimeCapability,
LAYER_ORDER,
CapabilityMatcher,
MakeInstallCapability,
NixFlakeCapability,
CapabilityMatcher,
PythonRuntimeCapability,
detect_capabilities,
resolve_effective_capabilities,
LAYER_ORDER,
)

View File

@@ -1,4 +1,5 @@
import unittest
from pkgmgr.actions.install.context import RepoContext

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import unittest
@@ -8,7 +7,6 @@ from unittest.mock import MagicMock, patch
from pkgmgr.actions.install import install_repos
Repository = Dict[str, Any]

View File

@@ -1,12 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import unittest
from pkgmgr.actions.install.layers import (
CliLayer,
CLI_LAYERS,
CliLayer,
classify_command_layer,
layer_priority,
)

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
from unittest.mock import MagicMock, patch

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

View File

@@ -22,25 +22,24 @@ class TestGitRemotePrimaryPush(unittest.TestCase):
},
)
with patch("os.path.isdir", return_value=True):
with (
patch(
"pkgmgr.actions.mirror.git_remote.has_origin_remote",
return_value=False,
),
patch("pkgmgr.actions.mirror.git_remote.add_remote") as m_add_remote,
patch(
"pkgmgr.actions.mirror.git_remote.set_remote_url"
) as m_set_remote_url,
patch(
"pkgmgr.actions.mirror.git_remote.get_remote_push_urls",
return_value=set(),
),
patch(
"pkgmgr.actions.mirror.git_remote.add_remote_push_url"
) as m_add_push,
):
ensure_origin_remote(repo, ctx, preview=False)
with (
patch("os.path.isdir", return_value=True), patch(
"pkgmgr.actions.mirror.git_remote.has_origin_remote",
return_value=False,
),
patch("pkgmgr.actions.mirror.git_remote.add_remote") as m_add_remote,
patch(
"pkgmgr.actions.mirror.git_remote.set_remote_url"
) as m_set_remote_url,
patch(
"pkgmgr.actions.mirror.git_remote.get_remote_push_urls",
return_value=set(),
),
patch(
"pkgmgr.actions.mirror.git_remote.add_remote_push_url"
) as m_add_push,
):
ensure_origin_remote(repo, ctx, preview=False)
# determine_primary_remote_url falls back to file order (primary first)
m_add_remote.assert_called_once_with(

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

View File

@@ -4,7 +4,7 @@ from __future__ import annotations
import io
import unittest
from contextlib import redirect_stdout
from unittest.mock import patch, MagicMock
from unittest.mock import MagicMock, patch
from pkgmgr.actions.mirror.visibility_cmd import set_mirror_visibility

View File

@@ -1,4 +1,5 @@
import unittest
from pkgmgr.actions.publish.pypi_url import parse_pypi_project_url

View File

@@ -5,7 +5,7 @@ import unittest
class TestReleasePackageInit(unittest.TestCase):
def test_release_is_reexported(self) -> None:
from pkgmgr.actions.release import release # noqa: F401
from pkgmgr.actions.release import release
self.assertTrue(callable(release))

View File

@@ -3,11 +3,11 @@ from __future__ import annotations
import unittest
from unittest.mock import patch
from pkgmgr.core.version.semver import SemVer
from pkgmgr.actions.release.versioning import (
determine_current_version,
bump_semver,
determine_current_version,
)
from pkgmgr.core.version.semver import SemVer
class TestDetermineCurrentVersion(unittest.TestCase):

View File

@@ -4,10 +4,10 @@ import unittest
from pkgmgr.actions.repository.create.model import RepoParts
from pkgmgr.actions.repository.create.parser import (
parse_identifier,
_parse_git_url,
_strip_git_suffix,
_split_host_port,
_strip_git_suffix,
parse_identifier,
)

View File

@@ -4,8 +4,8 @@ import unittest
from unittest.mock import patch
from pkgmgr.actions.changelog import generate_changelog
from pkgmgr.core.git.queries import GitChangelogQueryError
from pkgmgr.cli.commands.changelog import _find_previous_and_current_tag
from pkgmgr.core.git.queries import GitChangelogQueryError
class TestGenerateChangelog(unittest.TestCase):

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Unit tests for pkgmgr.cli.commands.release.
@@ -14,12 +13,11 @@ These tests focus on the wiring layer:
from __future__ import annotations
from types import SimpleNamespace
from typing import List
from unittest.mock import patch, call
import argparse
import unittest
from types import SimpleNamespace
from typing import List
from unittest.mock import call, patch
class TestReleaseCommand(unittest.TestCase):

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Unit tests for pkgmgr.cli.commands.repos
@@ -30,9 +29,8 @@ from types import SimpleNamespace
from typing import Any, Dict, List
from unittest.mock import patch
from pkgmgr.cli.context import CLIContext
from pkgmgr.cli.commands.repos import handle_repos_command
from pkgmgr.cli.context import CLIContext
Repository = Dict[str, Any]

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Unit tests for the pkgmgr CLI (version command).

View File

@@ -54,9 +54,9 @@ class TestOpenVSCodeWorkspace(unittest.TestCase):
"pkgmgr.cli.tools.vscode.get_repo_identifier",
return_value="github.com/x/y",
),
self.assertRaises(RuntimeError) as cm,
):
with self.assertRaises(RuntimeError) as cm:
open_vscode_workspace(ctx, selected)
open_vscode_workspace(ctx, selected)
msg = str(cm.exception)
self.assertIn("not yet identified", msg)

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import stat

View File

@@ -82,9 +82,8 @@ class UpdateDefaultConfigsTests(unittest.TestCase):
# Patch the source dir finder to our temp source_dir
with patch.object(
config_cmd, "_find_defaults_source_dir", return_value=str(source_dir)
):
with patch.dict(os.environ, {"HOME": str(home)}):
config_cmd._update_default_configs(user_config_path)
), patch.dict(os.environ, {"HOME": str(home)}):
config_cmd._update_default_configs(user_config_path)
self.assertTrue((dest_cfg_dir / "a.yaml").is_file())
self.assertTrue((dest_cfg_dir / "b.yml").is_file())
@@ -102,9 +101,8 @@ class UpdateDefaultConfigsTests(unittest.TestCase):
with patch.object(
config_cmd, "_find_defaults_source_dir", return_value=str(source_dir)
):
with patch.dict(os.environ, {"HOME": str(home)}):
config_cmd._update_default_configs(user_config_path)
), patch.dict(os.environ, {"HOME": str(home)}):
config_cmd._update_default_configs(user_config_path)
self.assertEqual(
(dest_cfg_dir / "config.yaml").read_text(encoding="utf-8"),
@@ -122,10 +120,8 @@ class UpdateDefaultConfigsTests(unittest.TestCase):
buf = io.StringIO()
with patch.object(
config_cmd, "_find_defaults_source_dir", return_value=None
):
with patch("sys.stdout", buf):
with patch.dict(os.environ, {"HOME": str(home)}):
config_cmd._update_default_configs(user_config_path)
), patch("sys.stdout", buf), patch.dict(os.environ, {"HOME": str(home)}):
config_cmd._update_default_configs(user_config_path)
out = buf.getvalue()
self.assertIn("[WARN] No config directory found", out)

View File

@@ -12,9 +12,9 @@ import yaml
from pkgmgr.core.config.load import (
_deep_merge,
_merge_repo_lists,
_load_layer_dir,
_load_defaults_from_package_or_project,
_load_layer_dir,
_merge_repo_lists,
load_config,
)

View File

@@ -1,5 +1,5 @@
import unittest
import subprocess
import unittest
from unittest.mock import patch
from pkgmgr.core.git.errors import GitNotRepositoryError

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
import unittest
from unittest.mock import MagicMock
from pkgmgr.core.remote_provisioning.http.errors import HttpError
from pkgmgr.core.remote_provisioning.types import (
AuthError,
NetworkError,
@@ -16,7 +17,6 @@ from pkgmgr.core.remote_provisioning.visibility import (
VisibilityOptions,
set_repo_visibility,
)
from pkgmgr.core.remote_provisioning.http.errors import HttpError
class TestSetRepoVisibility(unittest.TestCase):

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import unittest

View File

@@ -118,6 +118,5 @@ class TestVerifyRepository(unittest.TestCase):
with patch(
"pkgmgr.core.repository.verify.get_head_commit",
side_effect=GitNotRepositoryError("no repo"),
):
with self.assertRaises(GitNotRepositoryError):
verify_repository(repo, "/tmp/no-repo", mode="local")
), self.assertRaises(GitNotRepositoryError):
verify_repository(repo, "/tmp/no-repo", mode="local")

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
from unittest.mock import patch

View File

@@ -1,12 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
from unittest.mock import patch
from pkgmgr.core.git.errors import GitRunError
from pkgmgr.core.git.queries import get_current_branch, get_head_commit, get_tags
from pkgmgr.core.git.run import run
from pkgmgr.core.git.queries import get_tags, get_head_commit, get_current_branch
class TestGitRun(unittest.TestCase):

View File

@@ -1,16 +1,15 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
from pkgmgr.core.version.semver import (
SemVer,
is_semver_tag,
extract_semver_from_tags,
find_latest_version,
bump_major,
bump_minor,
bump_patch,
extract_semver_from_tags,
find_latest_version,
is_semver_tag,
)
@@ -30,9 +29,8 @@ class TestSemVer(unittest.TestCase):
def test_semver_parse_invalid(self):
invalid_values = ["", "1", "1.2", "1.2.3.4", "a.b.c", "v1.2.x"]
for value in invalid_values:
with self.subTest(value=value):
with self.assertRaises(ValueError):
SemVer.parse(value)
with self.subTest(value=value), self.assertRaises(ValueError):
SemVer.parse(value)
def test_semver_to_tag_and_str(self):
ver = SemVer(1, 2, 3)