Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.13] gh-120873: Add tests for new widget options in Tk 8.7 (GH-120877) #120879

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Lib/test/test_tkinter/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def test_configure_visual(self):
@add_standard_options(StandardOptionsTests)
class ToplevelTest(AbstractToplevelTest, unittest.TestCase):
OPTIONS = (
'background', 'borderwidth',
'background', 'backgroundimage', 'borderwidth',
'class', 'colormap', 'container', 'cursor', 'height',
'highlightbackground', 'highlightcolor', 'highlightthickness',
'menu', 'padx', 'pady', 'relief', 'screen',
'takefocus', 'use', 'visual', 'width',
'takefocus', 'tile', 'use', 'visual', 'width',
)

def create(self, **kwargs):
Expand Down Expand Up @@ -104,10 +104,10 @@ def test_configure_use(self):
@add_standard_options(StandardOptionsTests)
class FrameTest(AbstractToplevelTest, unittest.TestCase):
OPTIONS = (
'background', 'borderwidth',
'background', 'backgroundimage', 'borderwidth',
'class', 'colormap', 'container', 'cursor', 'height',
'highlightbackground', 'highlightcolor', 'highlightthickness',
'padx', 'pady', 'relief', 'takefocus', 'visual', 'width',
'padx', 'pady', 'relief', 'takefocus', 'tile', 'visual', 'width',
)

def create(self, **kwargs):
Expand Down Expand Up @@ -338,7 +338,8 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
'highlightbackground', 'highlightcolor', 'highlightthickness',
'insertbackground', 'insertborderwidth',
'insertofftime', 'insertontime', 'insertwidth',
'invalidcommand', 'justify', 'readonlybackground', 'relief',
'invalidcommand', 'justify', 'placeholder', 'placeholderforeground',
'readonlybackground', 'relief',
'selectbackground', 'selectborderwidth', 'selectforeground',
'show', 'state', 'takefocus', 'textvariable',
'validate', 'validatecommand', 'width', 'xscrollcommand',
Expand Down Expand Up @@ -432,8 +433,8 @@ class SpinboxTest(EntryTest, unittest.TestCase):
'increment',
'insertbackground', 'insertborderwidth',
'insertofftime', 'insertontime', 'insertwidth',
'invalidcommand', 'justify', 'relief', 'readonlybackground',
'repeatdelay', 'repeatinterval',
'invalidcommand', 'justify', 'placeholder', 'placeholderforeground',
'relief', 'readonlybackground', 'repeatdelay', 'repeatinterval',
'selectbackground', 'selectborderwidth', 'selectforeground',
'state', 'takefocus', 'textvariable', 'to',
'validate', 'validatecommand', 'values',
Expand Down Expand Up @@ -1176,10 +1177,6 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
def create(self, **kwargs):
return tkinter.Scrollbar(self.root, **kwargs)

def test_configure_activerelief(self):
widget = self.create()
self.checkReliefParam(widget, 'activerelief')

