from typing import Generator import pytest from unittest.mock import patch, MagicMock from gui_2 import App def test_cb_ticket_retry(app_instance: App) -> None: ticket_id = "test_ticket_1" app_instance.active_tickets = [{"id": ticket_id, "status": "failed"}] with patch('asyncio.run_coroutine_threadsafe') as mock_run_safe: app_instance._cb_ticket_retry(ticket_id) # Verify status update assert app_instance.active_tickets[0]['status'] == 'todo' # Verify event pushed mock_run_safe.assert_called_once() # First arg is the coroutine (event_queue.put), second is self._loop args, _ = mock_run_safe.call_args assert args[1] == app_instance._loop def test_cb_ticket_skip(app_instance: App) -> None: ticket_id = "test_ticket_1" app_instance.active_tickets = [{"id": ticket_id, "status": "todo"}] with patch('asyncio.run_coroutine_threadsafe') as mock_run_safe: app_instance._cb_ticket_skip(ticket_id) # Verify status update assert app_instance.active_tickets[0]['status'] == 'skipped' # Verify event pushed mock_run_safe.assert_called_once() args, _ = mock_run_safe.call_args assert args[1] == app_instance._loop