[Python-checkins] cpython (merge 3.3 -> default): Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).

serhiy.storchaka python-checkins at python.org
Sat Nov 9 20:18:03 CET 2013


http://hg.python.org/cpython/rev/2834e410d1ae
changeset:   87023:2834e410d1ae
parent:      87020:6952c14a3f75
parent:      87022:204e66190dbb
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat Nov 09 21:17:37 2013 +0200
summary:
  Fix Tkinter tests on Tk 8.5 with patchlevel < 8.5.11 (issue #19085).

files:
  Lib/tkinter/test/support.py                   |  15 +++++
  Lib/tkinter/test/test_tkinter/test_widgets.py |  11 ++-
  Lib/tkinter/test/widget_tests.py              |  28 ++-------
  3 files changed, 31 insertions(+), 23 deletions(-)


diff --git a/Lib/tkinter/test/support.py b/Lib/tkinter/test/support.py
--- a/Lib/tkinter/test/support.py
+++ b/Lib/tkinter/test/support.py
@@ -86,6 +86,21 @@
     return unittest.skipUnless(tcl_version >= version,
             'requires Tcl version >= ' + '.'.join(map(str, version)))
 
+_tk_patchlevel = None
+def get_tk_patchlevel():
+    global _tk_patchlevel
+    if _tk_patchlevel is None:
+        tcl = tkinter.Tcl()
+        patchlevel = []
+        for x in tcl.call('info', 'patchlevel').split('.'):
+            try:
+                x = int(x, 10)
+            except ValueError:
+                x = -1
+            patchlevel.append(x)
+        _tk_patchlevel = tuple(patchlevel)
+    return _tk_patchlevel
+
 units = {
     'c': 72 / 2.54,     # centimeters
     'i': 72,            # inches
diff --git a/Lib/tkinter/test/test_tkinter/test_widgets.py b/Lib/tkinter/test/test_tkinter/test_widgets.py
--- a/Lib/tkinter/test/test_tkinter/test_widgets.py
+++ b/Lib/tkinter/test/test_tkinter/test_widgets.py
@@ -3,7 +3,8 @@
 import os
 from test.support import requires
 
-from tkinter.test.support import tcl_version, requires_tcl, widget_eq
+from tkinter.test.support import (tcl_version, requires_tcl,
+                                  get_tk_patchlevel, widget_eq)
 from tkinter.test.widget_tests import (
     add_standard_options, noconv, pixels_round,
     AbstractWidgetTest, StandardOptionsTests, IntegerSizeTests, PixelSizeTests)
@@ -539,7 +540,7 @@
     def test_selectborderwidth(self):
         widget = self.create()
         self.checkPixelsParam(widget, 'selectborderwidth',
-                              1.3, 2.6, -2, '10p', conv=False,
+                              1.3, 2.6, -2, '10p', conv=noconv,
                               keep_orig=tcl_version >= (8, 5))
 
     def test_spacing1(self):
@@ -580,7 +581,11 @@
 
     def test_tabs(self):
         widget = self.create()
-        self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'))
+        if get_tk_patchlevel() < (8, 5, 11):
+            self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'),
+                            expected=('10.2', '20.7', '1i', '2i'))
+        else:
+            self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'))
         self.checkParam(widget, 'tabs', '10.2 20.7 1i 2i',
                         expected=('10.2', '20.7', '1i', '2i'))
         self.checkParam(widget, 'tabs', '2c left 4c 6c center',
diff --git a/Lib/tkinter/test/widget_tests.py b/Lib/tkinter/test/widget_tests.py
--- a/Lib/tkinter/test/widget_tests.py
+++ b/Lib/tkinter/test/widget_tests.py
@@ -2,28 +2,19 @@
 
 import tkinter
 from tkinter.ttk import setup_master, Scale
-from tkinter.test.support import (tcl_version, requires_tcl, pixels_conv,
-                                  tcl_obj_eq)
+from tkinter.test.support import (tcl_version, requires_tcl, get_tk_patchlevel,
+                                  pixels_conv, tcl_obj_eq)
 
 
-noconv = str if tcl_version < (8, 5) else False
+noconv = False
+if get_tk_patchlevel() < (8, 5, 11):
+    noconv = str
 
 pixels_round = round
-if tcl_version[:2] == (8, 5):
+if get_tk_patchlevel()[:3] == (8, 5, 11):
     # Issue #19085: Workaround a bug in Tk
     # http://core.tcl.tk/tk/info/3497848
-    _pixels_round = None
-    def pixels_round(x):
-        global _pixels_round
-        if _pixels_round is None:
-            root = setup_master()
-            patchlevel = root.call('info', 'patchlevel')
-            patchlevel = tuple(map(int, patchlevel.split('.')))
-            if patchlevel < (8, 5, 12):
-                _pixels_round = int
-            else:
-                _pixels_round = round
-        return _pixels_round(x)
+    pixels_round = int
 
 
 _sentinel = object()
@@ -406,10 +397,7 @@
 
     def test_wraplength(self):
         widget = self.create()
-        if tcl_version < (8, 5):
-            self.checkPixelsParam(widget, 'wraplength', 100)
-        else:
-            self.checkParams(widget, 'wraplength', 100)
+        self.checkPixelsParam(widget, 'wraplength', 100)
 
     def test_xscrollcommand(self):
         widget = self.create()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list