From 1f31477658632be75db3e8ff50d4b3195120fc5f Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sat, 13 Jun 2026 14:42:47 -0600 Subject: [PATCH] Test pygame showOptions selection paths showOptions is the pygame UI's primary menu loop and was the last interactive method with no coverage. Its three input paths now have tests (events injected via the patched pygame.event.get): a number key selects directly, arrow-down + Enter moves the highlight and confirms it, and an out-of-range number key is ignored until a valid choice is pressed. With this, the pygame front-end's resize/font helpers and all four interactive primitives (showOptions / showDialogue / promptForText / timedKeyPress) are covered. Co-Authored-By: Claude Sonnet 4.6 --- tests/ui/test_pygameUserInterface.py | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/ui/test_pygameUserInterface.py b/tests/ui/test_pygameUserInterface.py index 1db615c..eac6d87 100644 --- a/tests/ui/test_pygameUserInterface.py +++ b/tests/ui/test_pygameUserInterface.py @@ -129,3 +129,35 @@ def test_promptForText_handles_backspace(): assert result == "a" finally: ui.cleanup() + + +def test_showOptions_number_key_selects_directly(): + ui = makeUI() + try: + with injected_events([keydown(key=pygame.K_2)]): + choice = ui.showOptions("Pick", ["A", "B", "C"]) + assert choice == "2" + finally: + ui.cleanup() + + +def test_showOptions_arrow_then_enter_selects(): + ui = makeUI() + try: + # down moves the highlight from option 1 to option 2, Enter confirms it + with injected_events([keydown(key=pygame.K_DOWN), keydown(key=pygame.K_RETURN)]): + choice = ui.showOptions("Pick", ["A", "B", "C"]) + assert choice == "2" + finally: + ui.cleanup() + + +def test_showOptions_ignores_out_of_range_number(): + ui = makeUI() + try: + # "9" exceeds the 2 options and is ignored; "1" then selects + with injected_events([keydown(key=pygame.K_9), keydown(key=pygame.K_1)]): + choice = ui.showOptions("Pick", ["A", "B"]) + assert choice == "1" + finally: + ui.cleanup()