Skip to content

Commit da61136

Browse files
PICA GUI test added
1 parent 3033914 commit da61136

2 files changed

Lines changed: 63 additions & 8 deletions

File tree

tests/test_full_stack_simulation.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22
import sys
33
import os
44
import importlib
5-
from unittest.mock import MagicMock, patch, mock_open
5+
import pytest
6+
from unittest.mock import MagicMock, patch, mock_open, PropertyMock
67

7-
# -------------------------------------------------------------------------
8-
# 1. GLOBAL MOCKS (The "Headless" GUI Trick)
9-
# -------------------------------------------------------------------------
10-
sys.modules['tkinter'] = MagicMock()
11-
sys.modules['tkinter.ttk'] = MagicMock()
12-
sys.modules['tkinter.messagebox'] = MagicMock()
13-
sys.modules['tkinter.filedialog'] = MagicMock()
148

159
# Matplotlib Mocks
10+
@pytest.fixture(autouse=True)
11+
def mock_gui_libraries():
12+
"""
13+
This fixture mocks the entire tkinter and matplotlib libraries to prevent
14+
any GUI windows from being created during tests. It is applied automatically
15+
to all tests within this file.
16+
"""
17+
with patch.dict('sys.modules', {
18+
'tkinter': MagicMock(),
19+
'tkinter.ttk': MagicMock(),
20+
'tkinter.messagebox': MagicMock(),
21+
'tkinter.filedialog': MagicMock(),
22+
}):
23+
yield
24+
25+
1626
class TestDeepSimulation(unittest.TestCase):
1727

1828
def setUp(self):

tests/test_pica_launcher.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# tests/test_pica_launcher.py
2+
"""
3+
Unit tests for the main PICA Launcher GUI application.
4+
5+
These tests are designed to run in a CI environment, so they use mocking
6+
to prevent the GUI from entering its main loop and blocking the test runner.
7+
"""
8+
9+
import tkinter as tk
10+
from unittest.mock import patch, MagicMock
11+
import pytest
12+
13+
# The PICA_v6.py file contains the main PICALauncherApp
14+
from PICA_v6 import PICALauncherApp
15+
16+
17+
@pytest.fixture
18+
def mock_app_dependencies():
19+
"""
20+
Pytest fixture to mock dependencies that would block or interfere with
21+
a non-interactive test run.
22+
"""
23+
# Mock methods that would create new windows, run blocking loops, or
24+
# perform file I/O.
25+
with patch('tkinter.Tk.mainloop', MagicMock()), \
26+
patch('PICA_v6.PICALauncherApp.run_gpib_test', MagicMock()), \
27+
patch('PICA_v6.PICALauncherApp._load_logo', MagicMock()), \
28+
patch('PICA_v6.PICALauncherApp._pre_cache_markdown_files', MagicMock()):
29+
yield
30+
31+
32+
def test_pica_launcher_initialization(mock_app_dependencies):
33+
"""
34+
Tests if the PICALauncherApp initializes without errors.
35+
36+
It confirms that the main window is created and that key widgets
37+
like the console are initialized.
38+
"""
39+
root = tk.Tk()
40+
app = PICALauncherApp(root)
41+
42+
# --- Assertions ---
43+
assert app is not None, "PICALauncherApp failed to initialize."
44+
assert app.root.title() == f"PICA Launcher v{app.PROGRAM_VERSION}", "Window title was not set correctly."
45+
assert app.console_widget is not None, "Console widget was not created during initialization."

0 commit comments

Comments
 (0)