@@ -38,8 +38,38 @@ def __init__(self, root, text):
3838 self .text .undo_block_stop = mock .Mock ()
3939
4040
41- class ZZDummyMixin :
42- """Shared tests for ZzDummy with default and user configs."""
41+ class ZZDummyTest (unittest .TestCase ):
42+
43+ @classmethod
44+ def setUpClass (cls ):
45+ requires ('gui' )
46+ root = cls .root = Tk ()
47+ root .withdraw ()
48+ text = cls .text = Text (cls .root )
49+ cls .editor = DummyEditwin (root , text )
50+ zzdummy .idleConf .userCfg = testcfg
51+
52+ @classmethod
53+ def tearDownClass (cls ):
54+ zzdummy .idleConf .userCfg = usercfg
55+ del cls .editor , cls .text
56+ cls .root .update_idletasks ()
57+ for id in cls .root .tk .call ('after' , 'info' ):
58+ cls .root .after_cancel (id ) # Need for EditorWindow.
59+ cls .root .destroy ()
60+ del cls .root
61+
62+ def setUp (self ):
63+ text = self .text
64+ text .insert ('1.0' , code_sample )
65+ text .undo_block_start .reset_mock ()
66+ text .undo_block_stop .reset_mock ()
67+ zz = self .zz = zzdummy .ZzDummy (self .editor )
68+ zzdummy .ZzDummy .ztext = '# ignore #'
69+
70+ def tearDown (self ):
71+ self .text .delete ('1.0' , 'end' )
72+ del self .zz
4373
4474 def checklines (self , text , value ):
4575 # Verify that there are lines being checked.
@@ -59,8 +89,7 @@ def test_init(self):
5989
6090 def test_reload (self ):
6191 self .assertEqual (self .zz .ztext , '# ignore #' )
62- zzdummy .idleConf .userCfg ['extensions' ].SetOption (
63- 'ZzDummy' , 'z-text' , 'spam' )
92+ testcfg ['extensions' ].SetOption ('ZzDummy' , 'z-text' , 'spam' )
6493 zzdummy .ZzDummy .reload ()
6594 self .assertEqual (self .zz .ztext , 'spam' )
6695
@@ -119,75 +148,5 @@ def test_roundtrip(self):
119148 self .assertEqual (text .get ('1.0' , 'end-1c' ), code_sample )
120149
121150
122- class ZZDummyTest (ZZDummyMixin , unittest .TestCase ):
123-
124- @classmethod
125- def setUpClass (cls ):
126- requires ('gui' )
127- root = cls .root = Tk ()
128- root .withdraw ()
129- text = cls .text = Text (cls .root )
130- cls .editor = DummyEditwin (root , text )
131- zzdummy .idleConf .userCfg = testcfg
132-
133- @classmethod
134- def tearDownClass (cls ):
135- zzdummy .idleConf .userCfg = usercfg
136- del cls .editor , cls .text
137- cls .root .update_idletasks ()
138- for id in cls .root .after_info ():
139- cls .root .after_cancel (id ) # Need for EditorWindow.
140- cls .root .destroy ()
141- del cls .root
142-
143- def setUp (self ):
144- text = self .text
145- text .insert ('1.0' , code_sample )
146- text .undo_block_start .reset_mock ()
147- text .undo_block_stop .reset_mock ()
148- zz = self .zz = zzdummy .ZzDummy (self .editor )
149- zzdummy .ZzDummy .ztext = '# ignore #'
150-
151- def tearDown (self ):
152- self .text .delete ('1.0' , 'end' )
153- del self .zz
154-
155- def test_exists (self ):
156- conf = zzdummy .idleConf
157- self .assertEqual (
158- conf .GetSectionList ('user' , 'extensions' ), [])
159- self .assertEqual (
160- conf .GetSectionList ('default' , 'extensions' ),
161- ['AutoComplete' , 'CodeContext' , 'FormatParagraph' ,
162- 'ParenMatch' , 'ZzDummy' , 'ZzDummy_cfgBindings' ,
163- 'ZzDummy_bindings' ])
164- self .assertIn ("ZzDummy" , conf .GetExtensions (False ))
165- self .assertNotIn ("ZzDummy" , conf .GetExtensions ())
166- self .assertEqual (
167- conf .GetExtensionKeys ("ZzDummy" ), {})
168- self .assertEqual (
169- conf .GetExtensionBindings ("ZzDummy" ),
170- {'<<z-out>>' : ['<Control-Shift-KeyRelease-Delete>' ]})
171-
172- def test_exists_user (self ):
173- conf = zzdummy .idleConf
174- conf .userCfg ["extensions" ].read_dict ({
175- "ZzDummy" : {'enable' : 'True' }
176- })
177- self .assertEqual (
178- conf .GetSectionList ('user' , 'extensions' ),
179- ["ZzDummy" ])
180- self .assertIn ("ZzDummy" , conf .GetExtensions ())
181- self .assertEqual (
182- conf .GetExtensionKeys ("ZzDummy" ),
183- {'<<z-in>>' : ['<Control-Shift-KeyRelease-Insert>' ]})
184- self .assertEqual (
185- conf .GetExtensionBindings ("ZzDummy" ),
186- {'<<z-in>>' : ['<Control-Shift-KeyRelease-Insert>' ],
187- '<<z-out>>' : ['<Control-Shift-KeyRelease-Delete>' ]})
188- # Restore
189- conf .userCfg ["extensions" ].remove_section ("ZzDummy" )
190-
191-
192151if __name__ == '__main__' :
193152 unittest .main (verbosity = 2 )
0 commit comments