Skip to content

Commit b6958a5

Browse files
pythongh-120873: Add tests for new widget options in Tk 8.7
1 parent 974a978 commit b6958a5

File tree

3 files changed

+115
-23
lines changed

3 files changed

+115
-23
lines changed

Lib/test/test_tkinter/test_widgets.py

Lines changed: 10 additions & 7 deletions
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):
@@ -148,6 +148,7 @@ class AbstractLabelTest(AbstractWidgetTest, IntegerSizeTests):
148148
_clip_pad = tk_version >= (8, 7)
149149
_clip_borderwidth = tk_version >= (8, 7)
150150

151+
test_configure_justify = requires_tk(8, 7)(StandardOptionsTests.test_configure_justify)
151152

152153
@add_standard_options(StandardOptionsTests)
153154
class LabelTest(AbstractLabelTest, unittest.TestCase):
@@ -338,7 +339,8 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
338339
'highlightbackground', 'highlightcolor', 'highlightthickness',
339340
'insertbackground', 'insertborderwidth',
340341
'insertofftime', 'insertontime', 'insertwidth',
341-
'invalidcommand', 'justify', 'readonlybackground', 'relief',
342+
'invalidcommand', 'justify', 'placeholder', 'placeholderforeground',
343+
'readonlybackground', 'relief',
342344
'selectbackground', 'selectborderwidth', 'selectforeground',
343345
'show', 'state', 'takefocus', 'textvariable',
344346
'validate', 'validatecommand', 'width', 'xscrollcommand',
@@ -432,8 +434,8 @@ class SpinboxTest(EntryTest, unittest.TestCase):
432434
'increment',
433435
'insertbackground', 'insertborderwidth',
434436
'insertofftime', 'insertontime', 'insertwidth',
435-
'invalidcommand', 'justify', 'relief', 'readonlybackground',
436-
'repeatdelay', 'repeatinterval',
437+
'invalidcommand', 'justify', 'placeholder', 'placeholderforeground',
438+
'relief', 'readonlybackground', 'repeatdelay', 'repeatinterval',
437439
'selectbackground', 'selectborderwidth', 'selectforeground',
438440
'state', 'takefocus', 'textvariable', 'to',
439441
'validate', 'validatecommand', 'values',
@@ -1386,6 +1388,7 @@ def test_paneconfigure_width(self):
13861388
class MenuTest(AbstractWidgetTest, unittest.TestCase):
13871389
OPTIONS = (
13881390
'activebackground', 'activeborderwidth', 'activeforeground',
1391+
'activerelief',
13891392
'background', 'borderwidth', 'cursor',
13901393
'disabledforeground', 'font', 'foreground',
13911394
'postcommand', 'relief', 'selectcolor', 'takefocus',

Lib/test/test_tkinter/widget_tests.py

Lines changed: 27 additions & 1 deletion
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

@@ -200,6 +200,7 @@ def test_keys(self):
200200
aliases = {
201201
'bd': 'borderwidth',
202202
'bg': 'background',
203+
'bgimg': 'backgroundimage',
203204
'fg': 'foreground',
204205
'invcmd': 'invalidcommand',
205206
'vcmd': 'validatecommand',
@@ -242,6 +243,11 @@ def test_configure_activeforeground(self):
242243
widget = self.create()
243244
self.checkColorParam(widget, 'activeforeground')
244245

246+
@requires_tk(8, 7)
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')
@@ -379,6 +390,16 @@ def test_configure_pady(self):
379390
self.checkParam(widget, 'pady', -2, expected=expected,
380391
conv=self._conv_pad_pixels)
381392

393+
@requires_tk(8, 7)
394+
def test_configure_placeholder(self):
395+
widget = self.create()
396+
self.checkParam(widget, 'placeholder', 'xxx')
397+
398+
@requires_tk(8, 7)
399+
def test_configure_placeholderforeground(self):
400+
widget = self.create()
401+
self.checkColorParam(widget, 'placeholderforeground')
402+
382403
def test_configure_relief(self):
383404
widget = self.create()
384405
self.checkReliefParam(widget, 'relief')
@@ -424,6 +445,11 @@ def test_configure_textvariable(self):
424445
var = tkinter.StringVar(self.root)
425446
self.checkVariableParam(widget, 'textvariable', var)
426447

448+
@requires_tk(8, 7)
449+
def test_configure_tile(self):
450+
widget = self.create()
451+
self.checkBooleanParam(widget, 'tile')
452+
427453
def test_configure_troughcolor(self):
428454
widget = self.create()
429455
self.checkColorParam(widget, 'troughcolor')

Lib/test/test_ttk/test_widgets.py

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ def test_configure_compound(self):
188188
widget = self.create()
189189
self.checkEnumParam(widget, 'compound', *values, allow_empty=True)
190190

191+
@requires_tk(8, 7)
192+
def test_configure_justify(self):
193+
widget = self.create()
194+
values = ('left', 'right', 'center')
195+
if tk_version >= (8, 7):
196+
values += ('',)
197+
self.checkEnumParam(widget, 'justify', *values,
198+
fullname='justification')
199+
191200
def test_configure_width(self):
192201
widget = self.create()
193202
self.checkParams(widget, 'width', 402, -402, 0)
@@ -207,11 +216,6 @@ class LabelTest(AbstractLabelTest, unittest.TestCase):
207216
def create(self, **kwargs):
208217
return ttk.Label(self.root, **kwargs)
209218

210-
def test_configure_font(self):
211-
widget = self.create()
212-
self.checkParam(widget, 'font',
213-
'-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*')
214-
215219
def test_configure_justify(self):
216220
widget = self.create()
217221
values = ('left', 'right', 'center')
@@ -220,11 +224,17 @@ def test_configure_justify(self):
220224
self.checkEnumParam(widget, 'justify', *values,
221225
fullname='justification')
222226

227+
def test_configure_font(self):
228+
widget = self.create()
229+
self.checkParam(widget, 'font',
230+
'-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*')
231+
232+
223233
@add_standard_options(StandardTtkOptionsTests)
224234
class ButtonTest(AbstractLabelTest, unittest.TestCase):
225235
OPTIONS = (
226236
'class', 'command', 'compound', 'cursor', 'default',
227-
'image', 'padding', 'state', 'style',
237+
'image', 'justify', 'padding', 'state', 'style',
228238
'takefocus', 'text', 'textvariable',
229239
'underline', 'width',
230240
)
@@ -249,7 +259,7 @@ def test_invoke(self):
249259
class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
250260
OPTIONS = (
251261
'class', 'command', 'compound', 'cursor',
252-
'image',
262+
'image', 'justify',
253263
'offvalue', 'onvalue',
254264
'padding', 'state', 'style',
255265
'takefocus', 'text', 'textvariable',
@@ -338,6 +348,7 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
338348
'background', 'class', 'cursor',
339349
'exportselection', 'font', 'foreground',
340350
'invalidcommand', 'justify',
351+
'placeholder', 'placeholderforeground',
341352
'show', 'state', 'style', 'takefocus', 'textvariable',
342353
'validate', 'validatecommand', 'width', 'xscrollcommand',
343354
)
@@ -460,7 +471,8 @@ class ComboboxTest(EntryTest, unittest.TestCase):
460471
OPTIONS = (
461472
'background', 'class', 'cursor', 'exportselection',
462473
'font', 'foreground', 'height', 'invalidcommand',
463-
'justify', 'postcommand', 'show', 'state', 'style',
474+
'justify', 'placeholder', 'placeholderforeground', 'postcommand',
475+
'show', 'state', 'style',
464476
'takefocus', 'textvariable',
465477
'validate', 'validatecommand', 'values',
466478
'width', 'xscrollcommand',
@@ -720,7 +732,7 @@ def test_sashpos(self):
720732
class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
721733
OPTIONS = (
722734
'class', 'command', 'compound', 'cursor',
723-
'image',
735+
'image', 'justify',
724736
'padding', 'state', 'style',
725737
'takefocus', 'text', 'textvariable',
726738
'underline', 'value', 'variable', 'width',
@@ -774,7 +786,7 @@ def cb_test():
774786
class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
775787
OPTIONS = (
776788
'class', 'compound', 'cursor', 'direction',
777-
'image', 'menu', 'padding', 'state', 'style',
789+
'image', 'justify', 'menu', 'padding', 'state', 'style',
778790
'takefocus', 'text', 'textvariable',
779791
'underline', 'width',
780792
)
@@ -906,8 +918,9 @@ def test_set(self):
906918
@add_standard_options(StandardTtkOptionsTests)
907919
class ProgressbarTest(AbstractWidgetTest, unittest.TestCase):
908920
OPTIONS = (
909-
'class', 'cursor', 'orient', 'length',
910-
'mode', 'maximum', 'phase',
921+
'anchor', 'class', 'cursor', 'font', 'foreground', 'justify',
922+
'orient', 'length',
923+
'mode', 'maximum', 'phase', 'text', 'wraplength',
911924
'style', 'takefocus', 'value', 'variable',
912925
)
913926
_conv_pixels = False
@@ -916,6 +929,27 @@ class ProgressbarTest(AbstractWidgetTest, unittest.TestCase):
916929
def create(self, **kwargs):
917930
return ttk.Progressbar(self.root, **kwargs)
918931

932+
@requires_tk(8, 7)
933+
def test_configure_anchor(self):
934+
widget = self.create()
935+
self.checkEnumParam(widget, 'anchor',
936+
'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'center', '')
937+
938+
@requires_tk(8, 7)
939+
def test_configure_font(self):
940+
widget = self.create()
941+
self.checkParam(widget, 'font',
942+
'-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*')
943+
944+
test_configure_foreground = requires_tk(8, 7)(StandardOptionsTests.test_configure_foreground)
945+
946+
@requires_tk(8, 7)
947+
def test_configure_justify(self):
948+
widget = self.create()
949+
values = ('left', 'right', 'center', '')
950+
self.checkEnumParam(widget, 'justify', *values,
951+
fullname='justification')
952+
919953
def test_configure_length(self):
920954
widget = self.create()
921955
self.checkPixelsParam(widget, 'length', 100.1, 56.7, '2i')
@@ -932,11 +966,15 @@ def test_configure_phase(self):
932966
# XXX
933967
pass
934968

969+
test_configure_text = requires_tk(8, 7)(StandardOptionsTests.test_configure_text)
970+
935971
def test_configure_value(self):
936972
widget = self.create()
937973
self.checkFloatParam(widget, 'value', 150.2, 77.7, 0, -10,
938974
conv=False)
939975

976+
test_configure_wraplength = requires_tk(8, 7)(StandardOptionsTests.test_configure_wraplength)
977+
940978

941979
@unittest.skipIf(sys.platform == 'darwin',
942980
'ttk.Scrollbar is special on MacOSX')
@@ -1173,7 +1211,9 @@ class SpinboxTest(EntryTest, unittest.TestCase):
11731211
OPTIONS = (
11741212
'background', 'class', 'command', 'cursor', 'exportselection',
11751213
'font', 'foreground', 'format', 'from', 'increment',
1176-
'invalidcommand', 'justify', 'show', 'state', 'style',
1214+
'invalidcommand', 'justify',
1215+
'placeholder', 'placeholderforeground',
1216+
'show', 'state', 'style',
11771217
'takefocus', 'textvariable', 'to', 'validate', 'validatecommand',
11781218
'values', 'width', 'wrap', 'xscrollcommand',
11791219
)
@@ -1347,8 +1387,9 @@ def test_configure_values(self):
13471387
class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
13481388
OPTIONS = (
13491389
'class', 'columns', 'cursor', 'displaycolumns',
1350-
'height', 'padding', 'selectmode', 'show',
1351-
'style', 'takefocus', 'xscrollcommand', 'yscrollcommand',
1390+
'height', 'padding', 'selectmode', 'selecttype', 'show', 'striped',
1391+
'style', 'takefocus', 'titlecolumns', 'titleitems',
1392+
'xscrollcommand', 'yscrollcommand',
13521393
)
13531394

13541395
def setUp(self):
@@ -1393,6 +1434,11 @@ def test_configure_selectmode(self):
13931434
self.checkEnumParam(widget, 'selectmode',
13941435
'none', 'browse', 'extended')
13951436

1437+
@requires_tk(8, 7)
1438+
def test_configure_selecttype(self):
1439+
widget = self.create()
1440+
self.checkEnumParam(widget, 'selecttype', 'item', 'cell')
1441+
13961442
def test_configure_show(self):
13971443
widget = self.create()
13981444
self.checkParam(widget, 'show', 'tree headings',
@@ -1402,6 +1448,23 @@ def test_configure_show(self):
14021448
self.checkParam(widget, 'show', 'tree', expected=('tree',))
14031449
self.checkParam(widget, 'show', 'headings', expected=('headings',))
14041450

1451+
@requires_tk(8, 7)
1452+
def test_configure_striped(self):
1453+
widget = self.create()
1454+
self.checkBooleanParam(widget, 'striped')
1455+
1456+
@requires_tk(8, 7)
1457+
def test_configure_titlecolumns(self):
1458+
widget = self.create()
1459+
self.checkIntegerParam(widget, 'titlecolumns', 0, 1, 5)
1460+
self.checkInvalidParam(widget, 'titlecolumns', -2)
1461+
1462+
@requires_tk(8, 7)
1463+
def test_configure_titleitems(self):
1464+
widget = self.create()
1465+
self.checkIntegerParam(widget, 'titleitems', 0, 1, 5)
1466+
self.checkInvalidParam(widget, 'titleitems', -2)
1467+
14051468
def test_bbox(self):
14061469
self.tv.pack()
14071470
self.assertEqual(self.tv.bbox(''), '')

0 commit comments

Comments
 (0)