mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 11:03:59 +00:00
- improve installer/action/controller flow and shell-variable expansion handling across screens\n- adjust Supabase Helm rendering and storage deployment templates\n- align monitoring, cloudnative-pg and repair pipeline behavior with updated config paths\n- refresh and expand installer/core regression tests around milestones, navigation and repair logic Co-authored-by: Junie <junie@jetbrains.com>
77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
import sys
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
# Mock tkinter and other GUI/macOS specific imports before they are imported in install.py
|
|
mock_tk = MagicMock()
|
|
mock_tk.Entry.return_value.get.return_value.strip.return_value = "mock_val"
|
|
mock_tk.StringVar.return_value.get.return_value.strip.return_value = "mock_val"
|
|
sys.modules["tkinter"] = mock_tk
|
|
sys.modules["tkinter.ttk"] = MagicMock()
|
|
sys.modules["tkinter.scrolledtext"] = MagicMock()
|
|
sys.modules["tkinter.messagebox"] = MagicMock()
|
|
sys.modules["Foundation"] = MagicMock()
|
|
sys.modules["objc"] = MagicMock()
|
|
|
|
import os
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
# Now import install.py after mocking
|
|
from install import KnoeInstaller
|
|
|
|
|
|
@pytest.fixture
|
|
def installer(tmp_path):
|
|
# Mocking os.environ to avoid messing with real env
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
# We need to mock KnoeInstaller.__init__ because it creates GUI elements
|
|
with patch.object(KnoeInstaller, "__init__", return_value=None):
|
|
ins = KnoeInstaller()
|
|
# Core helpers expect `inputs` to exist; bypassing `__init__` means
|
|
# we must seed minimal state for method calls.
|
|
ins.inputs = {}
|
|
return ins
|
|
|
|
|
|
def test_resolve_prole_home_default(installer):
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
# Path.home() might vary, so we just check it ends with .prole if no env var
|
|
home = installer.resolve_prole_home()
|
|
assert home.name == ".prole"
|
|
|
|
|
|
def test_resolve_prole_home_env(installer):
|
|
custom_home = "/tmp/custom_prole"
|
|
with patch.dict(os.environ, {"PROLE_HOME": custom_home}):
|
|
home = installer.resolve_prole_home()
|
|
assert str(home) == custom_home
|
|
|
|
|
|
def test_env_defaults(installer):
|
|
with patch.dict(os.environ, {}, clear=True), patch.object(
|
|
installer, "_read_existing_env", return_value={}
|
|
):
|
|
defaults = installer._env_defaults()
|
|
assert "PROLE_HOME" in defaults
|
|
assert defaults["PROLE_HOME"].endswith(".prole")
|
|
assert defaults["PROLE_CONF"].endswith(".prole/conf")
|
|
|
|
|
|
def test_read_existing_env_no_file(installer, tmp_path):
|
|
# Ensure neither PROLE_HOME nor the default location has an env.sh for this test
|
|
with patch.dict(os.environ, {"PROLE_HOME": str(tmp_path)}):
|
|
with patch("pathlib.Path.home", return_value=tmp_path / "fake_home"):
|
|
env = installer._read_existing_env()
|
|
assert env == {}
|
|
|
|
|
|
def test_read_existing_env_with_file(installer, tmp_path):
|
|
env_sh = tmp_path / "env.sh"
|
|
env_sh.write_text('export VAR1="val1"\nVAR2=val2\n# comment\n')
|
|
|
|
with patch.dict(os.environ, {"PROLE_HOME": str(tmp_path)}):
|
|
with patch("pathlib.Path.home", return_value=tmp_path / "fake_home"):
|
|
env = installer._read_existing_env()
|
|
assert env.get("VAR1") == "val1"
|
|
assert env.get("VAR2") == "val2"
|