Skip to content

Commit 7d619c2

Browse files
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 <noreply@anthropic.com>
1 parent 2ab620b commit 7d619c2

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Lib/test/test_tkinter/test_simpledialog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_use_ttk(self):
4444
self.assertEqual(str(d.root.cget('background')),
4545
ttk.Style(d.root).lookup('.', 'background'))
4646
# The bindings work with the themed buttons too.
47+
self.require_mapped(d.root)
4748
d._buttons[0].focus_force()
4849
d.root.update()
4950
d.root.event_generate('<Return>')
@@ -139,6 +140,7 @@ def test_alt_key(self):
139140
# Alt + an underlined character (the "underline" button option) invokes
140141
# the matching button (cf. tk::AmpWidget in tk::MessageBox).
141142
d = self.create(buttons=['Yes', {'text': 'No', 'underline': 0}])
143+
self.require_mapped(d.root)
142144
d._buttons[0].focus_force()
143145
d.root.update()
144146
d.root.event_generate('<Alt-n>') # "No" -> underline 0 -> "N"
@@ -149,6 +151,7 @@ def test_return_invokes_focused_button(self):
149151
# <Return> invokes the button with the focus, even if it is not the
150152
# default and the focus was not moved by keyboard traversal.
151153
d = self.create(buttons=['Yes', 'No']) # default 0
154+
self.require_mapped(d.root)
152155
d._buttons[1].focus_force()
153156
d.root.update()
154157
d.root.event_generate('<Return>')
@@ -158,6 +161,7 @@ def test_return_invokes_focused_button(self):
158161
def test_focus_next_then_return(self):
159162
# <Tab> moves the focus to the next button; <Return> invokes it.
160163
d = self.create(buttons=['Yes', 'No'])
164+
self.require_mapped(d.root)
161165
d._buttons[0].focus_force()
162166
d.root.update()
163167
d._buttons[0].event_generate('<Tab>')
@@ -169,6 +173,7 @@ def test_focus_next_then_return(self):
169173
def test_focus_prev_then_return(self):
170174
# <Shift-Tab> moves the focus to the previous button.
171175
d = self.create(buttons=['Yes', 'No'])
176+
self.require_mapped(d.root)
172177
d._buttons[1].focus_force()
173178
d.root.update()
174179
d._buttons[1].event_generate('<Shift-Tab>')
@@ -180,6 +185,7 @@ def test_focus_prev_then_return(self):
180185
def test_return_activates_default(self):
181186
# <Return> with the focus off the buttons invokes the default button.
182187
d = self.create() # default 0
188+
self.require_mapped(d.root)
183189
d.root.focus_force() # the dialog, not a button, has the focus
184190
d.root.update()
185191
d.root.event_generate('<Return>')
@@ -190,6 +196,7 @@ def test_return_no_default(self):
190196
# With no default button, <Return> off the buttons rings the bell and
191197
# leaves the dialog open instead of activating a button.
192198
d = self.create(default=None)
199+
self.require_mapped(d.root)
193200
d.root.focus_force() # the dialog, not a button, has the focus
194201
d.root.update()
195202
bells = []

0 commit comments

Comments
 (0)