mirror of https://github.com/python/cpython
gh-120873: Add tests for new widget options in Tk 8.7 (GH-120877)
This commit is contained in:
parent
974a978631
commit
a046c848c1
|
@ -61,11 +61,11 @@ class AbstractToplevelTest(AbstractWidgetTest, PixelSizeTests):
|
|||
@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):
|
||||
|
@ -104,10 +104,10 @@ class ToplevelTest(AbstractToplevelTest, unittest.TestCase):
|
|||
@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):
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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')
|
||||
|
@ -1386,6 +1383,7 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
|
|||
class MenuTest(AbstractWidgetTest, unittest.TestCase):
|
||||
OPTIONS = (
|
||||
'activebackground', 'activeborderwidth', 'activeforeground',
|
||||
'activerelief',
|
||||
'background', 'borderwidth', 'cursor',
|
||||
'disabledforeground', 'font', 'foreground',
|
||||
'postcommand', 'relief', 'selectcolor', 'takefocus',
|
||||
|
@ -1401,6 +1399,8 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
|
|||
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')
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -17,6 +17,7 @@ class AbstractWidgetTest(AbstractTkTest):
|
|||
_clip_highlightthickness = True
|
||||
_clip_pad = False
|
||||
_clip_borderwidth = False
|
||||
_allow_empty_justify = False
|
||||
|
||||
@property
|
||||
def scaling(self):
|
||||
|
@ -200,6 +201,7 @@ class AbstractWidgetTest(AbstractTkTest):
|
|||
aliases = {
|
||||
'bd': 'borderwidth',
|
||||
'bg': 'background',
|
||||
'bgimg': 'backgroundimage',
|
||||
'fg': 'foreground',
|
||||
'invcmd': 'invalidcommand',
|
||||
'vcmd': 'validatecommand',
|
||||
|
@ -242,6 +244,10 @@ class StandardOptionsTests:
|
|||
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',
|
||||
|
@ -253,6 +259,11 @@ class StandardOptionsTests:
|
|||
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')
|
||||
|
@ -299,8 +310,10 @@ class StandardOptionsTests:
|
|||
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()
|
||||
|
@ -355,7 +368,10 @@ class StandardOptionsTests:
|
|||
|
||||
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):
|
||||
|
@ -379,6 +395,16 @@ class StandardOptionsTests:
|
|||
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')
|
||||
|
@ -424,6 +450,11 @@ class StandardOptionsTests:
|
|||
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')
|
||||
|
|
|
@ -167,6 +167,7 @@ class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
|
|||
|
||||
|
||||
class AbstractLabelTest(AbstractWidgetTest):
|
||||
_allow_empty_justify = True
|
||||
|
||||
def checkImageParam(self, widget, name):
|
||||
image = tkinter.PhotoImage(master=self.root, name='image1')
|
||||
|
@ -188,6 +189,8 @@ class AbstractLabelTest(AbstractWidgetTest):
|
|||
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)
|
||||
|
@ -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',
|
||||
)
|
||||
|
@ -249,7 +243,7 @@ class ButtonTest(AbstractLabelTest, unittest.TestCase):
|
|||
class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
|
||||
OPTIONS = (
|
||||
'class', 'command', 'compound', 'cursor',
|
||||
'image',
|
||||
'image', 'justify',
|
||||
'offvalue', 'onvalue',
|
||||
'padding', 'state', 'style',
|
||||
'takefocus', 'text', 'textvariable',
|
||||
|
@ -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',
|
||||
)
|
||||
|
@ -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',
|
||||
|
@ -720,7 +716,7 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
|
|||
class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
|
||||
OPTIONS = (
|
||||
'class', 'command', 'compound', 'cursor',
|
||||
'image',
|
||||
'image', 'justify',
|
||||
'padding', 'state', 'style',
|
||||
'takefocus', 'text', 'textvariable',
|
||||
'underline', 'value', 'variable', 'width',
|
||||
|
@ -774,7 +770,7 @@ class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
|
|||
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',
|
||||
)
|
||||
|
@ -906,16 +902,28 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase):
|
|||
@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')
|
||||
|
@ -932,11 +940,15 @@ class ProgressbarTest(AbstractWidgetTest, unittest.TestCase):
|
|||
# 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')
|
||||
|
@ -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',
|
||||
)
|
||||
|
@ -1347,8 +1361,9 @@ class SpinboxTest(EntryTest, unittest.TestCase):
|
|||
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):
|
||||
|
@ -1393,6 +1408,11 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
|
|||
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',
|
||||
|
@ -1402,6 +1422,23 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
|
|||
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(''), '')
|
||||
|
|
Loading…
Reference in New Issue