MCPcopy Index your code
hub / github.com/python/cpython / test_after

Method test_after

Lib/test/test_tkinter/test_misc.py:134–179  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

132 root.tk_setPalette, highlightColor='blue')
133
134 def test_after(self):
135 root = self.root
136
137 def callback(start=0, step=1, *, end=0):
138 nonlocal count
139 count = start + step + end
140
141 # Without function, sleeps for ms.
142 self.assertIsNone(root.after(1))
143
144 # Set up with callback with no args.
145 count = 0
146 timer1 = root.after(0, callback)
147 self.assertIn(timer1, root.tk.call('after', 'info'))
148 (script, _) = root.tk.splitlist(root.tk.call('after', 'info', timer1))
149 root.update() # Process all pending events.
150 self.assertEqual(count, 1)
151 with self.assertRaises(tkinter.TclError):
152 root.tk.call(script)
153
154 # Set up with callback with args.
155 count = 0
156 timer1 = root.after(0, callback, 42, 11)
157 root.update() # Process all pending events.
158 self.assertEqual(count, 53)
159
160 # Cancel before called.
161 timer1 = root.after(1000, callback)
162 self.assertIn(timer1, root.tk.call('after', 'info'))
163 (script, _) = root.tk.splitlist(root.tk.call('after', 'info', timer1))
164 root.after_cancel(timer1) # Cancel this event.
165 self.assertEqual(count, 53)
166 with self.assertRaises(tkinter.TclError):
167 root.tk.call(script)
168
169 # Call with a callable class
170 count = 0
171 timer1 = root.after(0, functools.partial(callback, 42, 11))
172 root.update() # Process all pending events.
173 self.assertEqual(count, 53)
174
175 # Set up with callback with keyword args.
176 count = 0
177 timer1 = root.after(0, callback, 42, step=11, end=1)
178 root.update() # Process all pending events.
179 self.assertEqual(count, 54)
180
181 def test_after_idle(self):
182 root = self.root

Callers

nothing calls this directly

Calls 10

assertIsNoneMethod · 0.80
afterMethod · 0.80
assertInMethod · 0.80
splitlistMethod · 0.80
after_cancelMethod · 0.80
partialMethod · 0.80
callMethod · 0.45
updateMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected