Skip to content

Commit af8830d

Browse files
committed
Update ttk tests.
1 parent 0d2337a commit af8830d

File tree

4 files changed

+75
-65
lines changed

4 files changed

+75
-65
lines changed

Lib/test/test_tkinter/test_widgets.py

+23-24
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from test.test_tkinter.support import (requires_tk, tk_version,
88
get_tk_patchlevel, widget_eq,
99
AbstractDefaultRootTest)
10-
if tk_version < (9,0):
10+
if tk_version < (9, 0):
1111
from test.test_tkinter.support import messages_v1 as messages, is_pixel_str
1212
else:
1313
from test.test_tkinter.support import messages_v2 as messages, is_pixel_str
@@ -26,13 +26,12 @@
2626
def float_round(x):
2727
return float(round(x))
2828

29-
3029
class AbstractToplevelTest(AbstractWidgetTest, PixelSizeTests):
31-
_no_round = {'padx', 'pady'} if tk_version < (9,0) else {
30+
_no_round = {'padx', 'pady'} if tk_version < (9, 0) else {
3231
'borderwidth', 'height', 'highlightthickness', 'padx', 'pady',
3332
'width'}
3433
_clipped = {
35-
'highlightthickness'} if tk_version < (9,0) else {
34+
'highlightthickness'} if tk_version < (9, 0) else {
3635
'borderwidth', 'height', 'highlightthickness', 'padx', 'pady',
3736
'width'}
3837

@@ -121,7 +120,7 @@ class FrameTest(AbstractToplevelTest, unittest.TestCase):
121120
'highlightbackground', 'highlightcolor', 'highlightthickness',
122121
'padx', 'pady', 'relief', 'takefocus', 'tile', 'visual', 'width',
123122
)
124-
_no_round = {'padx', 'pady'} if tk_version < (9,0) else {
123+
_no_round = {'padx', 'pady'} if tk_version < (9, 0) else {
125124
'borderwidth', 'height', 'highlightthickness', 'padx', 'pady',
126125
'width'}
127126

@@ -139,7 +138,7 @@ class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
139138
'labelanchor', 'labelwidget', 'padx', 'pady', 'relief',
140139
'takefocus', 'text', 'visual', 'width',
141140
)
142-
_no_round = {'padx', 'pady'} if tk_version < (9,0) else {
141+
_no_round = {'padx', 'pady'} if tk_version < (9, 0) else {
143142
'borderwidth', 'height', 'highlightthickness', 'padx', 'pady',
144143
'width'}
145144

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

@@ -293,9 +292,9 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
293292
'takefocus', 'text', 'textvariable',
294293
'underline', 'width', 'wraplength',
295294
)
296-
_rounds_pixels = tk_version < (9,0)
295+
_rounds_pixels = tk_version < (9, 0)
297296
_clipped = {'highlightthickness', 'padx', 'pady'
298-
} if tk_version < (9,0) else { 'insertborderwidth',
297+
} if tk_version < (9, 0) else { 'insertborderwidth',
299298
'highlightthickness', 'padx', 'pady'}
300299

301300
def create(self, **kwargs):
@@ -346,8 +345,8 @@ def test_bad_kwarg(self):
346345

347346
@add_configure_tests(IntegerSizeTests, StandardOptionsTests)
348347
class EntryTest(AbstractWidgetTest, unittest.TestCase):
349-
_rounds_pixels = (tk_version < (9,0))
350-
_clipped = {'highlightthickness'} if tk_version < (9,0) else {
348+
_rounds_pixels = (tk_version < (9, 0))
349+
_clipped = {'highlightthickness'} if tk_version < (9, 0) else {
351350
'highlightthickness', 'borderwidth', 'insertborderwidth',
352351
'selectborderwidth'}
353352

@@ -601,7 +600,7 @@ class TextTest(AbstractWidgetTest, unittest.TestCase):
601600
'tabs', 'tabstyle', 'takefocus', 'undo', 'width', 'wrap',
602601
'xscrollcommand', 'yscrollcommand',
603602
)
604-
_rounds_pixels = (tk_version < (9,0))
603+
_rounds_pixels = (tk_version < (9, 0))
605604
_no_round = {'selectborderwidth'}
606605
_clipped = {'highlightthickness'}
607606

@@ -996,9 +995,9 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase):
996995
'selectmode', 'setgrid', 'state',
997996
'takefocus', 'width', 'xscrollcommand', 'yscrollcommand',
998997
)
999-
_rounds_pixels = (tk_version < (9,0))
998+
_rounds_pixels = (tk_version < (9, 0))
1000999
_clipped = {'highlightthickness'
1001-
} if tk_version < (9,0) else { 'borderwidth',
1000+
} if tk_version < (9, 0) else { 'borderwidth',
10021001
'highlightthickness', 'selectborderwidth'}
10031002

10041003
def create(self, **kwargs):
@@ -1137,7 +1136,7 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase):
11371136
'resolution', 'showvalue', 'sliderlength', 'sliderrelief', 'state',
11381137
'takefocus', 'tickinterval', 'to', 'troughcolor', 'variable', 'width',
11391138
)
1140-
_rounds_pixels = (tk_version < (9,0))
1139+
_rounds_pixels = (tk_version < (9, 0))
11411140
_clipped = {'highlightthickness'}
11421141
default_orient = 'vertical'
11431142

