]> granicus.if.org Git - python/commitdiff
Issue #19085: Fix running test_ttk_textonly on displayless host.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 4 Nov 2013 21:05:37 +0000 (23:05 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 4 Nov 2013 21:05:37 +0000 (23:05 +0200)
Lib/tkinter/test/test_tkinter/test_widgets.py
Lib/tkinter/test/widget_tests.py

index 1ed306a7ebb3f6d02226cfd3a894859e1361ac5c..8a768edfa89aec62d7e6d4780084689e025ededb 100644 (file)
@@ -4,7 +4,8 @@ import os
 from test.support import requires
 
 from tkinter.test.support import tcl_version, requires_tcl, widget_eq
-from tkinter.test.widget_tests import (add_standard_options, noconv,
+from tkinter.test.widget_tests import (
+    add_standard_options, noconv, pixels_round,
     AbstractWidgetTest, StandardOptionsTests, IntegerSizeTests, PixelSizeTests)
 
 requires('gui')
@@ -243,7 +244,7 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
         'takefocus', 'text', 'textvariable',
         'underline', 'width', 'wraplength',
     )
-    _conv_pixels = AbstractWidgetTest._conv_pixels
+    _conv_pixels = staticmethod(pixels_round)
 
     def _create(self, **kwargs):
         return tkinter.Menubutton(self.root, **kwargs)
index 28cc9861790673d25b75778e22c715ec189e67bb..e488565087155a6864ae098cfe8f4f9b23488cc2 100644 (file)
@@ -12,18 +12,24 @@ pixels_round = round
 if tcl_version[:2] == (8, 5):
     # Issue #19085: Workaround a bug in Tk
     # http://core.tcl.tk/tk/info/3497848
-    root = setup_master()
-    patchlevel = root.call('info', 'patchlevel')
-    patchlevel = tuple(map(int, patchlevel.split('.')))
-    if patchlevel < (8, 5, 12):
-        pixels_round = int
-    del root
+    _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 = int_round
+        return _pixels_round(x)
 
 
 _sentinel = object()
 
 class AbstractWidgetTest:
-    _conv_pixels = pixels_round
+    _conv_pixels = staticmethod(pixels_round)
     _conv_pad_pixels = None
     wantobjects = True