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