Skip to content

Commit

Permalink
Update ttk tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
culler committed Sep 16, 2024
1 parent 0d2337a commit af8830d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 65 deletions.
47 changes: 23 additions & 24 deletions Lib/test/test_tkinter/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from test.test_tkinter.support import (requires_tk, tk_version,
get_tk_patchlevel, widget_eq,
AbstractDefaultRootTest)
if tk_version < (9,0):
if tk_version < (9, 0):
from test.test_tkinter.support import messages_v1 as messages, is_pixel_str
else:
from test.test_tkinter.support import messages_v2 as messages, is_pixel_str
Expand All @@ -26,13 +26,12 @@
def float_round(x):
return float(round(x))


class AbstractToplevelTest(AbstractWidgetTest, PixelSizeTests):
_no_round = {'padx', 'pady'} if tk_version < (9,0) else {
_no_round = {'padx', 'pady'} if tk_version < (9, 0) else {
'borderwidth', 'height', 'highlightthickness', 'padx', 'pady',
'width'}
_clipped = {
'highlightthickness'} if tk_version < (9,0) else {
'highlightthickness'} if tk_version < (9, 0) else {
'borderwidth', 'height', 'highlightthickness', 'padx', 'pady',
'width'}

Expand Down Expand Up @@ -121,7 +120,7 @@ class FrameTest(AbstractToplevelTest, unittest.TestCase):
'highlightbackground', 'highlightcolor', 'highlightthickness',
'padx', 'pady', 'relief', 'takefocus', 'tile', 'visual', 'width',
)
_no_round = {'padx', 'pady'} if tk_version < (9,0) else {
_no_round = {'padx', 'pady'} if tk_version < (9, 0) else {
'borderwidth', 'height', 'highlightthickness', 'padx', 'pady',
'width'}

Expand All @@ -139,7 +138,7 @@ class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
'labelanchor', 'labelwidget', 'padx', 'pady', 'relief',
'takefocus', 'text', 'visual', 'width',
)
_no_round = {'padx', 'pady'} if tk_version < (9,0) else {
_no_round = {'padx', 'pady'} if tk_version < (9, 0) else {
'borderwidth', 'height', 'highlightthickness', 'padx', 'pady',
'width'}

Expand All @@ -162,7 +161,7 @@ def test_configure_labelwidget(self):
# Label, Button, Checkbutton, Radiobutton, MenuButton
class AbstractLabelTest(AbstractWidgetTest, IntegerSizeTests):
_rounds_pixels = False
_clipped = set() if tk_version < (9,0) else {
_clipped = {} if tk_version < (9, 0) else {
'borderwidth', 'insertborderwidth', 'highlightthickness',
'padx', 'pady'}

Expand Down Expand Up @@ -293,9 +292,9 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
'takefocus', 'text', 'textvariable',
'underline', 'width', 'wraplength',
)
_rounds_pixels = tk_version < (9,0)
_rounds_pixels = tk_version < (9, 0)
_clipped = {'highlightthickness', 'padx', 'pady'
} if tk_version < (9,0) else { 'insertborderwidth',
} if tk_version < (9, 0) else { 'insertborderwidth',
'highlightthickness', 'padx', 'pady'}

def create(self, **kwargs):
Expand Down Expand Up @@ -346,8 +345,8 @@ def test_bad_kwarg(self):

@add_configure_tests(IntegerSizeTests, StandardOptionsTests)
class EntryTest(AbstractWidgetTest, unittest.TestCase):
_rounds_pixels = (tk_version < (9,0))
_clipped = {'highlightthickness'} if tk_version < (9,0) else {
_rounds_pixels = (tk_version < (9, 0))
_clipped = {'highlightthickness'} if tk_version < (9, 0) else {
'highlightthickness', 'borderwidth', 'insertborderwidth',
'selectborderwidth'}

Expand Down Expand Up @@ -601,7 +600,7 @@ class TextTest(AbstractWidgetTest, unittest.TestCase):
'tabs', 'tabstyle', 'takefocus', 'undo', 'width', 'wrap',
'xscrollcommand', 'yscrollcommand',
)
_rounds_pixels = (tk_version < (9,0))
_rounds_pixels = (tk_version < (9, 0))
_no_round = {'selectborderwidth'}
_clipped = {'highlightthickness'}

Expand Down Expand Up @@ -996,9 +995,9 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase):
'selectmode', 'setgrid', 'state',
'takefocus', 'width', 'xscrollcommand', 'yscrollcommand',
)
_rounds_pixels = (tk_version < (9,0))
_rounds_pixels = (tk_version < (9, 0))
_clipped = {'highlightthickness'
} if tk_version < (9,0) else { 'borderwidth',
} if tk_version < (9, 0) else { 'borderwidth',
'highlightthickness', 'selectborderwidth'}

def create(self, **kwargs):
Expand Down Expand Up @@ -1137,7 +1136,7 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase):
'resolution', 'showvalue', 'sliderlength', 'sliderrelief', 'state',
'takefocus', 'tickinterval', 'to', 'troughcolor', 'variable', 'width',
)
_rounds_pixels = (tk_version < (9,0))
_rounds_pixels = (tk_version < (9, 0))
_clipped = {'highlightthickness'}
default_orient = 'vertical'

