Mercurial > cpython-lru_cache-weakref
annotate Lib/tkinter/test/support.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 204e66190dbb |
| children |
| rev | line source |
|---|---|
|
71185
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
1 import sys |
|
51132
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
2 import tkinter |
|
71185
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
3 import unittest |
|
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
4 |
|
71242
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
5 _tk_unavailable = None |
|
71185
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
6 |
|
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
7 def check_tk_availability(): |
|
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
8 """Check that Tk is installed and available.""" |
|
71242
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
9 global _tk_unavailable |
|
71185
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
10 |
|
71242
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
11 if _tk_unavailable is None: |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
12 _tk_unavailable = False |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
13 if sys.platform == 'darwin': |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
14 # The Aqua Tk implementations on OS X can abort the process if |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
15 # being called in an environment where a window server connection |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
16 # cannot be made, for instance when invoked by a buildbot or ssh |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
17 # process not running under the same user id as the current console |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
18 # user. To avoid that, raise an exception if the window manager |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
19 # connection is not available. |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
20 from ctypes import cdll, c_int, pointer, Structure |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
21 from ctypes.util import find_library |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
22 |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
23 app_services = cdll.LoadLibrary(find_library("ApplicationServices")) |
|
71185
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
24 |
|
71242
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
25 if app_services.CGMainDisplayID() == 0: |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
26 _tk_unavailable = "cannot run without OS X window manager" |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
27 else: |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
28 class ProcessSerialNumber(Structure): |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
29 _fields_ = [("highLongOfPSN", c_int), |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
30 ("lowLongOfPSN", c_int)] |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
31 psn = ProcessSerialNumber() |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
32 psn_p = pointer(psn) |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
33 if ( (app_services.GetCurrentProcess(psn_p) < 0) or |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
34 (app_services.SetFrontProcess(psn_p) < 0) ): |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
35 _tk_unavailable = "cannot run without OS X gui process" |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
36 else: # not OS X |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
37 import tkinter |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
38 try: |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
39 tkinter.Button() |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
40 except tkinter.TclError as msg: |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
41 # assuming tk is not available |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
42 _tk_unavailable = "tk not available: %s" % msg |
|
71185
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
43 |
|
71242
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
44 if _tk_unavailable: |
|
b58b0c5c7e96
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of
Ned Deily <nad@acm.org>
parents:
71185
diff
changeset
|
45 raise unittest.SkipTest(_tk_unavailable) |
|
71185
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
46 return |
|
51132
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
47 |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
48 def get_tk_root(): |
|
71185
279488f5a171
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
Ned Deily <nad@acm.org>
parents:
51255
diff
changeset
|
49 check_tk_availability() # raise exception if tk unavailable |
|
51132
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
50 try: |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
51 root = tkinter._default_root |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
52 except AttributeError: |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
53 # it is possible to disable default root in Tkinter, although |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
54 # I haven't seen people doing it (but apparently someone did it |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
55 # here). |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
56 root = None |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
57 |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
58 if root is None: |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
59 # create a new master only if there isn't one already |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
60 root = tkinter.Tk() |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
61 |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
62 return root |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
63 |
|
51255
8c4410d067ee
Recorded merge of revisions 69195 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
51132
diff
changeset
|
64 def root_deiconify(): |
|
8c4410d067ee
Recorded merge of revisions 69195 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
51132
diff
changeset
|
65 root = get_tk_root() |
|
8c4410d067ee
Recorded merge of revisions 69195 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
51132
diff
changeset
|
66 root.deiconify() |
|
8c4410d067ee
Recorded merge of revisions 69195 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
51132
diff
changeset
|
67 |
|
8c4410d067ee
Recorded merge of revisions 69195 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
51132
diff
changeset
|
68 def root_withdraw(): |
|
8c4410d067ee
Recorded merge of revisions 69195 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
51132
diff
changeset
|
69 root = get_tk_root() |
|
8c4410d067ee
Recorded merge of revisions 69195 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
51132
diff
changeset
|
70 root.withdraw() |
|
8c4410d067ee
Recorded merge of revisions 69195 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
51132
diff
changeset
|
71 |
|
51132
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
72 |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
73 def simulate_mouse_click(widget, x, y): |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
74 """Generate proper events to click at the x, y position (tries to act |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
75 like an X server).""" |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
76 widget.event_generate('<Enter>', x=0, y=0) |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
77 widget.event_generate('<Motion>', x=x, y=y) |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
78 widget.event_generate('<ButtonPress-1>', x=x, y=y) |
|
c9093d41590e
Merged revisions 69050 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
diff
changeset
|
79 widget.event_generate('<ButtonRelease-1>', x=x, y=y) |
|
86834
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
80 |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
81 |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
82 import _tkinter |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
83 tcl_version = tuple(map(int, _tkinter.TCL_VERSION.split('.'))) |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
84 |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
85 def requires_tcl(*version): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
86 return unittest.skipUnless(tcl_version >= version, |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
87 'requires Tcl version >= ' + '.'.join(map(str, version))) |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
88 |
|
87022
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
89 _tk_patchlevel = None |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
90 def get_tk_patchlevel(): |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
91 global _tk_patchlevel |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
92 if _tk_patchlevel is None: |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
93 tcl = tkinter.Tcl() |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
94 patchlevel = [] |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
95 for x in tcl.call('info', 'patchlevel').split('.'): |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
96 try: |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
97 x = int(x, 10) |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
98 except ValueError: |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
99 x = -1 |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
100 patchlevel.append(x) |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
101 _tk_patchlevel = tuple(patchlevel) |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
102 return _tk_patchlevel |
|
204e66190dbb
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
Serhiy Storchaka <storchaka@gmail.com>
parents:
86834
diff
changeset
|
103 |
|
86834
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
104 units = { |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
105 'c': 72 / 2.54, # centimeters |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
106 'i': 72, # inches |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
107 'm': 72 / 25.4, # millimeters |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
108 'p': 1, # points |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
109 } |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
110 |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
111 def pixels_conv(value): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
112 return float(value[:-1]) * units[value[-1:]] |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
113 |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
114 def tcl_obj_eq(actual, expected): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
115 if actual == expected: |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
116 return True |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
117 if isinstance(actual, _tkinter.Tcl_Obj): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
118 if isinstance(expected, str): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
119 return str(actual) == expected |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
120 if isinstance(actual, tuple): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
121 if isinstance(expected, tuple): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
122 return (len(actual) == len(expected) and |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
123 all(tcl_obj_eq(act, exp) |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
124 for act, exp in zip(actual, expected))) |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
125 return False |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
126 |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
127 def widget_eq(actual, expected): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
128 if actual == expected: |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
129 return True |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
130 if isinstance(actual, (str, tkinter.Widget)): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
131 if isinstance(expected, (str, tkinter.Widget)): |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
132 return str(actual) == str(expected) |
|
92e268f2719e
Issue #19085: Added basic tests for all tkinter widget options.
Serhiy Storchaka <storchaka@gmail.com>
parents:
71242
diff
changeset
|
133 return False |
