WIP: I HATE PYTHON

This commit is contained in:
2026-03-05 13:55:40 -05:00
parent 107608cd76
commit 5e69617f88
43 changed files with 1854 additions and 1671 deletions

View File

@@ -12,12 +12,11 @@ from pathlib import Path
from typing import Generator, Any
from unittest.mock import patch
# Ensure project root and src/ are in path for imports
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
# Import the App class after patching if necessary, but here we just need the type hint
from gui_2 import App
from src.gui_2 import App
class VerificationLogger:
def __init__(self, test_name: str, script_name: str) -> None:
@@ -62,8 +61,8 @@ def reset_ai_client() -> Generator[None, None, None]:
Autouse fixture that resets the ai_client global state before each test.
This is critical for preventing state pollution between tests.
"""
import ai_client
import mcp_client
from src import ai_client
from src import mcp_client
ai_client.reset_session()
# Reset callbacks to None or default to ensure no carry-over
ai_client.confirm_and_run_callback = None
@@ -115,10 +114,10 @@ def mock_app() -> Generator[App, None, None]:
'projects': {'paths': [], 'active': ''},
'gui': {'show_windows': {}}
}),
patch('gui_2.save_config'),
patch('gui_2.project_manager'),
patch('gui_2.session_logger'),
patch('gui_2.immapp.run'),
patch('src.gui_2.save_config'),
patch('src.gui_2.project_manager'),
patch('src.gui_2.session_logger'),
patch('src.gui_2.immapp.run'),
patch('src.app_controller.AppController._load_active_project'),
patch('src.app_controller.AppController._fetch_models'),
patch.object(App, '_load_fonts'),
@@ -126,7 +125,7 @@ def mock_app() -> Generator[App, None, None]:
patch('src.app_controller.AppController._prune_old_logs'),
patch('src.app_controller.AppController.start_services'),
patch('src.app_controller.AppController._init_ai_and_hooks'),
patch('gui_2.PerformanceMonitor')
patch('src.performance_monitor.PerformanceMonitor')
):
app = App()
yield app
@@ -147,10 +146,10 @@ def app_instance() -> Generator[App, None, None]:
'projects': {'paths': [], 'active': ''},
'gui': {'show_windows': {}}
}),
patch('gui_2.save_config'),
patch('gui_2.project_manager'),
patch('gui_2.session_logger'),
patch('gui_2.immapp.run'),
patch('src.gui_2.save_config'),
patch('src.gui_2.project_manager'),
patch('src.gui_2.session_logger'),
patch('src.gui_2.immapp.run'),
patch('src.app_controller.AppController._load_active_project'),
patch('src.app_controller.AppController._fetch_models'),
patch.object(App, '_load_fonts'),
@@ -158,37 +157,16 @@ def app_instance() -> Generator[App, None, None]:
patch('src.app_controller.AppController._prune_old_logs'),
patch('src.app_controller.AppController.start_services'),
patch('src.app_controller.AppController._init_ai_and_hooks'),
patch('gui_2.PerformanceMonitor')
patch('src.performance_monitor.PerformanceMonitor')
):
app = App()
yield app
# Cleanup: Ensure background threads and asyncio loop are stopped
# Cleanup: Ensure background threads are stopped
if hasattr(app, 'controller'):
app.controller.shutdown()
if hasattr(app, 'shutdown'):
app.shutdown()
# Use controller._loop for cleanup
loop = getattr(app.controller, '_loop', None) if hasattr(app, 'controller') else None
if loop and not loop.is_closed():
tasks = [t for t in asyncio.all_tasks(loop) if not t.done()]
if tasks:
# Cancel tasks so they can be gathered
for task in tasks:
task.cancel()
# We can't really run the loop if it's already stopping or thread is dead,
# but we try to be clean.
try:
if loop.is_running():
loop.call_soon_threadsafe(loop.stop)
except: pass
# Finally close the loop if we can
try:
if not loop.is_running():
loop.close()
except: pass
@pytest.fixture(scope="session")
def live_gui() -> Generator[tuple[subprocess.Popen, str], None, None]:
@@ -301,7 +279,7 @@ def live_gui() -> Generator[tuple[subprocess.Popen, str], None, None]:
print(f"\n[Fixture] Finally block triggered: Shutting down {gui_script}...")
# Reset the GUI state before shutting down
try:
from api_hook_client import ApiHookClient
from src.api_hook_client import ApiHookClient
client = ApiHookClient()
client.reset_session()
time.sleep(0.5)