From: Serhiy Storchaka Date: Sun, 5 Jul 2026 10:51:34 +0000 (+0300) Subject: gh-69134: Wait until mapped in SimpleDialog keyboard tests (GH-152690) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d619c2fea131722d0bfdad150c081c44cc0abd7;p=thirdparty%2FPython%2Fcpython.git gh-69134: Wait until mapped in SimpleDialog keyboard tests (GH-152690) The SimpleDialog keyboard tests generate key events after focus_force(), which on Windows are dropped until the toplevel is mapped, so they could fail intermittently (seen on the Windows10 buildbot as test_return_no_default). Wait until the window is mapped in each of these tests, as GH-152599 did for the other keyboard tests. Co-authored-by: Claude Opus 4.8 --- diff --git a/Lib/test/test_tkinter/test_simpledialog.py b/Lib/test/test_tkinter/test_simpledialog.py index 5c739d9ad6e6..33a0173ba67a 100644 --- a/Lib/test/test_tkinter/test_simpledialog.py +++ b/Lib/test/test_tkinter/test_simpledialog.py @@ -44,6 +44,7 @@ class SimpleDialogTest(AbstractTkTest, unittest.TestCase): self.assertEqual(str(d.root.cget('background')), ttk.Style(d.root).lookup('.', 'background')) # The bindings work with the themed buttons too. + self.require_mapped(d.root) d._buttons[0].focus_force() d.root.update() d.root.event_generate('') @@ -139,6 +140,7 @@ class SimpleDialogTest(AbstractTkTest, unittest.TestCase): # Alt + an underlined character (the "underline" button option) invokes # the matching button (cf. tk::AmpWidget in tk::MessageBox). d = self.create(buttons=['Yes', {'text': 'No', 'underline': 0}]) + self.require_mapped(d.root) d._buttons[0].focus_force() d.root.update() d.root.event_generate('') # "No" -> underline 0 -> "N" @@ -149,6 +151,7 @@ class SimpleDialogTest(AbstractTkTest, unittest.TestCase): # invokes the button with the focus, even if it is not the # default and the focus was not moved by keyboard traversal. d = self.create(buttons=['Yes', 'No']) # default 0 + self.require_mapped(d.root) d._buttons[1].focus_force() d.root.update() d.root.event_generate('') @@ -158,6 +161,7 @@ class SimpleDialogTest(AbstractTkTest, unittest.TestCase): def test_focus_next_then_return(self): # moves the focus to the next button; invokes it. d = self.create(buttons=['Yes', 'No']) + self.require_mapped(d.root) d._buttons[0].focus_force() d.root.update() d._buttons[0].event_generate('') @@ -169,6 +173,7 @@ class SimpleDialogTest(AbstractTkTest, unittest.TestCase): def test_focus_prev_then_return(self): # moves the focus to the previous button. d = self.create(buttons=['Yes', 'No']) + self.require_mapped(d.root) d._buttons[1].focus_force() d.root.update() d._buttons[1].event_generate('') @@ -180,6 +185,7 @@ class SimpleDialogTest(AbstractTkTest, unittest.TestCase): def test_return_activates_default(self): # with the focus off the buttons invokes the default button. d = self.create() # default 0 + self.require_mapped(d.root) d.root.focus_force() # the dialog, not a button, has the focus d.root.update() d.root.event_generate('') @@ -190,6 +196,7 @@ class SimpleDialogTest(AbstractTkTest, unittest.TestCase): # With no default button, off the buttons rings the bell and # leaves the dialog open instead of activating a button. d = self.create(default=None) + self.require_mapped(d.root) d.root.focus_force() # the dialog, not a button, has the focus d.root.update() bells = []