[3.12] gh-120873: Add tests for new widget options in Tk 8.7 (GH-120877) (GH-120880)

(cherry picked from commit a046c848c1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-06-22 15:38:08 +02:00 committed by GitHub
parent 22a276ff15
commit 7f64c2fb43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 104 additions and 36 deletions

View file

@ -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(''), '')