import pytest from unittest.mock import patch, MagicMock import importlib.util import sys import os from typing import Any # Ensure project root is in path for imports sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) # Load gui_2.py as a module for testing spec = importlib.util.spec_from_file_location("gui_2", "gui_2.py") gui_2 = importlib.util.module_from_spec(spec) sys.modules["gui_2"] = gui_2 spec.loader.exec_module(gui_2) from gui_2 import App @pytest.fixture def app_instance() -> Any: 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 def test_diagnostics_panel_initialization(app_instance: Any) -> None: assert "Diagnostics" in app_instance.show_windows assert "frame_time" in app_instance.perf_history assert len(app_instance.perf_history["frame_time"]) == 100 def test_diagnostics_history_updates(app_instance: Any) -> None: """ Verifies that the internal performance history is updated correctly. This logic is inside the render loop in gui_2.py, but we can test the data structure and initialization. """ assert "fps" in app_instance.perf_history assert len(app_instance.perf_history["fps"]) == 100 # Test pushing a value manually as a surrogate for the render loop app_instance.perf_history["fps"].pop(0) app_instance.perf_history["fps"].append(60.0) assert app_instance.perf_history["fps"][-1] == 60.0