Expand Down Expand Up @@ -1208,7 +1207,7 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
'takefocus', 'troughcolor', 'width',
)
_rounds_pixels = True
_clipped = {'highlightthickness'} if tk_version < (9,0) else{
_clipped = {'highlightthickness'} if tk_version < (9, 0) else{
'borderwidth', 'highlightthickness'}
_stringify = True
default_orient = 'vertical'
Expand Down Expand Up @@ -1261,7 +1260,7 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
_rounds_pixels = True
_no_round = {'handlesize', 'height', 'proxyborderwidth',
'sashwidth', 'selectborderwidth', 'width'
} if tk_version < (9,0) else {'borderwidth',
} if tk_version < (9, 0) else {'borderwidth',
'handlepad', 'handlesize',
'height', 'proxyborderwidth', 'sashpad',
'sashwidth', 'selectborderwidth', 'width'}
Expand Down Expand Up @@ -1394,13 +1393,13 @@ def test_paneconfigure_minsize(self):

def test_paneconfigure_padx(self):
p, b, c = self.create2()
self.check_paneconfigure(p, b, 'padx', 1.3, 1 if tk_version < (9,0) else 1.3)
self.check_paneconfigure(p, b, 'padx', 1.3, 1 if tk_version < (9, 0) else 1.3)
self.check_paneconfigure_bad(p, b, 'padx',
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('badValue'))

def test_paneconfigure_pady(self):
p, b, c = self.create2()
self.check_paneconfigure(p, b, 'pady', 1.3, 1 if tk_version < (9,0) else 1.3)
self.check_paneconfigure(p, b, 'pady', 1.3, 1 if tk_version < (9, 0) else 1.3)
self.check_paneconfigure_bad(p, b, 'pady',
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('badValue'))

Expand Down Expand Up @@ -1436,7 +1435,7 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
'tearoff', 'tearoffcommand', 'title', 'type',
)
_rounds_pixels = False
_clipped = set()
_clipped = {}

def create(self, **kwargs):
return tkinter.Menu(self.root, **kwargs)
Expand Down Expand Up @@ -1514,9 +1513,9 @@ class MessageTest(AbstractWidgetTest, unittest.TestCase):
'justify', 'padx', 'pady', 'relief',
'takefocus', 'text', 'textvariable', 'width',
)
_rounds_pixels = (tk_version < (9,0))
_rounds_pixels = (tk_version < (9, 0))
_no_round = {'padx', 'pady'}
_clipped = {'highlightthickness'} if tk_version < (9,0) else {
_clipped = {'highlightthickness'} if tk_version < (9, 0) else {
'borderwidth', 'highlightthickness', 'padx', 'pady'}

def create(self, **kwargs):
Expand All @@ -1529,13 +1528,13 @@ def test_configure_aspect(self):
def test_configure_padx(self):
widget = self.create()
self.checkPixelsParam(widget, 'padx', 3, 4.4, 5.6, '12m')#,
expected = -2 if tk_version < (9,0) else self._default_pixels
expected = -2 if tk_version < (9, 0) else self._default_pixels
self.checkParam(widget, 'padx', -2, expected=expected)

def test_configure_pady(self):
widget = self.create()
self.checkPixelsParam(widget, 'pady', 3, 4.4, 5.6, '12m')#,
expected = -2 if tk_version < (9,0) else self._default_pixels
expected = -2 if tk_version < (9, 0) else self._default_pixels
self.checkParam(widget, 'pady', -2, expected=expected)

def test_configure_width(self):
Expand Down
13 changes: 0 additions & 13 deletions Lib/test/test_tkinter/widget_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,6 @@ def checkEnumParam(self, widget, name, *values,
errmsg = 'bad' + errmsg2
self.checkInvalidParam(widget, name, 'spam', errmsg=errmsg)

def XcheckPixelsParam(self, widget, name, *values, conv=None, **kwargs):
# Some widget options can be specified as distances which are
# independent from the screen resolution. These distances are
# given as a string consisting of a number followed by a single
# character representing the unit - c for cm, m for mm, p for point
# or i for inch. Tk can convert such a value to pixels using the
# current resolution and scaling, but the cget command *should* return the
# string value. Some widgets don't follow this convention (yet)
# and instead return a number. An option which violates the
# convention should be listed in the _converts attribute of the
# widget test object.
pass

def checkPixelsParam(self, widget, name, *values, conv=None, **kwargs):
if not self._rounds_pixels or name in self._no_round:
conv = False
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_ttk/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ def test_element_create_image(self):
foreground='blue', background='yellow')
img3 = tkinter.BitmapImage(master=self.root, file=imgfile,
foreground='white', background='black')
style.element_create('Button.button', 'image',
style.element_create('Button.testbutton', 'image',
img1, ('pressed', img2), ('active', img3),
border=(2, 4), sticky='we')
self.assertIn('Button.button', style.element_names())
self.assertIn('Button.testbutton', style.element_names())

style.layout('Button', [('Button.button', {'sticky': 'news'})])
style.layout('Button', [('Button.testbutton', {'sticky': 'news'})])
b = ttk.Button(self.root, style='Button')
b.pack(expand=True, fill='both')
self.assertEqual(b.winfo_reqwidth(), 16)
Expand Down
Loading

0 comments on commit af8830d

Please sign in to comment.