56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
"""Google Workspace setup delegates dependency ownership to PM."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
from unittest.mock import Mock
|
|
|
|
import pm
|
|
import pytest
|
|
|
|
|
|
SETUP_PATH = (
|
|
Path(__file__).resolve().parents[2]
|
|
/ "skills/productivity/google-workspace/scripts/setup.py"
|
|
)
|
|
|
|
|
|
@pytest.fixture()
|
|
def setup_module(monkeypatch):
|
|
# setup.py exposes sibling imports for direct script execution.
|
|
monkeypatch.syspath_prepend(str(SETUP_PATH.parent))
|
|
spec = importlib.util.spec_from_file_location("google_workspace_setup", SETUP_PATH)
|
|
assert spec is not None and spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
@pytest.mark.parametrize("error", [None, pm.InstallError("venv", "sync refused")])
|
|
def test_explicit_install_uses_pm_and_reports_restart(setup_module, monkeypatch, capsys, error):
|
|
sync = Mock(side_effect=error)
|
|
monkeypatch.setattr(pm, "sync_venv", sync)
|
|
# Even a successful old-interpreter probe must not bypass explicit sync.
|
|
monkeypatch.setattr(pm, "ensure_import", Mock(side_effect=AssertionError("not a sync")))
|
|
monkeypatch.setattr("subprocess.check_call", Mock(side_effect=AssertionError("ambient install")))
|
|
|
|
assert setup_module.install_deps() is (error is None)
|
|
sync.assert_called_once_with(["google"], explicit=True)
|
|
output = capsys.readouterr().out
|
|
if error is None:
|
|
assert "restart" in output.lower()
|
|
else:
|
|
assert "sync refused" in output
|
|
|
|
|
|
def test_auth_uses_pm_import_check(setup_module, monkeypatch):
|
|
ensure = Mock()
|
|
monkeypatch.setattr(pm, "ensure_import", ensure)
|
|
monkeypatch.setattr(pm, "sync_venv", Mock(side_effect=AssertionError("explicit sync during auth")))
|
|
monkeypatch.setattr("subprocess.check_call", Mock(side_effect=AssertionError("ambient install")))
|
|
|
|
setup_module._ensure_deps()
|
|
|
|
ensure.assert_called_once_with("google")
|