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

Method test_widget_destroy

Lib/test/test_ttk/test_extensions.py:17–52  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

15 super().tearDown()
16
17 def test_widget_destroy(self):
18 # automatically created variable
19 x = ttk.LabeledScale(self.root)
20 var = x._variable._name
21 x.destroy()
22 gc_collect() # For PyPy or other GCs.
23 self.assertRaises(tkinter.TclError, x.tk.globalgetvar, var)
24
25 # manually created variable
26 myvar = tkinter.DoubleVar(self.root)
27 name = myvar._name
28 x = ttk.LabeledScale(self.root, variable=myvar)
29 x.destroy()
30 if self.wantobjects:
31 self.assertEqual(x.tk.globalgetvar(name), myvar.get())
32 else:
33 self.assertEqual(float(x.tk.globalgetvar(name)), myvar.get())
34 del myvar
35 gc_collect() # For PyPy or other GCs.
36 self.assertRaises(tkinter.TclError, x.tk.globalgetvar, name)
37
38 # checking that the tracing callback is properly removed
39 myvar = tkinter.IntVar(self.root)
40 # LabeledScale will start tracing myvar
41 x = ttk.LabeledScale(self.root, variable=myvar)
42 x.destroy()
43 # Unless the tracing callback was removed, creating a new
44 # LabeledScale with the same var will cause an error now. This
45 # happens because the variable will be set to (possibly) a new
46 # value which causes the tracing callback to be called and then
47 # it tries calling instance attributes not yet defined.
48 ttk.LabeledScale(self.root, variable=myvar)
49 if hasattr(sys, 'last_exc'):
50 self.assertNotEqual(type(sys.last_exc), tkinter.TclError)
51 elif hasattr(sys, 'last_type'):
52 self.assertNotEqual(sys.last_type, tkinter.TclError)
53
54 def test_initialization(self):
55 # master passing

Callers

nothing calls this directly

Calls 6

destroyMethod · 0.95
getMethod · 0.95
gc_collectFunction · 0.90
assertNotEqualMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected