11
11
from idlelib .idle_test .mock_idle import Func
12
12
from tkinter import Tk , IntVar , BooleanVar , DISABLED , NORMAL
13
13
from idlelib import config
14
- from idlelib .configdialog import ConfigDialog , idleConf , changes , VarTrace
14
+ from idlelib .configdialog import idleConf , changes , tracers
15
15
16
16
# Tests should not depend on fortuitous user configurations.
17
17
# They must not affect actual user .cfg files.
@@ -35,12 +35,12 @@ def setUpModule():
35
35
idleConf .userCfg = testcfg
36
36
root = Tk ()
37
37
# root.withdraw() # Comment out, see issue 30870
38
- dialog = ConfigDialog (root , 'Test' , _utest = True )
38
+ dialog = configdialog . ConfigDialog (root , 'Test' , _utest = True )
39
39
40
40
def tearDownModule ():
41
41
global root , dialog
42
42
idleConf .userCfg = usercfg
43
- dialog . remove_var_callbacks ()
43
+ tracers . detach ()
44
44
del dialog
45
45
root .update_idletasks ()
46
46
root .destroy ()
@@ -423,14 +423,14 @@ def test_update_help_changes(self):
423
423
d .update_help_changes = Func ()
424
424
425
425
426
- class TestVarTrace (unittest .TestCase ):
426
+ class VarTraceTest (unittest .TestCase ):
427
427
428
428
def setUp (self ):
429
429
changes .clear ()
430
+ tracers .clear ()
430
431
self .v1 = IntVar (root )
431
432
self .v2 = BooleanVar (root )
432
433
self .called = 0
433
- self .tracers = VarTrace ()
434
434
435
435
def tearDown (self ):
436
436
del self .v1 , self .v2
@@ -442,11 +442,19 @@ def var_changed_boolean(self, *params):
442
442
pass
443
443
444
444
def test_init (self ):
445
- self .assertEqual (self .tracers .untraced , [])
446
- self .assertEqual (self .tracers .traced , [])
445
+ tracers .__init__ ()
446
+ self .assertEqual (tracers .untraced , [])
447
+ self .assertEqual (tracers .traced , [])
448
+
449
+ def test_clear (self ):
450
+ tracers .untraced .append (0 )
451
+ tracers .traced .append (1 )
452
+ tracers .clear ()
453
+ self .assertEqual (tracers .untraced , [])
454
+ self .assertEqual (tracers .traced , [])
447
455
448
456
def test_add (self ):
449
- tr = self . tracers
457
+ tr = tracers
450
458
func = Func ()
451
459
cb = tr .make_callback = mock .Mock (return_value = func )
452
460
@@ -469,8 +477,7 @@ def test_add(self):
469
477
del tr .make_callback
470
478
471
479
def test_make_callback (self ):
472
- tr = self .tracers
473
- cb = tr .make_callback (self .v1 , ('main' , 'section' , 'option' ))
480
+ cb = tracers .make_callback (self .v1 , ('main' , 'section' , 'option' ))
474
481
self .assertTrue (callable (cb ))
475
482
self .v1 .set (42 )
476
483
# Not attached, so set didn't invoke the callback.
@@ -481,7 +488,7 @@ def test_make_callback(self):
481
488
self .assertEqual (changes ['main' ]['section' ]['option' ], '42' )
482
489
483
490
def test_attach_detach (self ):
484
- tr = self . tracers
491
+ tr = tracers
485
492
v1 = tr .add (self .v1 , self .var_changed_increment )
486
493
v2 = tr .add (self .v2 , self .var_changed_boolean )
487
494
expected = [(v1 , self .var_changed_increment ),
0 commit comments