Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2564ce

Browse files
Issue #19085: Added basic tests for all tkinter widget options.
2 parents 2b8fc30 + 758c521 commit b2564ce

5 files changed

Lines changed: 1919 additions & 25 deletions

File tree

Lib/tkinter/test/support.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,42 @@ def simulate_mouse_click(widget, x, y):
7777
widget.event_generate('<Motion>', x=x, y=y)
7878
widget.event_generate('<ButtonPress-1>', x=x, y=y)
7979
widget.event_generate('<ButtonRelease-1>', x=x, y=y)
80+
81+
82+
import _tkinter
83+
tcl_version = tuple(map(int, _tkinter.TCL_VERSION.split('.')))
84+
85+
def requires_tcl(*version):
86+
return unittest.skipUnless(tcl_version >= version,
87+
'requires Tcl version >= ' + '.'.join(map(str, version)))
88+
89+
units = {
90+
'c': 72 / 2.54, # centimeters
91+
'i': 72, # inches
92+
'm': 72 / 25.4, # millimeters
93+
'p': 1, # points
94+
}
95+
96+
def pixels_conv(value):
97+
return float(value[:-1]) * units[value[-1:]]
98+
99+
def tcl_obj_eq(actual, expected):
100+
if actual == expected:
101+
return True
102+
if isinstance(actual, _tkinter.Tcl_Obj):
103+
if isinstance(expected, str):
104+
return str(actual) == expected
105+
if isinstance(actual, tuple):
106+
if isinstance(expected, tuple):
107+
return (len(actual) == len(expected) and
108+
all(tcl_obj_eq(act, exp)
109+
for act, exp in zip(actual, expected)))
110+
return False
111+
112+
def widget_eq(actual, expected):
113+
if actual == expected:
114+
return True
115+
if isinstance(actual, (str, tkinter.Widget)):
116+
if isinstance(expected, (str, tkinter.Widget)):
117+
return str(actual) == str(expected)
118+
return False

0 commit comments

Comments
 (0)