Moved installer dir

This commit is contained in:
Kevin Veen-Birkenbach
2025-12-10 17:27:26 +01:00
parent e290043089
commit 900224ed2e
31 changed files with 132 additions and 132 deletions

View File

@@ -6,9 +6,9 @@ import tempfile
import unittest
from unittest.mock import patch
import pkgmgr.actions.repository.install as install_module
from pkgmgr.actions.repository.install import install_repos
from pkgmgr.actions.repository.install.installers.base import BaseInstaller
import pkgmgr.actions.install as install_module
from pkgmgr.actions.install import install_repos
from pkgmgr.actions.install.installers.base import BaseInstaller
class DummyInstaller(BaseInstaller):
@@ -27,10 +27,10 @@ class DummyInstaller(BaseInstaller):
class TestInstallReposIntegration(unittest.TestCase):
@patch("pkgmgr.actions.repository.install.verify_repository")
@patch("pkgmgr.actions.repository.install.clone_repos")
@patch("pkgmgr.actions.repository.install.get_repo_dir")
@patch("pkgmgr.actions.repository.install.get_repo_identifier")
@patch("pkgmgr.actions.install.verify_repository")
@patch("pkgmgr.actions.install.clone_repos")
@patch("pkgmgr.actions.install.get_repo_dir")
@patch("pkgmgr.actions.install.get_repo_identifier")
def test_system_binary_vs_nix_binary(
self,
mock_get_repo_identifier,
@@ -104,9 +104,9 @@ class TestInstallReposIntegration(unittest.TestCase):
# Patch resolve_command_for_repo at the *pipeline* module level,
# because InstallationPipeline imports it there.
with patch(
"pkgmgr.actions.repository.install.pipeline.resolve_command_for_repo"
"pkgmgr.actions.install.pipeline.resolve_command_for_repo"
) as mock_resolve, patch(
"pkgmgr.actions.repository.install.os.path.exists"
"pkgmgr.actions.install.os.path.exists"
) as mock_exists_install:
def fake_resolve(repo, repo_identifier: str, repo_dir: str):

View File

@@ -20,14 +20,14 @@ import unittest
from typing import List, Sequence, Tuple
from unittest.mock import patch
import pkgmgr.actions.repository.install as install_mod
from pkgmgr.actions.repository.install import install_repos
from pkgmgr.actions.repository.install.installers.makefile import MakefileInstaller
from pkgmgr.actions.repository.install.installers.nix_flake import NixFlakeInstaller
from pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild import (
import pkgmgr.actions.install as install_mod
from pkgmgr.actions.install import install_repos
from pkgmgr.actions.install.installers.makefile import MakefileInstaller
from pkgmgr.actions.install.installers.nix_flake import NixFlakeInstaller
from pkgmgr.actions.install.installers.os_packages.arch_pkgbuild import (
ArchPkgbuildInstaller,
)
from pkgmgr.actions.repository.install.installers.python import PythonInstaller
from pkgmgr.actions.install.installers.python import PythonInstaller
InstallerSpec = Tuple[str, object]

View File

@@ -4,8 +4,8 @@ import os
import unittest
from unittest.mock import patch
from pkgmgr.actions.repository.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild import ArchPkgbuildInstaller
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.os_packages.arch_pkgbuild import ArchPkgbuildInstaller
class TestArchPkgbuildInstaller(unittest.TestCase):
@@ -26,7 +26,7 @@ class TestArchPkgbuildInstaller(unittest.TestCase):
)
self.installer = ArchPkgbuildInstaller()
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("os.path.exists", return_value=True)
@patch("shutil.which")
def test_supports_true_when_tools_and_pkgbuild_exist(
@@ -46,7 +46,7 @@ class TestArchPkgbuildInstaller(unittest.TestCase):
self.assertIn("makepkg", calls)
mock_exists.assert_called_with(os.path.join(self.ctx.repo_dir, "PKGBUILD"))
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=0)
@patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=0)
@patch("os.path.exists", return_value=True)
@patch("shutil.which")
def test_supports_false_when_running_as_root(
@@ -55,7 +55,7 @@ class TestArchPkgbuildInstaller(unittest.TestCase):
mock_which.return_value = "/usr/bin/pacman"
self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("os.path.exists", return_value=False)
@patch("shutil.which")
def test_supports_false_when_pkgbuild_missing(
@@ -64,8 +64,8 @@ class TestArchPkgbuildInstaller(unittest.TestCase):
mock_which.return_value = "/usr/bin/pacman"
self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.run_command")
@patch("pkgmgr.actions.repository.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.run_command")
@patch("pkgmgr.actions.install.installers.os_packages.arch_pkgbuild.os.geteuid", return_value=1000)
@patch("os.path.exists", return_value=True)
@patch("shutil.which")
def test_run_builds_and_installs_with_makepkg(

View File

@@ -1,8 +1,8 @@
import unittest
from unittest.mock import patch
from pkgmgr.actions.repository.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.os_packages.debian_control import (
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.os_packages.debian_control import (
DebianControlInstaller,
)
@@ -44,7 +44,7 @@ class TestDebianControlInstaller(unittest.TestCase):
self.assertFalse(self.installer.supports(self.ctx))
@patch(
"pkgmgr.actions.repository.install.installers.os_packages.debian_control.run_command"
"pkgmgr.actions.install.installers.os_packages.debian_control.run_command"
)
@patch("glob.glob", return_value=["/tmp/package-manager_0.1.1_all.deb"])
@patch("os.path.exists", return_value=True)

View File

@@ -1,8 +1,8 @@
import unittest
from unittest.mock import patch
from pkgmgr.actions.repository.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.os_packages.rpm_spec import (
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.os_packages.rpm_spec import (
RpmSpecInstaller,
)
@@ -57,7 +57,7 @@ class TestRpmSpecInstaller(unittest.TestCase):
self.assertFalse(self.installer.supports(self.ctx))
@patch.object(RpmSpecInstaller, "_prepare_source_tarball")
@patch("pkgmgr.actions.repository.install.installers.os_packages.rpm_spec.run_command")
@patch("pkgmgr.actions.install.installers.os_packages.rpm_spec.run_command")
@patch("glob.glob")
@patch("shutil.which")
def test_run_builds_and_installs_rpms(

View File

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

View File

@@ -4,8 +4,8 @@ import os
import unittest
from unittest.mock import patch, mock_open
from pkgmgr.actions.repository.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.makefile import MakefileInstaller
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.makefile import MakefileInstaller
class TestMakefileInstaller(unittest.TestCase):
@@ -35,7 +35,7 @@ class TestMakefileInstaller(unittest.TestCase):
def test_supports_false_when_makefile_missing(self, mock_exists):
self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.makefile.run_command")
@patch("pkgmgr.actions.install.installers.makefile.run_command")
@patch(
"builtins.open",
new_callable=mock_open,
@@ -62,7 +62,7 @@ class TestMakefileInstaller(unittest.TestCase):
self.ctx.repo_dir,
)
@patch("pkgmgr.actions.repository.install.installers.makefile.run_command")
@patch("pkgmgr.actions.install.installers.makefile.run_command")
@patch(
"builtins.open",
new_callable=mock_open,

View File

@@ -6,8 +6,8 @@ import unittest
from unittest import mock
from unittest.mock import MagicMock, patch
from pkgmgr.actions.repository.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.nix_flake import NixFlakeInstaller
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.nix_flake import NixFlakeInstaller
class TestNixFlakeInstaller(unittest.TestCase):
@@ -29,8 +29,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
)
self.installer = NixFlakeInstaller()
@patch("pkgmgr.actions.repository.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.shutil.which")
@patch("pkgmgr.actions.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.install.installers.nix_flake.shutil.which")
def test_supports_true_when_nix_and_flake_exist(
self,
mock_which: MagicMock,
@@ -47,8 +47,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
os.path.join(self.ctx.repo_dir, self.installer.FLAKE_FILE)
)
@patch("pkgmgr.actions.repository.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.shutil.which")
@patch("pkgmgr.actions.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.install.installers.nix_flake.shutil.which")
def test_supports_false_when_nix_missing(
self,
mock_which: MagicMock,
@@ -60,8 +60,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
with patch.dict(os.environ, {"PKGMGR_DISABLE_NIX_FLAKE_INSTALLER": ""}, clear=False):
self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.shutil.which")
@patch("pkgmgr.actions.install.installers.nix_flake.os.path.exists")
@patch("pkgmgr.actions.install.installers.nix_flake.shutil.which")
def test_supports_false_when_disabled_via_env(
self,
mock_which: MagicMock,
@@ -77,8 +77,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
):
self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.nix_flake.NixFlakeInstaller.supports")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.run_command")
@patch("pkgmgr.actions.install.installers.nix_flake.NixFlakeInstaller.supports")
@patch("pkgmgr.actions.install.installers.nix_flake.run_command")
def test_run_removes_old_profile_and_installs_outputs(
self,
mock_run_command: MagicMock,
@@ -112,8 +112,8 @@ class TestNixFlakeInstaller(unittest.TestCase):
self.assertEqual(commands[0], remove_cmd)
@patch("pkgmgr.actions.repository.install.installers.nix_flake.shutil.which")
@patch("pkgmgr.actions.repository.install.installers.nix_flake.run_command")
@patch("pkgmgr.actions.install.installers.nix_flake.shutil.which")
@patch("pkgmgr.actions.install.installers.nix_flake.run_command")
def test_ensure_old_profile_removed_ignores_systemexit(
self,
mock_run_command: MagicMock,

View File

@@ -2,8 +2,8 @@ import os
import unittest
from unittest.mock import patch
from pkgmgr.actions.repository.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.python import PythonInstaller
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.python import PythonInstaller
class TestPythonInstaller(unittest.TestCase):
@@ -41,7 +41,7 @@ class TestPythonInstaller(unittest.TestCase):
with patch.dict(os.environ, {"IN_NIX_SHELL": ""}, clear=False):
self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.repository.install.installers.python.run_command")
@patch("pkgmgr.actions.install.installers.python.run_command")
@patch("os.path.exists", side_effect=lambda path: path.endswith("pyproject.toml"))
def test_run_installs_project_from_pyproject(self, mock_exists, mock_run_command):
"""

View File

@@ -4,7 +4,7 @@ import os
import unittest
from unittest.mock import patch, mock_open
from pkgmgr.actions.repository.install.capabilities import (
from pkgmgr.actions.install.capabilities import (
PythonRuntimeCapability,
MakeInstallCapability,
NixFlakeCapability,
@@ -31,7 +31,7 @@ class TestCapabilitiesDetectors(unittest.TestCase):
def setUp(self):
self.ctx = DummyCtx("/tmp/repo")
@patch("pkgmgr.actions.repository.install.capabilities.os.path.exists")
@patch("pkgmgr.actions.install.capabilities.os.path.exists")
def test_python_runtime_python_layer_pyproject(self, mock_exists):
"""PythonRuntimeCapability: python layer is provided if pyproject.toml exists."""
cap = PythonRuntimeCapability()
@@ -47,8 +47,8 @@ class TestCapabilitiesDetectors(unittest.TestCase):
self.assertFalse(cap.is_provided(self.ctx, "nix"))
self.assertFalse(cap.is_provided(self.ctx, "os-packages"))
@patch("pkgmgr.actions.repository.install.capabilities._read_text_if_exists")
@patch("pkgmgr.actions.repository.install.capabilities.os.path.exists")
@patch("pkgmgr.actions.install.capabilities._read_text_if_exists")
@patch("pkgmgr.actions.install.capabilities.os.path.exists")
def test_python_runtime_nix_layer_flake(self, mock_exists, mock_read):
"""
PythonRuntimeCapability: nix layer is provided if flake.nix contains
@@ -65,7 +65,7 @@ class TestCapabilitiesDetectors(unittest.TestCase):
self.assertTrue(cap.applies_to_layer("nix"))
self.assertTrue(cap.is_provided(self.ctx, "nix"))
@patch("pkgmgr.actions.repository.install.capabilities.os.path.exists", return_value=True)
@patch("pkgmgr.actions.install.capabilities.os.path.exists", return_value=True)
@patch(
"builtins.open",
new_callable=mock_open,
@@ -78,7 +78,7 @@ class TestCapabilitiesDetectors(unittest.TestCase):
self.assertTrue(cap.applies_to_layer("makefile"))
self.assertTrue(cap.is_provided(self.ctx, "makefile"))
@patch("pkgmgr.actions.repository.install.capabilities.os.path.exists")
@patch("pkgmgr.actions.install.capabilities.os.path.exists")
def test_nix_flake_capability_on_nix_layer(self, mock_exists):
"""NixFlakeCapability: nix layer is provided if flake.nix exists."""
cap = NixFlakeCapability()
@@ -153,7 +153,7 @@ class TestDetectCapabilities(unittest.TestCase):
},
)
with patch("pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", [dummy1, dummy2]):
with patch("pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS", [dummy1, dummy2]):
caps = detect_capabilities(self.ctx, layers)
self.assertEqual(
@@ -221,7 +221,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
)
with patch(
"pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS",
"pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS",
[cap_make_install, cap_python_runtime, cap_nix_flake],
):
effective = resolve_effective_capabilities(self.ctx, layers)
@@ -258,7 +258,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
)
with patch(
"pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS",
"pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS",
[cap_python_runtime],
):
effective = resolve_effective_capabilities(self.ctx, layers)
@@ -283,7 +283,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
},
)
with patch("pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", [cap_only_make]):
with patch("pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS", [cap_only_make]):
effective = resolve_effective_capabilities(self.ctx, layers)
self.assertEqual(effective["makefile"], {"make-install"})
@@ -306,7 +306,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
},
)
with patch("pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS", [cap_only_nix]):
with patch("pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS", [cap_only_nix]):
effective = resolve_effective_capabilities(self.ctx, layers)
self.assertEqual(effective["makefile"], set())
@@ -337,7 +337,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
)
with patch(
"pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS",
"pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS",
[cap_python_runtime],
):
effective = resolve_effective_capabilities(self.ctx, layers)
@@ -359,7 +359,7 @@ class TestResolveEffectiveCapabilities(unittest.TestCase):
)
with patch(
"pkgmgr.actions.repository.install.capabilities.CAPABILITY_MATCHERS",
"pkgmgr.actions.install.capabilities.CAPABILITY_MATCHERS",
[cap_dummy],
):
effective = resolve_effective_capabilities(self.ctx)

