From fd4b9e217433c389df3d17e6108adac3abece7e0 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Sat, 21 Mar 2026 22:08:41 -0700 Subject: [PATCH] Add tests for handling interface absence and keyboard interrupts in start function --- tests/test_main.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index 658693a..7f90efd 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -186,6 +186,15 @@ class MainRuntimeTests(unittest.TestCase): wrapper.assert_called_once_with(entrypoint.main) interface.close.assert_called_once_with() + def test_start_does_not_crash_when_wrapper_returns_without_interface(self) -> None: + interface_state.interface = None + + with mock.patch.object(entrypoint.sys, "argv", ["contact"]): + with mock.patch.object(entrypoint.curses, "wrapper") as wrapper: + entrypoint.start() + + wrapper.assert_called_once_with(entrypoint.main) + def test_main_returns_cleanly_when_user_closes_missing_node_dialog(self) -> None: stdscr = mock.Mock() args = Namespace(settings=False, demo_screenshot=False) @@ -215,6 +224,18 @@ class MainRuntimeTests(unittest.TestCase): interface.close.assert_called_once_with() exit_mock.assert_called_once_with(0) + def test_start_handles_keyboard_interrupt_with_no_interface(self) -> None: + interface_state.interface = None + + with mock.patch.object(entrypoint.sys, "argv", ["contact"]): + with mock.patch.object(entrypoint.curses, "wrapper", side_effect=KeyboardInterrupt): + with mock.patch.object(entrypoint.sys, "exit", side_effect=SystemExit(0)) as exit_mock: + with self.assertRaises(SystemExit) as raised: + entrypoint.start() + + self.assertEqual(raised.exception.code, 0) + exit_mock.assert_called_once_with(0) + def test_start_handles_fatal_exception_and_exits_one(self) -> None: with mock.patch.object(entrypoint.sys, "argv", ["contact"]): with mock.patch.object(entrypoint.curses, "wrapper", side_effect=RuntimeError("boom")):