Skip to content

Commit cffead8

Browse files
[3.13] gh-120873: Add tests for new widget options in Tk 8.7 (GH-120877) (GH-120879)
(cherry picked from commit a046c84) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 61e6b6a commit cffead8

File tree

3 files changed

+104
-36
lines changed

3 files changed

+104
-36
lines changed

Lib/test/test_tkinter/test_widgets.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def test_configure_visual(self):
6161
@add_standard_options(StandardOptionsTests)
6262
class ToplevelTest(AbstractToplevelTest, unittest.TestCase):
6363
OPTIONS = (
64-
'background', 'borderwidth',
64+
'background', 'backgroundimage', 'borderwidth',
6565
'class', 'colormap', 'container', 'cursor', 'height',
6666
'highlightbackground', 'highlightcolor', 'highlightthickness',
6767
'menu', 'padx', 'pady', 'relief', 'screen',
68-
'takefocus', 'use', 'visual', 'width',
68+
'takefocus', 'tile', 'use', 'visual', 'width',
6969
)
7070

7171
def create(self, **kwargs):
@@ -104,10 +104,10 @@ def test_configure_use(self):
104104
@add_standard_options(StandardOptionsTests)
105105
class FrameTest(AbstractToplevelTest, unittest.TestCase):
106106
OPTIONS = (
107-
'background', 'borderwidth',
107+
'background', 'backgroundimage', 'borderwidth',
108108
'class', 'colormap', 'container', 'cursor', 'height',
109109
'highlightbackground', 'highlightcolor', 'highlightthickness',
110-
'padx', 'pady', 'relief', 'takefocus', 'visual', 'width',
110+
'padx', 'pady', 'relief', 'takefocus', 'tile', 'visual', 'width',
111111
)
112112

113113
def create(self, **kwargs):
@@ -338,7 +338,8 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
338338
'highlightbackground', 'highlightcolor', 'highlightthickness',
339339
'insertbackground', 'insertborderwidth',
340340
'insertofftime', 'insertontime', 'insertwidth',
341-
'invalidcommand', 'justify', 'readonlybackground', 'relief',
341+
'invalidcommand', 'justify', 'placeholder', 'placeholderforeground',
342+
'readonlybackground', 'relief',
342343
'selectbackground', 'selectborderwidth', 'selectforeground',
343344
'show', 'state', 'takefocus', 'textvariable',
344345
'validate', 'validatecommand', 'width', 'xscrollcommand',
@@ -432,8 +433,8 @@ class SpinboxTest(EntryTest, unittest.TestCase):
432433
'increment',
433434
'insertbackground', 'insertborderwidth',
434435
'insertofftime', 'insertontime', 'insertwidth',
435-
'invalidcommand', 'justify', 'relief', 'readonlybackground',
436-
'repeatdelay', 'repeatinterval',
436+
'invalidcommand', 'justify', 'placeholder', 'placeholderforeground',
437+
'relief', 'readonlybackground', 'repeatdelay', 'repeatinterval',
437438
'selectbackground', 'selectborderwidth', 'selectforeground',
438439
'state', 'takefocus', 'textvariable', 'to',
439440
'validate', 'validatecommand', 'values',
@@ -1176,10 +1177,6 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
11761177
def create(self, **kwargs):
11771178
return tkinter.Scrollbar(self.root, **kwargs)
11781179

