44import tkinter as tk
55from unittest .mock import MagicMock , patch
66
7- # Ensure the project root is in sys.path so we can import the PICA modules
7+ # Ensure the project root is in sys.path
88project_root = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' ))
99if project_root not in sys .path :
1010 sys .path .insert (0 , project_root )
1111
1212# Try importing the Launcher. If it fails due to imports, we skip.
1313try :
14- from PICALauncher import PICALauncherApp
14+ from PICA_v6 import PICALauncherApp
1515except ImportError :
1616 PICALauncherApp = None
1717
1818@pytest .fixture
1919def mock_app_dependencies ():
2020 """
21- Mocks the heavy dependencies that PICALauncherApp might use,
22- such as the PIL image loader or subprocess calls.
21+ Mocks the heavy dependencies: PIL, Subprocess, AND Fonts.
2322 """
2423 with patch ('PIL.Image.open' , MagicMock ()), \
2524 patch ('PIL.ImageTk.PhotoImage' , MagicMock ()), \
26- patch ('subprocess.Popen' , MagicMock ()):
25+ patch ('subprocess.Popen' , MagicMock ()), \
26+ patch ('tkinter.font.Font' , MagicMock ()): # <--- FIX: Mock Font creation
2727 yield
2828
2929def test_pica_launcher_initialization (mock_app_dependencies ):
3030 """
3131 Tests if the PICALauncherApp initializes without errors.
32-
33- CRITICAL FIX: We patch 'tkinter.Tk' so it doesn't try to open a real window
34- on the headless GitHub Actions server.
3532 """
3633 if PICALauncherApp is None :
37- pytest .skip ("PICALauncherApp could not be imported (likely missing dependencies) ." )
34+ pytest .skip ("PICALauncherApp could not be imported." )
3835
39- # FIX: Patch tk.Tk to prevent 'no display name' error
36+ # Patch tk.Tk to prevent 'no display name' error on headless servers
4037 with patch ('tkinter.Tk' ) as MockTk :
41- # Create the mock root
4238 mock_root = MockTk .return_value
4339
4440 # Initialize the app with the mocked root
41+ # This will now succeed because font.Font() is also mocked
4542 app = PICALauncherApp (mock_root )
4643
4744 # ASSERTIONS
48- # 1. Did it attach to the root?
4945 assert app .root == mock_root
50-
51- # 2. Did it set a title? (Check if title() was called on the mock)
52- # Note: Depending on your implementation, it might be app.root.title(...)
53- # We just check if the app object exists successfully.
5446 assert app is not None
5547
56- print ("\n [SUCCESS] PICALauncherApp initialized safely with Mock Tk." )
48+ print ("\n [SUCCESS] PICALauncherApp initialized safely with Mock Tk and Mock Font ." )
0 commit comments