33from tkinter import messagebox , ttk
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 , AbstractDialogTest
77from tkinter .simpledialog import (Dialog , SimpleDialog ,
88 askinteger , askfloat , askstring ,
99 _QueryInteger , _QueryFloat , _QueryString ,
1212requires ('gui' )
1313
1414
15- class SimpleDialogTest (AbstractTkTest , unittest .TestCase ):
15+ class SimpleDialogTest (AbstractDialogTest , unittest .TestCase ):
1616 # SimpleDialog's modal loop is in go(); its bindings are exercised here by
1717 # generating events on the constructed dialog, without entering the loop.
1818
@@ -45,8 +45,8 @@ def test_use_ttk(self):
4545 ttk .Style (d .root ).lookup ('.' , 'background' ))
4646 # The bindings work with the themed buttons too.
4747 self .require_mapped (d .root )
48- d ._buttons [0 ].focus_force ()
4948 d .root .update ()
49+ d ._buttons [0 ].focus_force ()
5050 d .root .event_generate ('<Return>' )
5151 d .root .update ()
5252 self .assertEqual (d .num , 0 )
@@ -144,8 +144,8 @@ def test_alt_key(self):
144144 # the matching button (cf. tk::AmpWidget in tk::MessageBox).
145145 d = self .create (buttons = ['Yes' , {'text' : 'No' , 'underline' : 0 }])
146146 self .require_mapped (d .root )
147- d ._buttons [0 ].focus_force ()
148147 d .root .update ()
148+ d ._buttons [0 ].focus_force ()
149149 d .root .event_generate ('<Alt-n>' ) # "No" -> underline 0 -> "N"
150150 d .root .update ()
151151 self .assertEqual (d .num , 1 )
@@ -155,8 +155,8 @@ def test_return_invokes_focused_button(self):
155155 # default and the focus was not moved by keyboard traversal.
156156 d = self .create (buttons = ['Yes' , 'No' ]) # default 0
157157 self .require_mapped (d .root )
158- d ._buttons [1 ].focus_force ()
159158 d .root .update ()
159+ d ._buttons [1 ].focus_force ()
160160 d .root .event_generate ('<Return>' )
161161 d .root .update ()
162162 self .assertEqual (d .num , 1 )
@@ -165,8 +165,8 @@ def test_focus_next_then_return(self):
165165 # <Tab> moves the focus to the next button; <Return> invokes it.
166166 d = self .create (buttons = ['Yes' , 'No' ])
167167 self .require_mapped (d .root )
168- d ._buttons [0 ].focus_force ()
169168 d .root .update ()
169+ d ._buttons [0 ].focus_force ()
170170 d ._buttons [0 ].event_generate ('<Tab>' )
171171 d .root .update ()
172172 d .root .event_generate ('<Return>' )
@@ -177,8 +177,8 @@ def test_focus_prev_then_return(self):
177177 # <Shift-Tab> moves the focus to the previous button.
178178 d = self .create (buttons = ['Yes' , 'No' ])
179179 self .require_mapped (d .root )
180- d ._buttons [1 ].focus_force ()
181180 d .root .update ()
181+ d ._buttons [1 ].focus_force ()
182182 d ._buttons [1 ].event_generate ('<Shift-Tab>' )
183183 d .root .update ()
184184 d .root .event_generate ('<Return>' )
@@ -189,8 +189,8 @@ def test_return_activates_default(self):
189189 # <Return> with the focus off the buttons invokes the default button.
190190 d = self .create () # default 0
191191 self .require_mapped (d .root )
192- d .root .focus_force () # the dialog, not a button, has the focus
193192 d .root .update ()
193+ d .root .focus_force () # the dialog, not a button, has the focus
194194 d .root .event_generate ('<Return>' )
195195 d .root .update ()
196196 self .assertEqual (d .num , 0 )
@@ -246,7 +246,7 @@ def test_go(self):
246246 self .assertEqual (d .go (), 0 )
247247
248248
249- class DialogTest (AbstractTkTest , unittest .TestCase ):
249+ class DialogTest (AbstractDialogTest , unittest .TestCase ):
250250 # Dialog's button box is modelled on tk::MessageBox.
251251
252252 def open (self , ** kw ):
@@ -279,8 +279,8 @@ def test_use_classic(self):
279279 invoked = []
280280 cancel = d .children ['cancel' ]
281281 cancel .configure (command = lambda : invoked .append (True ))
282- cancel .focus_force ()
283282 d .update ()
283+ cancel .focus_force ()
284284 d .event_generate ('<Return>' )
285285 d .update ()
286286 self .assertTrue (invoked )
@@ -359,8 +359,8 @@ def test_alt_key(self):
359359 invoked = []
360360 cancel = d .children ['cancel' ] # "&Cancel"
361361 cancel .configure (command = lambda : invoked .append (True ))
362- d .focus_force ()
363362 d .update ()
363+ d .focus_force ()
364364 d .event_generate ('<Alt-c>' )
365365 d .update ()
366366 self .assertTrue (invoked )
@@ -371,8 +371,8 @@ def test_return_invokes_focused_button(self):
371371 invoked = []
372372 cancel = d .children ['cancel' ]
373373 cancel .configure (command = lambda : invoked .append (True ))
374- cancel .focus_force ()
375374 d .update ()
375+ cancel .focus_force ()
376376 d .event_generate ('<Return>' )
377377 d .update ()
378378 self .assertEqual (invoked , [True ])
@@ -384,8 +384,8 @@ def test_focus_next_then_return(self):
384384 for name in ('ok' , 'cancel' ):
385385 d .children [name ].configure (command = lambda name = name : invoked .append (name ))
386386 ok = d .children ['ok' ]
387- ok .focus_force ()
388387 d .update ()
388+ ok .focus_force ()
389389 ok .event_generate ('<Tab>' ) # OK -> Cancel
390390 d .update ()
391391 d .event_generate ('<Return>' )
@@ -399,8 +399,8 @@ def test_focus_prev_then_return(self):
399399 for name in ('ok' , 'cancel' ):
400400 d .children [name ].configure (command = lambda name = name : invoked .append (name ))
401401 cancel = d .children ['cancel' ]
402- cancel .focus_force ()
403402 d .update ()
403+ cancel .focus_force ()
404404 cancel .event_generate ('<Shift-Tab>' ) # Cancel -> OK
405405 d .update ()
406406 d .event_generate ('<Return>' )
@@ -432,7 +432,7 @@ def mock_wait_window(w):
432432 self .assertRaises (RuntimeError , askinteger , "Go To Line" , "Line number" )
433433
434434
435- class QueryDialogTest (AbstractTkTest , unittest .TestCase ):
435+ class QueryDialogTest (AbstractDialogTest , unittest .TestCase ):
436436 # The query dialogs are modal: their __init__ blocks in wait_window().
437437 # Mock that out so the dialog stays alive and can be driven with generated
438438 # events, exercising the <Return>/<Escape> bindings and the validation.
0 commit comments