@@ -1208,7 +1207,7 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
12081207
'takefocus', 'troughcolor', 'width',
12091208
)
12101209
_rounds_pixels = True
1211-
_clipped = {'highlightthickness'} if tk_version < (9,0) else{
1210+
_clipped = {'highlightthickness'} if tk_version < (9, 0) else{
12121211
'borderwidth', 'highlightthickness'}
12131212
_stringify = True
12141213
default_orient = 'vertical'
@@ -1261,7 +1260,7 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
12611260
_rounds_pixels = True
12621261
_no_round = {'handlesize', 'height', 'proxyborderwidth',
12631262
'sashwidth', 'selectborderwidth', 'width'
1264-
} if tk_version < (9,0) else {'borderwidth',
1263+
} if tk_version < (9, 0) else {'borderwidth',
12651264
'handlepad', 'handlesize',
12661265
'height', 'proxyborderwidth', 'sashpad',
12671266
'sashwidth', 'selectborderwidth', 'width'}
@@ -1394,13 +1393,13 @@ def test_paneconfigure_minsize(self):
13941393

13951394
def test_paneconfigure_padx(self):
13961395
p, b, c = self.create2()
1397-
self.check_paneconfigure(p, b, 'padx', 1.3, 1 if tk_version < (9,0) else 1.3)
1396+
self.check_paneconfigure(p, b, 'padx', 1.3, 1 if tk_version < (9, 0) else 1.3)
13981397
self.check_paneconfigure_bad(p, b, 'padx',
13991398
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('badValue'))
14001399

14011400
def test_paneconfigure_pady(self):
14021401
p, b, c = self.create2()
1403-
self.check_paneconfigure(p, b, 'pady', 1.3, 1 if tk_version < (9,0) else 1.3)
1402+
self.check_paneconfigure(p, b, 'pady', 1.3, 1 if tk_version < (9, 0) else 1.3)
14041403
self.check_paneconfigure_bad(p, b, 'pady',
14051404
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('badValue'))
14061405

@@ -1436,7 +1435,7 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
14361435
'tearoff', 'tearoffcommand', 'title', 'type',
14371436
)
14381437
_rounds_pixels = False
1439-
_clipped = set()
1438+
_clipped = {}
14401439

14411440
def create(self, **kwargs):
14421441
return tkinter.Menu(self.root, **kwargs)
@@ -1514,9 +1513,9 @@ class MessageTest(AbstractWidgetTest, unittest.TestCase):
15141513
'justify', 'padx', 'pady', 'relief',
15151514
'takefocus', 'text', 'textvariable', 'width',
15161515
)
1517-
_rounds_pixels = (tk_version < (9,0))
1516+
_rounds_pixels = (tk_version < (9, 0))
15181517
_no_round = {'padx', 'pady'}
1519-
_clipped = {'highlightthickness'} if tk_version < (9,0) else {
1518+
_clipped = {'highlightthickness'} if tk_version < (9, 0) else {
15201519
'borderwidth', 'highlightthickness', 'padx', 'pady'}
15211520

15221521
def create(self, **kwargs):
@@ -1529,13 +1528,13 @@ def test_configure_aspect(self):
15291528
def test_configure_padx(self):
15301529
widget = self.create()
15311530
self.checkPixelsParam(widget, 'padx', 3, 4.4, 5.6, '12m')#,
1532-
expected = -2 if tk_version < (9,0) else self._default_pixels
1531+
expected = -2 if tk_version < (9, 0) else self._default_pixels
15331532
self.checkParam(widget, 'padx', -2, expected=expected)
15341533

15351534
def test_configure_pady(self):
15361535
widget = self.create()
15371536
self.checkPixelsParam(widget, 'pady', 3, 4.4, 5.6, '12m')#,
1538-
expected = -2 if tk_version < (9,0) else self._default_pixels
1537+
expected = -2 if tk_version < (9, 0) else self._default_pixels
15391538
self.checkParam(widget, 'pady', -2, expected=expected)
15401539

15411540
def test_configure_width(self):

Lib/test/test_tkinter/widget_tests.py

-13
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,6 @@ def checkEnumParam(self, widget, name, *values,
146146
errmsg = 'bad' + errmsg2
147147
self.checkInvalidParam(widget, name, 'spam', errmsg=errmsg)
148148

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

Lib/test/test_ttk/test_style.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ def test_element_create_image(self):
227227
foreground='blue', background='yellow')
228228
img3 = tkinter.BitmapImage(master=self.root, file=imgfile,
229229
foreground='white', background='black')
230-
style.element_create('Button.button', 'image',
230+
style.element_create('Button.testbutton', 'image',
231231
img1, ('pressed', img2), ('active', img3),
232232
border=(2, 4), sticky='we')
233-
self.assertIn('Button.button', style.element_names())
233+
self.assertIn('Button.testbutton', style.element_names())
234234

235-
style.layout('Button', [('Button.button', {'sticky': 'news'})])
235+
style.layout('Button', [('Button.testbutton', {'sticky': 'news'})])
236236
b = ttk.Button(self.root, style='Button')
237237
b.pack(expand=True, fill='both')
238238
self.assertEqual(b.winfo_reqwidth(), 16)

0 commit comments

Comments
 (0)