chore(tests): Final stabilization of test suite and full isolation of live_gui artifacts
This commit is contained in:
@@ -12,6 +12,9 @@ from pathlib import Path
|
||||
from typing import Generator, Any
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
# Ensure project root is in path for imports
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
# Import the App class after patching if necessary, but here we just need the type hint
|
||||
from gui_2 import App
|
||||
|
||||
@@ -79,7 +82,7 @@ def kill_process_tree(pid: int | None) -> None:
|
||||
print(f"[Fixture] Error killing process tree {pid}: {e}")
|
||||
|
||||
@pytest.fixture
|
||||
def mock_app() -> App:
|
||||
def mock_app() -> Generator[App, None, None]:
|
||||
"""
|
||||
Mock version of the App for simple unit tests that don't need a loop.
|
||||
"""
|
||||
@@ -98,9 +101,13 @@ def mock_app() -> App:
|
||||
patch.object(App, '_load_fonts'),
|
||||
patch.object(App, '_post_init'),
|
||||
patch.object(App, '_prune_old_logs'),
|
||||
patch.object(App, '_init_ai_and_hooks')
|
||||
patch.object(App, '_init_ai_and_hooks'),
|
||||
patch('gui_2.PerformanceMonitor')
|
||||
):
|
||||
return App()
|
||||
app = App()
|
||||
yield app
|
||||
if hasattr(app, 'shutdown'):
|
||||
app.shutdown()
|
||||
|
||||
@pytest.fixture
|
||||
def app_instance() -> Generator[App, None, None]:
|
||||
@@ -123,7 +130,8 @@ def app_instance() -> Generator[App, None, None]:
|
||||
patch.object(App, '_load_fonts'),
|
||||
patch.object(App, '_post_init'),
|
||||
patch.object(App, '_prune_old_logs'),
|
||||
patch.object(App, '_init_ai_and_hooks')
|
||||
patch.object(App, '_init_ai_and_hooks'),
|
||||
patch('gui_2.PerformanceMonitor')
|
||||
):
|
||||
app = App()
|
||||
yield app
|
||||
@@ -171,6 +179,11 @@ def live_gui() -> Generator[tuple[subprocess.Popen, str], None, None]:
|
||||
(temp_workspace / "manual_slop.toml").write_text("[project]\nname = 'TestProject'\n", encoding="utf-8")
|
||||
(temp_workspace / "conductor" / "tracks").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Preserve GUI layout for tests
|
||||
layout_file = Path("manualslop_layout.ini")
|
||||
if layout_file.exists():
|
||||
shutil.copy2(layout_file, temp_workspace / layout_file.name)
|
||||
|
||||
# Check if already running (shouldn't be)
|
||||
try:
|
||||
resp = requests.get("http://127.0.0.1:8999/status", timeout=0.1)
|
||||
@@ -180,7 +193,8 @@ def live_gui() -> Generator[tuple[subprocess.Popen, str], None, None]:
|
||||
|
||||
print(f"\n[Fixture] Starting {gui_script} --enable-test-hooks in {temp_workspace}...")
|
||||
os.makedirs("logs", exist_ok=True)
|
||||
log_file = open(f"logs/{gui_script.replace('.', '_')}_test.log", "w", encoding="utf-8")
|
||||
log_file_name = Path(gui_script).name.replace('.', '_')
|
||||
log_file = open(f"logs/{log_file_name}_test.log", "w", encoding="utf-8")
|
||||
|
||||
# Use environment variable to point to temp config if App supports it,
|
||||
# or just run from that CWD.
|
||||
|
||||
Reference in New Issue
Block a user