prole/tests/test_install_logic.py
chrisfu 906392d462 feat(installer): improve UI and add test coverage for core features
- Refactored installer UI with updated canvas rendering, sidebar navigation, and footer buttons.
- Enhanced styling for macOS compatibility and consistent design across controls.
- Added Pytest-based unit tests for `screen.py` and `config.py`.
- Expanded dependency catalog with new tools like `tshark` and `pyshark`.
- Improved error tolerance for background rendering and added placeholders for Kerberos configuration.
2026-01-08 21:51:30 -08:00

63 lines
2.4 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
sys.modules['tkinter'] = MagicMock()
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
import install
from install import ProleInstaller
@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 ProleInstaller.__init__ because it creates GUI elements
with patch.object(ProleInstaller, '__init__', return_value=None):
ins = ProleInstaller()
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):
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"