View File

@@ -1,5 +1,5 @@
import unittest
from pkgmgr.actions.repository.install.context import RepoContext
from pkgmgr.actions.install.context import RepoContext
class TestRepoContext(unittest.TestCase):

View File

@@ -6,7 +6,7 @@ import unittest
from typing import Any, Dict, List
from unittest.mock import MagicMock, patch
from pkgmgr.actions.repository.install import install_repos
from pkgmgr.actions.install import install_repos
Repository = Dict[str, Any]
@@ -31,12 +31,12 @@ class TestInstallReposOrchestration(unittest.TestCase):
}
self.all_repos: List[Repository] = [self.repo1, self.repo2]
@patch("pkgmgr.actions.repository.install.InstallationPipeline")
@patch("pkgmgr.actions.repository.install.clone_repos")
@patch("pkgmgr.actions.repository.install.get_repo_dir")
@patch("pkgmgr.actions.repository.install.os.path.exists", return_value=True)
@patch("pkgmgr.actions.install.InstallationPipeline")
@patch("pkgmgr.actions.install.clone_repos")
@patch("pkgmgr.actions.install.get_repo_dir")
@patch("pkgmgr.actions.install.os.path.exists", return_value=True)
@patch(
"pkgmgr.actions.repository.install.verify_repository",
"pkgmgr.actions.install.verify_repository",
return_value=(True, [], "hash", "key"),
)
def test_install_repos_runs_pipeline_for_each_repo(
@@ -79,12 +79,12 @@ class TestInstallReposOrchestration(unittest.TestCase):
pipeline_instance = mock_pipeline_cls.return_value
self.assertEqual(pipeline_instance.run.call_count, len(selected))
@patch("pkgmgr.actions.repository.install.InstallationPipeline")
@patch("pkgmgr.actions.repository.install.clone_repos")
@patch("pkgmgr.actions.repository.install.get_repo_dir")
@patch("pkgmgr.actions.repository.install.os.path.exists", return_value=True)
@patch("pkgmgr.actions.install.InstallationPipeline")
@patch("pkgmgr.actions.install.clone_repos")
@patch("pkgmgr.actions.install.get_repo_dir")
@patch("pkgmgr.actions.install.os.path.exists", return_value=True)
@patch(
"pkgmgr.actions.repository.install.verify_repository",
"pkgmgr.actions.install.verify_repository",
return_value=(False, ["invalid signature"], None, None),
)
@patch("builtins.input", return_value="n")

View File

@@ -4,7 +4,7 @@
import os
import unittest
from pkgmgr.actions.repository.install.layers import (
from pkgmgr.actions.install.layers import (
CliLayer,
CLI_LAYERS,
classify_command_layer,

View File

@@ -4,10 +4,10 @@
import unittest
from unittest.mock import MagicMock, patch
from pkgmgr.actions.repository.install.context import RepoContext
from pkgmgr.actions.repository.install.installers.base import BaseInstaller
from pkgmgr.actions.repository.install.layers import CliLayer
from pkgmgr.actions.repository.install.pipeline import InstallationPipeline
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.base import BaseInstaller
from pkgmgr.actions.install.layers import CliLayer
from pkgmgr.actions.install.pipeline import InstallationPipeline
class DummyInstaller(BaseInstaller):
@@ -61,8 +61,8 @@ def _minimal_context() -> RepoContext:
class TestInstallationPipeline(unittest.TestCase):
@patch("pkgmgr.actions.repository.install.pipeline.create_ink")
@patch("pkgmgr.actions.repository.install.pipeline.resolve_command_for_repo")
@patch("pkgmgr.actions.install.pipeline.create_ink")
@patch("pkgmgr.actions.install.pipeline.resolve_command_for_repo")
def test_create_ink_called_when_command_resolved(
self,
mock_resolve_command_for_repo: MagicMock,
@@ -86,8 +86,8 @@ class TestInstallationPipeline(unittest.TestCase):
"/usr/local/bin/test-repo",
)
@patch("pkgmgr.actions.repository.install.pipeline.create_ink")
@patch("pkgmgr.actions.repository.install.pipeline.resolve_command_for_repo")
@patch("pkgmgr.actions.install.pipeline.create_ink")
@patch("pkgmgr.actions.install.pipeline.resolve_command_for_repo")
def test_lower_priority_installers_are_skipped_if_cli_exists(
self,
mock_resolve_command_for_repo: MagicMock,
@@ -116,8 +116,8 @@ class TestInstallationPipeline(unittest.TestCase):
)
self.assertEqual(ctx.repo.get("command"), "/usr/bin/test-repo")
@patch("pkgmgr.actions.repository.install.pipeline.create_ink")
@patch("pkgmgr.actions.repository.install.pipeline.resolve_command_for_repo")
@patch("pkgmgr.actions.install.pipeline.create_ink")
@patch("pkgmgr.actions.install.pipeline.resolve_command_for_repo")
def test_capabilities_prevent_duplicate_installers(
self,
mock_resolve_command_for_repo: MagicMock,