def test_configure_elementborderwidth(self):
widget = self.create()
self.checkPixelsParam(widget, 'elementborderwidth', 4.3, 5.6, '1m')
Expand Down Expand Up @@ -1386,6 +1383,7 @@ def test_paneconfigure_width(self):
class MenuTest(AbstractWidgetTest, unittest.TestCase):
OPTIONS = (
'activebackground', 'activeborderwidth', 'activeforeground',
'activerelief',
'background', 'borderwidth', 'cursor',
'disabledforeground', 'font', 'foreground',
'postcommand', 'relief', 'selectcolor', 'takefocus',
Expand All @@ -1401,6 +1399,8 @@ def test_indexcommand_none(self):
i = widget.index('none')
self.assertIsNone(i)

test_configure_activerelief = requires_tk(8, 7)(StandardOptionsTests.test_configure_activerelief)

def test_configure_postcommand(self):
widget = self.create()
self.checkCommandParam(widget, 'postcommand')
Expand Down
39 changes: 35 additions & 4 deletions Lib/test/test_tkinter/widget_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import re
import tkinter
from test.test_tkinter.support import (AbstractTkTest, tk_version,
from test.test_tkinter.support import (AbstractTkTest, requires_tk, tk_version,
pixels_conv, tcl_obj_eq)
import test.support

Expand All @@ -17,6 +17,7 @@ class AbstractWidgetTest(AbstractTkTest):
_clip_highlightthickness = True
_clip_pad = False
_clip_borderwidth = False
_allow_empty_justify = False

@property
def scaling(self):
Expand Down Expand Up @@ -200,6 +201,7 @@ def test_keys(self):
aliases = {
'bd': 'borderwidth',
'bg': 'background',
'bgimg': 'backgroundimage',
'fg': 'foreground',
'invcmd': 'invalidcommand',
'vcmd': 'validatecommand',
Expand Down Expand Up @@ -242,6 +244,10 @@ def test_configure_activeforeground(self):
widget = self.create()
self.checkColorParam(widget, 'activeforeground')

def test_configure_activerelief(self):
widget = self.create()
self.checkReliefParam(widget, 'activerelief')

def test_configure_anchor(self):
widget = self.create()
self.checkEnumParam(widget, 'anchor',
Expand All @@ -253,6 +259,11 @@ def test_configure_background(self):
if 'bg' in self.OPTIONS:
self.checkColorParam(widget, 'bg')

@requires_tk(8, 7)
def test_configure_backgroundimage(self):
widget = self.create()
self.checkImageParam(widget, 'backgroundimage')

def test_configure_bitmap(self):
widget = self.create()
self.checkParam(widget, 'bitmap', 'questhead')
Expand Down Expand Up @@ -299,8 +310,10 @@ def test_configure_font(self):
widget = self.create()
self.checkParam(widget, 'font',
'-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*')
self.checkInvalidParam(widget, 'font', '',
errmsg='font "" doesn\'t exist')
is_ttk = widget.__class__.__module__ == 'tkinter.ttk'
if not is_ttk:
self.checkInvalidParam(widget, 'font', '',
errmsg='font "" doesn\'t exist')

def test_configure_foreground(self):
widget = self.create()
Expand Down Expand Up @@ -355,7 +368,10 @@ def test_configure_jump(self):

def test_configure_justify(self):
widget = self.create()
self.checkEnumParam(widget, 'justify', 'left', 'right', 'center',
values = ('left', 'right', 'center')
if self._allow_empty_justify:
values += ('',)
self.checkEnumParam(widget, 'justify', *values,
fullname='justification')

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

@requires_tk(8, 7)
def test_configure_placeholder(self):
widget = self.create()
self.checkParam(widget, 'placeholder', 'xxx')

@requires_tk(8, 7)
def test_configure_placeholderforeground(self):
widget = self.create()
self.checkColorParam(widget, 'placeholderforeground')

def test_configure_relief(self):
widget = self.create()
self.checkReliefParam(widget, 'relief')
Expand Down Expand Up @@ -424,6 +450,11 @@ def test_configure_textvariable(self):
var = tkinter.StringVar(self.root)
self.checkVariableParam(widget, 'textvariable', var)

@requires_tk(8, 7)
def test_configure_tile(self):
widget = self.create()
self.checkBooleanParam(widget, 'tile')

def test_configure_troughcolor(self):
widget = self.create()
self.checkColorParam(widget, 'troughcolor')
Expand Down
79 changes: 58 additions & 21 deletions Lib/test/test_ttk/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def test_configure_labelwidget(self):


class AbstractLabelTest(AbstractWidgetTest):
_allow_empty_justify = True

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

test_configure_justify = requires_tk(8, 7)(StandardOptionsTests.test_configure_justify)

def test_configure_width(self):
widget = self.create()
self.checkParams(widget, 'width', 402, -402, 0)
Expand All @@ -203,28 +206,19 @@ class LabelTest(AbstractLabelTest, unittest.TestCase):
'underline', 'width', 'wraplength',
)
_conv_pixels = False
_allow_empty_justify = tk_version >= (8, 7)

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

def test_configure_font(self):
widget = self.create()
self.checkParam(widget, 'font',
'-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*')
test_configure_justify = StandardOptionsTests.test_configure_justify

def test_configure_justify(self):
widget = self.create()
values = ('left', 'right', 'center')
if tk_version >= (8, 7):
values += ('',)
self.checkEnumParam(widget, 'justify', *values,
fullname='justification')

@add_standard_options(StandardTtkOptionsTests)
class ButtonTest(AbstractLabelTest, unittest.TestCase):
OPTIONS = (
'class', 'command', 'compound', 'cursor', 'default',
'image', 'padding', 'state', 'style',
'image', 'justify', 'padding', 'state', 'style',
'takefocus', 'text', 'textvariable',
'underline', 'width',
)
Expand All @@ -249,7 +243,7 @@ def test_invoke(self):
class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
OPTIONS = (
'class', 'command', 'compound', 'cursor',
'image',
'image', 'justify',
'offvalue', 'onvalue',
'padding', 'state', 'style',
'takefocus', 'text', 'textvariable',
Expand Down Expand Up @@ -338,6 +332,7 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
'background', 'class', 'cursor',
'exportselection', 'font', 'foreground',
'invalidcommand', 'justify',
'placeholder', 'placeholderforeground',
'show', 'state', 'style', 'takefocus', 'textvariable',
'validate', 'validatecommand', 'width', 'xscrollcommand',
)
Expand Down Expand Up @@ -460,7 +455,8 @@ class ComboboxTest(EntryTest, unittest.TestCase):
OPTIONS = (
'background', 'class', 'cursor', 'exportselection',
'font', 'foreground', 'height', 'invalidcommand',
'justify', 'postcommand', 'show', 'state', 'style',
'justify', 'placeholder', 'placeholderforeground', 'postcommand',
'show', 'state', 'style',
'takefocus', 'textvariable',
'validate', 'validatecommand', 'values',
'width', 'xscrollcommand',
Expand Down Expand Up @@ -720,7 +716,7 @@ def test_sashpos(self):
class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
OPTIONS = (
'class', 'command', 'compound', 'cursor',
'image',
'image', 'justify',
'padding', 'state', 'style',
'takefocus', 'text', 'textvariable',
'underline', 'value', 'variable', 'width',
Expand Down Expand Up @@ -774,7 +770,7 @@ def cb_test():
class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
OPTIONS = (
'class', 'compound', 'cursor', 'direction',
'image', 'menu', 'padding', 'state', 'style',
'image', 'justify', 'menu', 'padding', 'state', 'style',
'takefocus', 'text', 'textvariable',
'underline', 'width',
)
Expand Down Expand Up @@ -906,16 +902,28 @@ def test_set(self):
@add_standard_options(StandardTtkOptionsTests)
class ProgressbarTest(AbstractWidgetTest, unittest.TestCase):
OPTIONS = (
'class', 'cursor', 'orient', 'length',
'mode', 'maximum', 'phase',
'anchor', 'class', 'cursor', 'font', 'foreground', 'justify',
'orient', 'length',
'mode', 'maximum', 'phase', 'text', 'wraplength',
'style', 'takefocus', 'value', 'variable',
)
_conv_pixels = False
_allow_empty_justify = True
default_orient = 'horizontal'

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

@requires_tk(8, 7)
def test_configure_anchor(self):
widget = self.create()
self.checkEnumParam(widget, 'anchor',
'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'center', '')

test_configure_font = requires_tk(8, 7)(StandardOptionsTests.test_configure_font)
test_configure_foreground = requires_tk(8, 7)(StandardOptionsTests.test_configure_foreground)
test_configure_justify = requires_tk(8, 7)(StandardTtkOptionsTests.test_configure_justify)

def test_configure_length(self):
widget = self.create()
self.checkPixelsParam(widget, 'length', 100.1, 56.7, '2i')
Expand All @@ -932,11 +940,15 @@ def test_configure_phase(self):
# XXX
pass

test_configure_text = requires_tk(8, 7)(StandardOptionsTests.test_configure_text)

def test_configure_value(self):
widget = self.create()
self.checkFloatParam(widget, 'value', 150.2, 77.7, 0, -10,
conv=False)

test_configure_wraplength = requires_tk(8, 7)(StandardOptionsTests.test_configure_wraplength)


@unittest.skipIf(sys.platform == 'darwin',
'ttk.Scrollbar is special on MacOSX')
Expand Down Expand Up @@ -1173,7 +1185,9 @@ class SpinboxTest(EntryTest, unittest.TestCase):
OPTIONS = (
'background', 'class', 'command', 'cursor', 'exportselection',
'font', 'foreground', 'format', 'from', 'increment',
'invalidcommand', 'justify', 'show', 'state', 'style',
'invalidcommand', 'justify',
'placeholder', 'placeholderforeground',
'show', 'state', 'style',
'takefocus', 'textvariable', 'to', 'validate', 'validatecommand',
'values', 'width', 'wrap', 'xscrollcommand',
)
Expand Down Expand Up @@ -1347,8 +1361,9 @@ def test_configure_values(self):
class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
OPTIONS = (
'class', 'columns', 'cursor', 'displaycolumns',
'height', 'padding', 'selectmode', 'show',
'style', 'takefocus', 'xscrollcommand', 'yscrollcommand',
'height', 'padding', 'selectmode', 'selecttype', 'show', 'striped',
'style', 'takefocus', 'titlecolumns', 'titleitems',
'xscrollcommand', 'yscrollcommand',
)

def setUp(self):
Expand Down Expand Up @@ -1393,6 +1408,11 @@ def test_configure_selectmode(self):
self.checkEnumParam(widget, 'selectmode',
'none', 'browse', 'extended')

@requires_tk(8, 7)
def test_configure_selecttype(self):
widget = self.create()
self.checkEnumParam(widget, 'selecttype', 'item', 'cell')

def test_configure_show(self):
widget = self.create()
self.checkParam(widget, 'show', 'tree headings',
Expand All @@ -1402,6 +1422,23 @@ def test_configure_show(self):
self.checkParam(widget, 'show', 'tree', expected=('tree',))
self.checkParam(widget, 'show', 'headings', expected=('headings',))

@requires_tk(8, 7)
def test_configure_striped(self):
widget = self.create()
self.checkBooleanParam(widget, 'striped')

@requires_tk(8, 7)
def test_configure_titlecolumns(self):
widget = self.create()
self.checkIntegerParam(widget, 'titlecolumns', 0, 1, 5)
self.checkInvalidParam(widget, 'titlecolumns', -2)

@requires_tk(8, 7)
def test_configure_titleitems(self):
widget = self.create()
self.checkIntegerParam(widget, 'titleitems', 0, 1, 5)
self.checkInvalidParam(widget, 'titleitems', -2)

def test_bbox(self):
self.tv.pack()
self.assertEqual(self.tv.bbox(''), '')
Expand Down
Loading