49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
import sys
|
|
import unittest
|
|
from unittest.mock import patch, MagicMock
|
|
import gui_2
|
|
|
|
class TestHeadlessStartup(unittest.TestCase):
|
|
|
|
@patch('gui_2.immapp.run')
|
|
@patch('gui_2.api_hooks.HookServer')
|
|
@patch('gui_2.save_config')
|
|
@patch('gui_2.ai_client.cleanup')
|
|
@patch('uvicorn.run') # Mock uvicorn.run to prevent hanging
|
|
def test_headless_flag_prevents_gui_run(self, mock_uvicorn_run, mock_cleanup, mock_save_config, mock_hook_server, mock_immapp_run):
|
|
# Setup mock argv with --headless
|
|
test_args = ["gui_2.py", "--headless"]
|
|
|
|
with patch.object(sys, 'argv', test_args):
|
|
with patch('gui_2.session_logger.close_session'), \
|
|
patch('gui_2.session_logger.open_session'):
|
|
app = gui_2.App()
|
|
|
|
# Mock _fetch_models to avoid network calls
|
|
app._fetch_models = MagicMock()
|
|
|
|
app.run()
|
|
|
|
# Expectation: immapp.run should NOT be called in headless mode
|
|
mock_immapp_run.assert_not_called()
|
|
# Expectation: uvicorn.run SHOULD be called
|
|
mock_uvicorn_run.assert_called_once()
|
|
|
|
@patch('gui_2.immapp.run')
|
|
def test_normal_startup_calls_gui_run(self, mock_immapp_run):
|
|
test_args = ["gui_2.py"]
|
|
with patch.object(sys, 'argv', test_args):
|
|
# In normal mode, it should still call immapp.run
|
|
with patch('gui_2.api_hooks.HookServer'), \
|
|
patch('gui_2.save_config'), \
|
|
patch('gui_2.ai_client.cleanup'), \
|
|
patch('gui_2.session_logger.close_session'), \
|
|
patch('gui_2.session_logger.open_session'):
|
|
app = gui_2.App()
|
|
app._fetch_models = MagicMock()
|
|
app.run()
|
|
mock_immapp_run.assert_called_once()
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|