33from tkinter import messagebox
44from test .support import requires , swap_attr
55from test .test_tkinter .support import setUpModule # noqa: F401
6- from test .test_tkinter .support import AbstractDefaultRootTest , AbstractTkTest
6+ from test .test_tkinter .support import (AbstractDefaultRootTest ,
7+ AbstractDialogTest , AbstractTkTest )
78from tkinter .simpledialog import (Dialog , SimpleDialog ,
89 askinteger , askfloat , askstring ,
910 _QueryInteger , _QueryFloat , _QueryString )
1213
1314
1415class SimpleDialogTest (AbstractTkTest , unittest .TestCase ):
16+ # The root window is not hidden here (cf. AbstractDialogTest): SimpleDialog
17+ # makes its window transient for the master unconditionally, and a
18+ # transient of a hidden window is never mapped on Windows, so that go()
19+ # would block in wait_visibility().
1520 # SimpleDialog's modal loop is in go(); its bindings are exercised here by
1621 # generating events on the constructed dialog, without entering the loop.
1722
@@ -50,8 +55,8 @@ def test_return_activates_default(self):
5055 # <Return> invokes the default button.
5156 d = self .create () # default 0
5257 self .require_mapped (d .root )
53- d .root .focus_force ()
5458 d .root .update ()
59+ d .root .focus_force ()
5560 d .root .event_generate ('<Return>' )
5661 d .root .update ()
5762 self .assertEqual (d .num , 0 )
@@ -61,10 +66,9 @@ def test_return_no_default(self):
6166 # open instead of activating a button.
6267 d = self .create (default = None )
6368 self .require_mapped (d .root )
64- d .root .focus_force ()
65- d .root .update ()
6669 bells = []
6770 with swap_attr (d .root , 'bell' , lambda * a , ** k : bells .append (True )):
71+ d .root .focus_force ()
6872 d .root .event_generate ('<Return>' )
6973 d .root .update ()
7074 self .assertTrue (bells ) # rang the bell
@@ -98,7 +102,7 @@ def test_go(self):
98102 self .assertEqual (d .go (), 0 )
99103
100104
101- class DialogTest (AbstractTkTest , unittest .TestCase ):
105+ class DialogTest (AbstractDialogTest , unittest .TestCase ):
102106 # Dialog is a base class for custom dialogs; exercise it via _QueryInteger.
103107
104108 def open (self , ** kw ):
@@ -167,7 +171,7 @@ def mock_wait_window(w):
167171 self .assertRaises (RuntimeError , askinteger , "Go To Line" , "Line number" )
168172
169173
170- class QueryDialogTest (AbstractTkTest , unittest .TestCase ):
174+ class QueryDialogTest (AbstractDialogTest , unittest .TestCase ):
171175 # The query dialogs are modal: their __init__ blocks in wait_window().
172176 # Mock that out so the dialog stays alive and can be driven with generated
173177 # events, exercising the <Return>/<Escape> bindings and the validation.
0 commit comments