Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35ac05e

Browse files
Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).
2 parents 86e83a0 + affb9b2 commit 35ac05e

3 files changed

Lines changed: 31 additions & 23 deletions

File tree

Lib/tkinter/test/support.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ def requires_tcl(*version):
8686
return unittest.skipUnless(tcl_version >= version,
8787
'requires Tcl version >= ' + '.'.join(map(str, version)))
8888

89+
_tk_patchlevel = None
90+
def get_tk_patchlevel():
91+
global _tk_patchlevel
92+
if _tk_patchlevel is None:
93+
tcl = tkinter.Tcl()
94+
patchlevel = []
95+
for x in tcl.call('info', 'patchlevel').split('.'):
96+
try:
97+
x = int(x, 10)
98+
except ValueError:
99+
x = -1
100+
patchlevel.append(x)
101+
_tk_patchlevel = tuple(patchlevel)
102+
return _tk_patchlevel
103+
89104
units = {
90105
'c': 72 / 2.54, # centimeters
91106
'i': 72, # inches

Lib/tkinter/test/test_tkinter/test_widgets.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44
from test.support import requires
55

6-
from tkinter.test.support import tcl_version, requires_tcl, widget_eq
6+
from tkinter.test.support import (tcl_version, requires_tcl,
7+
get_tk_patchlevel, widget_eq)
78
from tkinter.test.widget_tests import (
89
add_standard_options, noconv, pixels_round,
910
AbstractWidgetTest, StandardOptionsTests, IntegerSizeTests, PixelSizeTests)
@@ -539,7 +540,7 @@ def test_insertunfocussed(self):
539540
def test_selectborderwidth(self):
540541
widget = self.create()
541542
self.checkPixelsParam(widget, 'selectborderwidth',
542-
1.3, 2.6, -2, '10p', conv=False,
543+
1.3, 2.6, -2, '10p', conv=noconv,
543544
keep_orig=tcl_version >= (8, 5))
544545

545546
def test_spacing1(self):
@@ -580,7 +581,11 @@ def test_state(self):
580581

581582
def test_tabs(self):
582583
widget = self.create()
583-
self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'))
584+
if get_tk_patchlevel() < (8, 5, 11):
585+
self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'),
586+
expected=('10.2', '20.7', '1i', '2i'))
587+
else:
588+
self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'))
584589
self.checkParam(widget, 'tabs', '10.2 20.7 1i 2i',
585590
expected=('10.2', '20.7', '1i', '2i'))
586591
self.checkParam(widget, 'tabs', '2c left 4c 6c center',

Lib/tkinter/test/widget_tests.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,19 @@
22

33
import tkinter
44
from tkinter.ttk import setup_master, Scale
5-
from tkinter.test.support import (tcl_version, requires_tcl, pixels_conv,
6-
tcl_obj_eq)
5+
from tkinter.test.support import (tcl_version, requires_tcl, get_tk_patchlevel,
6+
pixels_conv, tcl_obj_eq)
77

88

9-
noconv = str if tcl_version < (8, 5) else False
9+
noconv = False
10+
if get_tk_patchlevel() < (8, 5, 11):
11+
noconv = str
1012

1113
pixels_round = round
12-
if tcl_version[:2] == (8, 5):
14+
if get_tk_patchlevel()[:3] == (8, 5, 11):
1315
# Issue #19085: Workaround a bug in Tk
1416
# http://core.tcl.tk/tk/info/3497848
15-
_pixels_round = None
16-
def pixels_round(x):
17-
global _pixels_round
18-
if _pixels_round is None:
19-
root = setup_master()
20-
patchlevel = root.call('info', 'patchlevel')
21-
patchlevel = tuple(map(int, patchlevel.split('.')))
22-
if patchlevel < (8, 5, 12):
23-
_pixels_round = int
24-
else:
25-
_pixels_round = round
26-
return _pixels_round(x)
17+
pixels_round = int
2718

2819

2920
_sentinel = object()
@@ -406,10 +397,7 @@ def test_underline(self):
406397

407398
def test_wraplength(self):
408399
widget = self.create()
409-
if tcl_version < (8, 5):
410-
self.checkPixelsParam(widget, 'wraplength', 100)
411-
else:
412-
self.checkParams(widget, 'wraplength', 100)
400+
self.checkPixelsParam(widget, 'wraplength', 100)
413401

414402
def test_xscrollcommand(self):
415403
widget = self.create()

0 commit comments

Comments
 (0)