Files
pkgmgr/tests/unit/pkgmgr/actions/install/installers/test_makefile_installer.py
T
kevinveenbirkenbachandClaude Opus 5 b778ad7dbe fix(install): treat install-* as what it is, not as an install target
The detection accepted any target starting with install-, while the run
below it has always called plain make install. A repository carrying
install-python and no install therefore pulled the installer in and died on
"No rule to make target 'install'" instead of being skipped, which is what
the surrounding branch is there for. meta-infinite-graph, universal-logout
and file-dedupe all failed this way, and with them two e2e tests.

775c301 added the parsing to run make install only where an install target
exists. The prefix arm undid that, so it goes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-01 17:45:42 +02:00

100 lines
3.3 KiB
Python

# tests/unit/pkgmgr/installers/test_makefile_installer.py
import os
import unittest
from unittest.mock import mock_open, patch
from pkgmgr.actions.install.context import RepoContext
from pkgmgr.actions.install.installers.makefile import MakefileInstaller
class TestMakefileInstaller(unittest.TestCase):
def setUp(self):
self.repo = {"name": "test-repo"}
self.ctx = RepoContext(
repo=self.repo,
identifier="test-id",
repo_dir="/tmp/repo",
repositories_base_dir="/tmp",
bin_dir="/bin",
all_repos=[self.repo],
no_verification=False,
preview=False,
quiet=False,
clone_mode="ssh",
update_dependencies=False,
)
self.installer = MakefileInstaller()
# @patch("os.path.exists", return_value=True)
# def test_supports_true_when_makefile_exists(self, mock_exists):
# self.assertTrue(self.installer.supports(self.ctx))
# mock_exists.assert_called_with(os.path.join(self.ctx.repo_dir, "Makefile"))
@patch("os.path.exists", return_value=False)
def test_supports_false_when_makefile_missing(self, mock_exists):
self.assertFalse(self.installer.supports(self.ctx))
@patch("pkgmgr.actions.install.installers.makefile.run_command")
@patch(
"builtins.open",
new_callable=mock_open,
read_data="install:\n\t@echo 'installing'\n",
)
@patch("os.path.exists", return_value=True)
def test_run_executes_make_install_when_target_present(
self, mock_exists, mock_file, mock_run_command
):
self.installer.run(self.ctx)
# Ensure we checked the Makefile and then called make install.
mock_file.assert_called_once_with(
os.path.join(self.ctx.repo_dir, "Makefile"),
encoding="utf-8",
errors="ignore",
)
cmd = mock_run_command.call_args[0][0]
self.assertEqual(cmd, "make install")
self.assertEqual(
mock_run_command.call_args[1].get("cwd"),
self.ctx.repo_dir,
)
@patch("pkgmgr.actions.install.installers.makefile.run_command")
@patch(
"builtins.open",
new_callable=mock_open,
read_data="all:\n\t@echo 'nothing here'\n",
)
@patch("os.path.exists", return_value=True)
def test_run_skips_when_no_install_target(
self, mock_exists, mock_file, mock_run_command
):
self.installer.run(self.ctx)
# 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"),
encoding="utf-8",
errors="ignore",
)
mock_run_command.assert_not_called()
@patch("pkgmgr.actions.install.installers.makefile.run_command")
@patch(
"builtins.open",
new_callable=mock_open,
read_data="install-python:\n\tpip install -r requirements.txt\n",
)
@patch("os.path.exists", return_value=True)
def test_run_skips_a_makefile_that_only_has_a_prefixed_target(
self, mock_exists, mock_file, mock_run_command
):
self.installer.run(self.ctx)
mock_run_command.assert_not_called()
if __name__ == "__main__":
unittest.main()