ยปCore Development>Code coverage>Lib/tkinter/test/support.py

Python code coverage for Lib/tkinter/test/support.py

#countcontent
1n/aimport re
2n/aimport tkinter
3n/aimport unittest
4n/a
5n/aclass AbstractTkTest:
6n/a
7n/a @classmethod
8n/a def setUpClass(cls):
9n/a cls._old_support_default_root = tkinter._support_default_root
10n/a destroy_default_root()
11n/a tkinter.NoDefaultRoot()
12n/a cls.root = tkinter.Tk()
13n/a cls.wantobjects = cls.root.wantobjects()
14n/a # De-maximize main window.
15n/a # Some window managers can maximize new windows.
16n/a cls.root.wm_state('normal')
17n/a try:
18n/a cls.root.wm_attributes('-zoomed', False)
19n/a except tkinter.TclError:
20n/a pass
21n/a
22n/a @classmethod
23n/a def tearDownClass(cls):
24n/a cls.root.update_idletasks()
25n/a cls.root.destroy()
26n/a del cls.root
27n/a tkinter._default_root = None
28n/a tkinter._support_default_root = cls._old_support_default_root
29n/a
30n/a def setUp(self):
31n/a self.root.deiconify()
32n/a
33n/a def tearDown(self):
34n/a for w in self.root.winfo_children():
35n/a w.destroy()
36n/a self.root.withdraw()
37n/a
38n/adef destroy_default_root():
39n/a if getattr(tkinter, '_default_root', None):
40n/a tkinter._default_root.update_idletasks()
41n/a tkinter._default_root.destroy()
42n/a tkinter._default_root = None
43n/a
44n/adef simulate_mouse_click(widget, x, y):
45n/a """Generate proper events to click at the x, y position (tries to act
46n/a like an X server)."""
47n/a widget.event_generate('<Enter>', x=0, y=0)
48n/a widget.event_generate('<Motion>', x=x, y=y)
49n/a widget.event_generate('<ButtonPress-1>', x=x, y=y)
50n/a widget.event_generate('<ButtonRelease-1>', x=x, y=y)
51n/a
52n/a
53n/aimport _tkinter
54n/atcl_version = tuple(map(int, _tkinter.TCL_VERSION.split('.')))
55n/a
56n/adef requires_tcl(*version):
57n/a return unittest.skipUnless(tcl_version >= version,
58n/a 'requires Tcl version >= ' + '.'.join(map(str, version)))
59n/a
60n/a_tk_patchlevel = None
61n/adef get_tk_patchlevel():
62n/a global _tk_patchlevel
63n/a if _tk_patchlevel is None:
64n/a tcl = tkinter.Tcl()
65n/a patchlevel = tcl.call('info', 'patchlevel')
66n/a m = re.fullmatch(r'(\d+)\.(\d+)([ab.])(\d+)', patchlevel)
67n/a major, minor, releaselevel, serial = m.groups()
68n/a major, minor, serial = int(major), int(minor), int(serial)
69n/a releaselevel = {'a': 'alpha', 'b': 'beta', '.': 'final'}[releaselevel]
70n/a if releaselevel == 'final':
71n/a _tk_patchlevel = major, minor, serial, releaselevel, 0
72n/a else:
73n/a _tk_patchlevel = major, minor, 0, releaselevel, serial
74n/a return _tk_patchlevel
75n/a
76n/aunits = {
77n/a 'c': 72 / 2.54, # centimeters
78n/a 'i': 72, # inches
79n/a 'm': 72 / 25.4, # millimeters
80n/a 'p': 1, # points
81n/a}
82n/a
83n/adef pixels_conv(value):
84n/a return float(value[:-1]) * units[value[-1:]]
85n/a
86n/adef tcl_obj_eq(actual, expected):
87n/a if actual == expected:
88n/a return True
89n/a if isinstance(actual, _tkinter.Tcl_Obj):
90n/a if isinstance(expected, str):
91n/a return str(actual) == expected
92n/a if isinstance(actual, tuple):
93n/a if isinstance(expected, tuple):
94n/a return (len(actual) == len(expected) and
95n/a all(tcl_obj_eq(act, exp)
96n/a for act, exp in zip(actual, expected)))
97n/a return False
98n/a
99n/adef widget_eq(actual, expected):
100n/a if actual == expected:
101n/a return True
102n/a if isinstance(actual, (str, tkinter.Widget)):
103n/a if isinstance(expected, (str, tkinter.Widget)):
104n/a return str(actual) == str(expected)
105n/a return False