Skip to content

Commit be37077

Browse files
committed
test: adapt Tkinter tests for Tk 8.6.12
Backport the relevant behavior changes from bpo-45436 (4fe454c), bpo-41306 (aecf036), and the bpo-45979 correction (dbbe4d2). Retain the older Tk expectations. On Tk 8.6.11+, explicitly test empty Menu.type and ttk compound values while still rejecting invalid enum values. On Tk 8.6.10+, expect Scale.from to retain its fractional value. Validated test_tk and test_ttk_guionly with Python 3.6 and Tcl/Tk 8.6.12 on openSUSE Leap 15.6, including the affected widget classes with wantobjects disabled.
1 parent 8d60b8b commit be37077

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎Lib/tkinter/test/test_tkinter/test_widgets.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,9 @@ def test_digits(self):
864864

865865
def test_from(self):
866866
widget = self.create()
867-
self.checkFloatParam(widget, 'from', 100, 14.9, 15.1, conv=float_round)
867+
# bpo-41306: Tk 8.6.10 no longer rounds the 'from' option.
868+
conv = float if get_tk_patchlevel() >= (8, 6, 10) else float_round
869+
self.checkFloatParam(widget, 'from', 100, 14.9, 15.1, conv=conv)
868870

869871
def test_label(self):
870872
widget = self.create()
@@ -1165,8 +1167,10 @@ def test_title(self):
11651167

11661168
def test_type(self):
11671169
widget = self.create()
1170+
# bpo-45436: Tk 8.6.11 accepts an empty menu type.
11681171
self.checkEnumParam(widget, 'type',
1169-
'normal', 'tearoff', 'menubar')
1172+
'normal', 'tearoff', 'menubar',
1173+
allow_empty=get_tk_patchlevel() >= (8, 6, 11))
11701174

11711175
def test_entryconfigure(self):
11721176
m1 = self.create()

‎Lib/tkinter/test/test_ttk/test_widgets.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,11 @@ def checkImageParam(self, widget, name):
171171

172172
def test_compound(self):
173173
widget = self.create()
174+
# bpo-45436: Tk 8.6.11 accepts an empty compound option.
174175
self.checkEnumParam(widget, 'compound',
175176
'none', 'text', 'image', 'center',
176-
'top', 'bottom', 'left', 'right')
177+
'top', 'bottom', 'left', 'right',
178+
allow_empty=get_tk_patchlevel() >= (8, 6, 11))
177179

178180
def test_state(self):
179181
widget = self.create()

‎Lib/tkinter/test/widget_tests.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,22 @@ def command(*args):
144144
self.assertTrue(widget[name])
145145
self.checkParams(widget, name, '')
146146

147-
def checkEnumParam(self, widget, name, *values, errmsg=None, **kwargs):
147+
def checkEnumParam(self, widget, name, *values, errmsg=None,
148+
allow_empty=False, **kwargs):
148149
self.checkParams(widget, name, *values, **kwargs)
149150
if errmsg is None:
150151
errmsg2 = ' %s "{}": must be %s%s or %s' % (
151152
name,
152153
', '.join(values[:-1]),
153154
',' if len(values) > 2 else '',
154155
values[-1])
155-
self.checkInvalidParam(widget, name, '',
156-
errmsg='ambiguous' + errmsg2)
156+
if not allow_empty:
157+
self.checkInvalidParam(widget, name, '',
158+
errmsg='ambiguous' + errmsg2)
157159
errmsg = 'bad' + errmsg2
158160
self.checkInvalidParam(widget, name, 'spam', errmsg=errmsg)
161+
if allow_empty:
162+
self.checkParam(widget, name, '', **kwargs)
159163

160164
def checkPixelsParam(self, widget, name, *values,
161165
conv=None, keep_orig=True, **kwargs):

0 commit comments

Comments
 (0)