22from unittest .mock import patch , MagicMock
33import sys
44import os
5+ import runpy
56
67sys .path .insert (0 , os .path .abspath ('.' ))
78
@@ -51,14 +52,16 @@ def test_run_pica_main(mock_freeze_support, mock_set_start_method, mock_pica_lau
5152def test_run_pica_script ():
5253 """
5354 Tests that run_pica.py correctly initializes the main GUI.
54- We mock the GUI main loop so the test doesn't hang .
55+ We use runpy to execute the script file while patching the main function .
5556 """
57+ # Get the absolute path to run_pica.py
58+ # Assuming tests/ is one level deep, so we go up one level
59+ script_path = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , 'run_pica.py' ))
60+
61+ # Patch pica.main.main to prevent the real GUI from launching
5662 with patch ("pica.main.main" ) as mock_main :
57- # Simulate running the script logic
58- # If run_pica.py has a main() function, call it.
59- # If it runs on import, verify the mock was called.
60- if hasattr (run_pica , 'main' ):
61- run_pica .main ()
63+ # Execute the script as __main__
64+ runpy .run_path (script_path , run_name = "__main__" )
6265
6366 # Verify it attempted to start the PICA GUI
64- mock_main .assert_called_once ()
67+ mock_main .assert_called_once ()
0 commit comments