chore(legacy): Remove gui_legacy.py and refactor all tests to use gui_2.py
This commit is contained in:
@@ -1,53 +1,35 @@
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
from typing import Generator
|
||||
import dearpygui.dearpygui as dpg
|
||||
from gui_legacy import App
|
||||
from typing import Generator, Any
|
||||
from gui_2 import App
|
||||
import ai_client
|
||||
|
||||
# Ensure project root is in path
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
@pytest.fixture
|
||||
def app_instance() -> Generator[App, None, None]:
|
||||
"""
|
||||
Fixture to create an instance of the App class for testing.
|
||||
It creates a real DPG context but mocks functions that would
|
||||
render a window or block execution.
|
||||
"""
|
||||
dpg.create_context()
|
||||
with patch('dearpygui.dearpygui.create_viewport'), \
|
||||
patch('dearpygui.dearpygui.setup_dearpygui'), \
|
||||
patch('dearpygui.dearpygui.show_viewport'), \
|
||||
patch('dearpygui.dearpygui.start_dearpygui'), \
|
||||
patch('gui_legacy.load_config', return_value={}), \
|
||||
patch('gui_legacy.PerformanceMonitor'), \
|
||||
patch('gui_legacy.shell_runner'), \
|
||||
patch('gui_legacy.project_manager'), \
|
||||
patch.object(App, '_load_active_project'), \
|
||||
patch.object(App, '_rebuild_files_list'), \
|
||||
patch.object(App, '_rebuild_shots_list'), \
|
||||
patch.object(App, '_rebuild_disc_list'), \
|
||||
patch.object(App, '_rebuild_disc_roles_list'), \
|
||||
patch.object(App, '_rebuild_discussion_selector'), \
|
||||
patch.object(App, '_refresh_project_widgets'):
|
||||
Fixture to create an instance of the App class for testing.
|
||||
"""
|
||||
with patch('gui_2.load_config', return_value={}), \
|
||||
patch('gui_2.PerformanceMonitor'), \
|
||||
patch('gui_2.session_logger'), \
|
||||
patch.object(App, '_prune_old_logs'), \
|
||||
patch.object(App, '_load_active_project'):
|
||||
app = App()
|
||||
yield app
|
||||
dpg.destroy_context()
|
||||
|
||||
def test_gui_updates_on_event(app_instance: App) -> None:
|
||||
with patch('dearpygui.dearpygui.set_value') as mock_set_value, \
|
||||
patch('dearpygui.dearpygui.does_item_exist', return_value=True), \
|
||||
patch('dearpygui.dearpygui.configure_item'), \
|
||||
patch('ai_client.get_history_bleed_stats') as mock_stats:
|
||||
mock_stats.return_value = {"percentage": 50.0, "current": 500, "limit": 1000}
|
||||
# We'll use patch.object to see if _refresh_api_metrics is called
|
||||
with patch.object(app_instance, '_refresh_api_metrics', wraps=app_instance._refresh_api_metrics) as mock_refresh:
|
||||
mock_stats = {"percentage": 50.0, "current": 500, "limit": 1000}
|
||||
app_instance.last_md = "mock_md"
|
||||
with patch('ai_client.get_token_stats', return_value=mock_stats) as mock_get_stats:
|
||||
# Simulate event
|
||||
ai_client.events.emit("response_received", payload={})
|
||||
# Process tasks manually
|
||||
app_instance._process_pending_gui_tasks()
|
||||
# Verify that _refresh_api_metrics was called
|
||||
mock_refresh.assert_called_once()
|
||||
# Verify that dpg.set_value was called for the metrics widgets
|
||||
calls = [call.args[0] for call in mock_set_value.call_args_list]
|
||||
assert "token_budget_bar" in calls
|
||||
assert "token_budget_label" in calls
|
||||
ai_client.events.emit("response_received", payload={"text": "test"})
|
||||
# Process tasks manually
|
||||
app_instance._process_pending_gui_tasks()
|
||||
# Verify that _token_stats was updated (via _refresh_api_metrics)
|
||||
assert app_instance._token_stats["percentage"] == 50.0
|
||||
assert app_instance._token_stats["current"] == 500
|
||||
|
||||
Reference in New Issue
Block a user