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 / codesniffer-shellcheck (push) Has been cancelled
Mark stable commit / codesniffer-ruff (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
- Fix undefined repo_dir usage in repository deinstall action - Centralize and harden get_repo_dir with strict validation and clear errors - Expand user paths for repository base and binary directories - Add unit tests for get_repo_dir and deinstall_repos - Add comprehensive tests for resolve_repos identifier matching - Remove obsolete command resolution tests no longer applicable https://chatgpt.com/share/693d7442-c2d0-800f-9ff3-fb84d60eaeb4
80 lines
3.4 KiB
Python
80 lines
3.4 KiB
Python
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from pkgmgr.actions.repository.deinstall import deinstall_repos
|
|
|
|
|
|
class TestDeinstallRepos(unittest.TestCase):
|
|
def test_preview_removes_nothing_but_runs_make_if_makefile_exists(self):
|
|
repo = {"provider": "github.com", "account": "alice", "repository": "demo", "alias": "demo"}
|
|
selected = [repo]
|
|
|
|
with patch("pkgmgr.actions.repository.deinstall.get_repo_identifier", return_value="demo"), \
|
|
patch("pkgmgr.actions.repository.deinstall.get_repo_dir", return_value="/repos/github.com/alice/demo"), \
|
|
patch("pkgmgr.actions.repository.deinstall.os.path.expanduser", return_value="/home/u/.local/bin"), \
|
|
patch("pkgmgr.actions.repository.deinstall.os.path.exists") as mock_exists, \
|
|
patch("pkgmgr.actions.repository.deinstall.os.remove") as mock_remove, \
|
|
patch("pkgmgr.actions.repository.deinstall.run_command") as mock_run, \
|
|
patch("builtins.input", return_value="y"):
|
|
|
|
# alias exists, Makefile exists
|
|
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
|
|
|
|
mock_exists.side_effect = exists_side_effect
|
|
|
|
deinstall_repos(
|
|
selected_repos=selected,
|
|
repositories_base_dir="/repos",
|
|
bin_dir="~/.local/bin",
|
|
all_repos=selected,
|
|
preview=True,
|
|
)
|
|
|
|
# Preview: do not remove
|
|
mock_remove.assert_not_called()
|
|
|
|
# But still "would run" make deinstall via run_command (preview=True)
|
|
mock_run.assert_called_once_with(
|
|
"make deinstall",
|
|
cwd="/repos/github.com/alice/demo",
|
|
preview=True,
|
|
)
|
|
|
|
def test_non_preview_removes_alias_when_confirmed(self):
|
|
repo = {"provider": "github.com", "account": "alice", "repository": "demo", "alias": "demo"}
|
|
selected = [repo]
|
|
|
|
with patch("pkgmgr.actions.repository.deinstall.get_repo_identifier", return_value="demo"), \
|
|
patch("pkgmgr.actions.repository.deinstall.get_repo_dir", return_value="/repos/github.com/alice/demo"), \
|
|
patch("pkgmgr.actions.repository.deinstall.os.path.expanduser", return_value="/home/u/.local/bin"), \
|
|
patch("pkgmgr.actions.repository.deinstall.os.path.exists") as mock_exists, \
|
|
patch("pkgmgr.actions.repository.deinstall.os.remove") as mock_remove, \
|
|
patch("pkgmgr.actions.repository.deinstall.run_command") as mock_run, \
|
|
patch("builtins.input", return_value="y"):
|
|
|
|
# alias exists, Makefile does NOT exist
|
|
def exists_side_effect(path):
|
|
if path == "/home/u/.local/bin/demo":
|
|
return True
|
|
if path == "/repos/github.com/alice/demo/Makefile":
|
|
return False
|
|
return False
|
|
|
|
mock_exists.side_effect = exists_side_effect
|
|
|
|
deinstall_repos(
|
|
selected_repos=selected,
|
|
repositories_base_dir="/repos",
|
|
bin_dir="~/.local/bin",
|
|
all_repos=selected,
|
|
preview=False,
|
|
)
|
|
|
|
mock_remove.assert_called_once_with("/home/u/.local/bin/demo")
|
|
mock_run.assert_not_called()
|