Deleted deprecated unit tests:
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
https://chatgpt.com/share/693efe80-d928-800f-98b7-0aaafee1d32a
This commit is contained in:
@@ -115,105 +115,7 @@ class TestNixFlakeInstaller(unittest.TestCase):
|
||||
|
||||
install_cmds = self._install_cmds_from_calls(subproc_mock.call_args_list)
|
||||
self.assertEqual(install_cmds, [f"nix profile install {self.repo_dir}#default"])
|
||||
|
||||
def test_nix_flake_run_mandatory_failure_raises(self) -> None:
|
||||
"""
|
||||
For a generic repository, 'default' is mandatory.
|
||||
A non-zero return code must raise SystemExit with that code.
|
||||
"""
|
||||
ctx = DummyCtx(identifier="some-lib", repo_dir=self.repo_dir)
|
||||
installer = NixFlakeInstaller()
|
||||
|
||||
# retry layer does one attempt (non-403), then fallback does final attempt => 2 installs
|
||||
install_results = [self._cp(1), self._cp(1)]
|
||||
|
||||
def fake_subprocess_run(cmd, *args, **kwargs):
|
||||
if isinstance(cmd, str) and cmd.startswith("nix profile list --json"):
|
||||
return self._cp(0, stdout='{"elements": []}', stderr="")
|
||||
if isinstance(cmd, str) and cmd.startswith("nix profile install "):
|
||||
return install_results.pop(0)
|
||||
return self._cp(0)
|
||||
|
||||
buf = io.StringIO()
|
||||
with patch("pkgmgr.actions.install.installers.nix.installer.shutil.which") as which_mock, patch(
|
||||
"pkgmgr.actions.install.installers.nix.installer.os.path.exists", return_value=True
|
||||
), patch(
|
||||
"pkgmgr.actions.install.installers.nix.runner.subprocess.run", side_effect=fake_subprocess_run
|
||||
) as subproc_mock, redirect_stdout(buf):
|
||||
self._enable_nix_in_module(which_mock)
|
||||
|
||||
self.assertTrue(installer.supports(ctx))
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
installer.run(ctx)
|
||||
|
||||
self.assertEqual(cm.exception.code, 1)
|
||||
|
||||
out = buf.getvalue()
|
||||
self.assertIn("[nix] install: nix profile install", out)
|
||||
self.assertIn("[ERROR] Failed to install Nix flake output 'default' (exit 1)", out)
|
||||
|
||||
install_cmds = self._install_cmds_from_calls(subproc_mock.call_args_list)
|
||||
self.assertEqual(
|
||||
install_cmds,
|
||||
[
|
||||
f"nix profile install {self.repo_dir}#default",
|
||||
f"nix profile install {self.repo_dir}#default",
|
||||
],
|
||||
)
|
||||
|
||||
def test_nix_flake_run_optional_failure_does_not_raise(self) -> None:
|
||||
"""
|
||||
For pkgmgr/package-manager repositories:
|
||||
- 'pkgmgr' output is mandatory
|
||||
- 'default' output is optional
|
||||
Failure of optional output must not raise.
|
||||
"""
|
||||
ctx = DummyCtx(identifier="pkgmgr", repo_dir=self.repo_dir)
|
||||
installer = NixFlakeInstaller()
|
||||
|
||||
# pkgmgr success (1 call), default fails (2 calls: attempt + final)
|
||||
install_results = [self._cp(0), self._cp(1), self._cp(1)]
|
||||
|
||||
def fake_subprocess_run(cmd, *args, **kwargs):
|
||||
if isinstance(cmd, str) and cmd.startswith("nix profile list --json"):
|
||||
return self._cp(0, stdout='{"elements": []}', stderr="")
|
||||
if isinstance(cmd, str) and cmd.startswith("nix profile install "):
|
||||
return install_results.pop(0)
|
||||
return self._cp(0)
|
||||
|
||||
buf = io.StringIO()
|
||||
with patch("pkgmgr.actions.install.installers.nix.installer.shutil.which") as which_mock, patch(
|
||||
"pkgmgr.actions.install.installers.nix.installer.os.path.exists", return_value=True
|
||||
), patch(
|
||||
"pkgmgr.actions.install.installers.nix.runner.subprocess.run", side_effect=fake_subprocess_run
|
||||
) as subproc_mock, redirect_stdout(buf):
|
||||
self._enable_nix_in_module(which_mock)
|
||||
|
||||
self.assertTrue(installer.supports(ctx))
|
||||
installer.run(ctx) # must NOT raise
|
||||
|
||||
out = buf.getvalue()
|
||||
|
||||
# Should announce both outputs
|
||||
self.assertIn("ensuring outputs: pkgmgr, default", out)
|
||||
|
||||
# First output ok
|
||||
self.assertIn("[nix] output 'pkgmgr' successfully installed.", out)
|
||||
|
||||
# Second output failed but no raise
|
||||
self.assertIn("[ERROR] Failed to install Nix flake output 'default' (exit 1)", out)
|
||||
self.assertIn("[WARNING] Continuing despite failure of optional output 'default'.", out)
|
||||
|
||||
install_cmds = self._install_cmds_from_calls(subproc_mock.call_args_list)
|
||||
self.assertEqual(
|
||||
install_cmds,
|
||||
[
|
||||
f"nix profile install {self.repo_dir}#pkgmgr",
|
||||
f"nix profile install {self.repo_dir}#default",
|
||||
f"nix profile install {self.repo_dir}#default",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def test_nix_flake_supports_respects_disable_env(self) -> None:
|
||||
"""
|
||||
PKGMGR_DISABLE_NIX_FLAKE_INSTALLER=1 must disable the installer,
|
||||
|
||||
Reference in New Issue
Block a user