1179-
def test_configure_activerelief(self):
1180-
widget = self.create()
1181-
self.checkReliefParam(widget, 'activerelief')
1182-
11831180
def test_configure_elementborderwidth(self):
11841181
widget = self.create()
11851182
self.checkPixelsParam(widget, 'elementborderwidth', 4.3, 5.6, '1m')
@@ -1386,6 +1383,7 @@ def test_paneconfigure_width(self):
13861383
class MenuTest(AbstractWidgetTest, unittest.TestCase):
13871384
OPTIONS = (
13881385
'activebackground', 'activeborderwidth', 'activeforeground',
1386+
'activerelief',
13891387
'background', 'borderwidth', 'cursor',
13901388
'disabledforeground', 'font', 'foreground',
13911389
'postcommand', 'relief', 'selectcolor', 'takefocus',
@@ -1401,6 +1399,8 @@ def test_indexcommand_none(self):
14011399
i = widget.index('none')
14021400
self.assertIsNone(i)
14031401

1402+
test_configure_activerelief = requires_tk(8, 7)(StandardOptionsTests.test_configure_activerelief)
1403+
14041404
def test_configure_postcommand(self):
14051405
widget = self.create()
14061406
self.checkCommandParam(widget, 'postcommand')

Lib/test/test_tkinter/widget_tests.py

+35-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
import tkinter
5-
from test.test_tkinter.support import (AbstractTkTest, tk_version,
5+
from test.test_tkinter.support import (AbstractTkTest, requires_tk, tk_version,
66
pixels_conv, tcl_obj_eq)
77
import test.support
88

@@ -17,6 +17,7 @@ class AbstractWidgetTest(AbstractTkTest):
1717
_clip_highlightthickness = True
1818
_clip_pad = False
1919
_clip_borderwidth = False
20+
_allow_empty_justify = False
2021

2122
@property
2223
def scaling(self):
@@ -200,6 +201,7 @@ def test_keys(self):
200201
aliases = {
201202
'bd': 'borderwidth',
202203
'bg': 'background',
204+
'bgimg': 'backgroundimage',
203205
'fg': 'foreground',
204206
'invcmd': 'invalidcommand',
205207
'vcmd': 'validatecommand',
@@ -242,6 +244,10 @@ def test_configure_activeforeground(self):
242244
widget = self.create()
243245
self.checkColorParam(widget, 'activeforeground')
244246

247+
def test_configure_activerelief(self):
248+
widget = self.create()
249+
self.checkReliefParam(widget, 'activerelief')
250+
245251
def test_configure_anchor(self):
246252
widget = self.create()
247253
self.checkEnumParam(widget, 'anchor',
@@ -253,6 +259,11 @@ def test_configure_background(self):
253259
if 'bg' in self.OPTIONS:
254260
self.checkColorParam(widget, 'bg')
255261

262+
@requires_tk(8, 7)
263+
def test_configure_backgroundimage(self):
264+
widget = self.create()
265+
self.checkImageParam(widget, 'backgroundimage')
266+
256267
def test_configure_bitmap(self):
257268
widget = self.create()
258269
self.checkParam(widget, 'bitmap', 'questhead')
@@ -299,8 +310,10 @@ def test_configure_font(self):
299310
widget = self.create()
300311
self.checkParam(widget, 'font',
301312
'-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*')
302-
self.checkInvalidParam(widget, 'font', '',
303-
errmsg='font "" doesn\'t exist')
313+
is_ttk = widget.__class__.__module__ == 'tkinter.ttk'
314+
if not is_ttk:
315+
self.checkInvalidParam(widget, 'font', '',
316+
errmsg='font "" doesn\'t exist')
304317

305318
def test_configure_foreground(self):
306319
widget = self.create()
@@ -355,7 +368,10 @@ def test_configure_jump(self):
355368

356369
def test_configure_justify(self):
357370
widget = self.create()
358-
self.checkEnumParam(widget, 'justify', 'left', 'right', 'center',
371+
values = ('left', 'right', 'center')
372+
if self._allow_empty_justify:
373+
values += ('',)
374+
self.checkEnumParam(widget, 'justify', *values,
359375
fullname='justification')
360376

361377
def test_configure_orient(self):
@@ -379,6 +395,16 @@ def test_configure_pady(self):
379395
self.checkParam(widget, 'pady', -2, expected=expected,
380396
conv=self._conv_pad_pixels)
381397

398+
@requires_tk(8, 7)
399+
def test_configure_placeholder(self):
400+
widget = self.create()
401+
self.checkParam(widget, 'placeholder', 'xxx')
402+
403+
@requires_tk(8, 7)
404+
def test_configure_placeholderforeground(self):
405+
widget = self.create()
406+
self.checkColorParam(widget, 'placeholderforeground')
407+
382408
def test_configure_relief(self):
383409
widget = self.create()
384410
self.checkReliefParam(widget, 'relief')
@@ -424,6 +450,11 @@ def test_configure_textvariable(self):
424450
var = tkinter.StringVar(self.root)
425451
self.checkVariableParam(widget, 'textvariable', var)
426452

453+
@requires_tk(8, 7)
454+
def test_configure_tile(self):
455+
widget = self.create()
456+
self.checkBooleanParam(widget, 'tile')
457+
427458
def test_configure_troughcolor(self):
428459
widget = self.create()
429460
self.checkColorParam(widget, 'troughcolor')

Lib/test/test_ttk/test_widgets.py

+58-21
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def test_configure_labelwidget(self):
167167

168168

169169
class AbstractLabelTest(AbstractWidgetTest):
170+
_allow_empty_justify = True
170171

171172
def checkImageParam(self, widget, name):
172173
image = tkinter.PhotoImage(master=self.root, name='image1')
@@ -188,6 +189,8 @@ def test_configure_compound(self):
188189
widget = self.create()
189190
self.checkEnumParam(widget, 'compound', *values, allow_empty=True)
190191

192+
test_configure_justify = requires_tk(8, 7)(StandardOptionsTests.test_configure_justify)
193+
191194
def test_configure_width(self):
192195
widget = self.create()
193196
self.checkParams(widget, 'width', 402, -402, 0)
@@ -203,28 +206,19 @@ class LabelTest(AbstractLabelTest, unittest.TestCase):
203206
'underline', 'width', 'wraplength',
204207
)
205208
_conv_pixels = False
209+
_allow_empty_justify = tk_version >= (8, 7)
206210

207211
def create(self, **kwargs):
208212
return ttk.Label(self.root, **kwargs)
209213

210-
def test_configure_font(self):
211-
widget = self.create()
212-
self.checkParam(widget, 'font',
213-
'-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*')
214+
test_configure_justify = StandardOptionsTests.test_configure_justify
214215

215-
def test_configure_justify(self):
216-
widget = self.create()
217-
values = ('left', 'right', 'center')
218-
if tk_version >= (8, 7):
219-
values += ('',)
220-
self.checkEnumParam(widget, 'justify', *values,
221-
fullname='justification')
222216

223217
@add_standard_options(StandardTtkOptionsTests)
224218
class ButtonTest(AbstractLabelTest, unittest.TestCase):
225219
OPTIONS = (
226220
'class', 'command', 'compound', 'cursor', 'default',
227-
'image', 'padding', 'state', 'style',
221+
'image', 'justify', 'padding', 'state', 'style',
228222
'takefocus', 'text', 'textvariable',
229223
'underline', 'width',
230224
)
@@ -249,7 +243,7 @@ def test_invoke(self):
249243
class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
250244
OPTIONS = (
251245
'class', 'command', 'compound', 'cursor',
252-
'image',
246+
'image', 'justify',
253247
'offvalue', 'onvalue',
254248
'padding', 'state', 'style',
255249
'takefocus', 'text', 'textvariable',
@@ -338,6 +332,7 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
338332
'background', 'class', 'cursor',
339333
'exportselection', 'font', 'foreground',
340334
'invalidcommand', 'justify',
335+
'placeholder', 'placeholderforeground',
341336
'show', 'state', 'style', 'takefocus', 'textvariable',
342337
'validate', 'validatecommand', 'width', 'xscrollcommand',
343338
)
@@ -460,7 +455,8 @@ class ComboboxTest(EntryTest, unittest.TestCase):
460455
OPTIONS = (
461456
'background', 'class', 'cursor', 'exportselection',
462457
'font', 'foreground', 'height', 'invalidcommand',
463-
'justify', 'postcommand', 'show', 'state', 'style',
458+
'justify', 'placeholder', 'placeholderforeground', 'postcommand',
459+
'show', 'state', 'style',
464460
'takefocus', 'textvariable',
465461
'validate', 'validatecommand', 'values',
466462
'width', 'xscrollcommand',
@@ -720,7 +716,7 @@ def test_sashpos(self):
720716
class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
721717
OPTIONS = (
722718
'class', 'command', 'compound', 'cursor',
723-
'image',
719+
'image', 'justify',
724720
'padding', 'state', 'style',
725721
'takefocus', 'text', 'textvariable',
726722
'underline', 'value', 'variable', 'width',
@@ -774,7 +770,7 @@ def cb_test():
774770
class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
775771
OPTIONS = (
776772
'class', 'compound', 'cursor', 'direction',
777-
'image', 'menu', 'padding', 'state', 'style',
773+
'image', 'justify', 'menu', 'padding', 'state', 'style',
778774
'takefocus', 'text', 'textvariable',
779775
'underline', 'width',
780776
)
@@ -906,16 +902,28 @@ def test_set(self):
906902
@add_standard_options(StandardTtkOptionsTests)
907903
class ProgressbarTest(AbstractWidgetTest, unittest.TestCase):
908904
OPTIONS = (
909-
'class', 'cursor', 'orient', 'length',
910-
'mode', 'maximum', 'phase',
905+
'anchor', 'class', 'cursor', 'font', 'foreground', 'justify',
906+
'orient', 'length',
907+
'mode', 'maximum', 'phase', 'text', 'wraplength',
911908
'style', 'takefocus', 'value', 'variable',
912909
)
913910
_conv_pixels = False
911+
_allow_empty_justify = True
914912
default_orient = 'horizontal'
915913

916914
def create(self, **kwargs):
917915
return ttk.Progressbar(self.root, **kwargs)
918916

917+
@requires_tk(8, 7)
918+
def test_configure_anchor(self):
919+
widget = self.create()
920+
self.checkEnumParam(widget, 'anchor',
921+
'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'center', '')
922+
923+
test_configure_font = requires_tk(8, 7)(StandardOptionsTests.test_configure_font)
924+
test_configure_foreground = requires_tk(8, 7)(StandardOptionsTests.test_configure_foreground)
925+
test_configure_justify = requires_tk(8, 7)(StandardTtkOptionsTests.test_configure_justify)
926+
919927
def test_configure_length(self):
920928
widget = self.create()
921929
self.checkPixelsParam(widget, 'length', 100.1, 56.7, '2i')
@@ -932,11 +940,15 @@ def test_configure_phase(self):
932940
# XXX
933941
pass
934942

943+
test_configure_text = requires_tk(8, 7)(StandardOptionsTests.test_configure_text)
944+
935945
def test_configure_value(self):
936946
widget = self.create()
937947
self.checkFloatParam(widget, 'value', 150.2, 77.7, 0, -10,
938948
conv=False)
939949

950+
test_configure_wraplength = requires_tk(8, 7)(StandardOptionsTests.test_configure_wraplength)
951+
940952

941953
@unittest.skipIf(sys.platform == 'darwin',
942954
'ttk.Scrollbar is special on MacOSX')
@@ -1173,7 +1185,9 @@ class SpinboxTest(EntryTest, unittest.TestCase):
11731185
OPTIONS = (
11741186
'background', 'class', 'command', 'cursor', 'exportselection',
11751187
'font', 'foreground', 'format', 'from', 'increment',
1176-
'invalidcommand', 'justify', 'show', 'state', 'style',
1188+
'invalidcommand', 'justify',
1189+
'placeholder', 'placeholderforeground',
1190+
'show', 'state', 'style',
11771191
'takefocus', 'textvariable', 'to', 'validate', 'validatecommand',
11781192
'values', 'width', 'wrap', 'xscrollcommand',
11791193
)
@@ -1347,8 +1361,9 @@ def test_configure_values(self):
13471361
class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
13481362
OPTIONS = (
13491363
'class', 'columns', 'cursor', 'displaycolumns',
1350-
'height', 'padding', 'selectmode', 'show',
1351-
'style', 'takefocus', 'xscrollcommand', 'yscrollcommand',
1364+
'height', 'padding', 'selectmode', 'selecttype', 'show', 'striped',
1365+
'style', 'takefocus', 'titlecolumns', 'titleitems',
1366+
'xscrollcommand', 'yscrollcommand',
13521367
)
13531368

13541369
def setUp(self):
@@ -1393,6 +1408,11 @@ def test_configure_selectmode(self):
13931408
self.checkEnumParam(widget, 'selectmode',
13941409
'none', 'browse', 'extended')
13951410

1411+
@requires_tk(8, 7)
1412+
def test_configure_selecttype(self):
1413+
widget = self.create()
1414+
self.checkEnumParam(widget, 'selecttype', 'item', 'cell')
1415+
13961416
def test_configure_show(self):
13971417
widget = self.create()
13981418
self.checkParam(widget, 'show', 'tree headings',
@@ -1402,6 +1422,23 @@ def test_configure_show(self):
14021422
self.checkParam(widget, 'show', 'tree', expected=('tree',))
14031423
self.checkParam(widget, 'show', 'headings', expected=('headings',))
14041424

1425+
@requires_tk(8, 7)
1426+
def test_configure_striped(self):
1427+
widget = self.create()
1428+
self.checkBooleanParam(widget, 'striped')
1429+
1430+
@requires_tk(8, 7)
1431+
def test_configure_titlecolumns(self):
1432+
widget = self.create()
1433+
self.checkIntegerParam(widget, 'titlecolumns', 0, 1, 5)
1434+
self.checkInvalidParam(widget, 'titlecolumns', -2)
1435+
1436+
@requires_tk(8, 7)
1437+
def test_configure_titleitems(self):
1438+
widget = self.create()
1439+
self.checkIntegerParam(widget, 'titleitems', 0, 1, 5)
1440+
self.checkInvalidParam(widget, 'titleitems', -2)
1441+
14051442
def test_bbox(self):
14061443
self.tv.pack()
14071444
self.assertEqual(self.tv.bbox(''), '')

0 commit comments

Comments
 (0)