]> 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:23 +0000 (23:05 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 4 Nov 2013 21:05:23 +0000 (23:05 +0200)
Lib/lib-tk/test/test_tkinter/test_widgets.py
Lib/lib-tk/test/widget_tests.py

index 3042599a09d49185342272898cc9e34769783984..f0a4eeb77a81d341b52425c46208629b147c9fb8 100644 (file)
@@ -4,7 +4,8 @@ import os
 from test.test_support import requires, run_unittest
 
 from test_ttk.support import tcl_version, requires_tcl, widget_eq
-from widget_tests import (add_standard_options, noconv, noconv_meth, int_round,
+from widget_tests import (
+    add_standard_options, noconv, noconv_meth, int_round, pixels_round,
     AbstractWidgetTest, StandardOptionsTests,
     IntegerSizeTests, PixelSizeTests)
 
@@ -240,7 +241,7 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
         'takefocus', 'text', 'textvariable',
         'underline', 'width', 'wraplength',
     )
-    _conv_pixels = staticmethod(AbstractWidgetTest._conv_pixels)
+    _conv_pixels = staticmethod(pixels_round)
 
     def _create(self, **kwargs):
         return Tkinter.Menubutton(self.root, **kwargs)
index c60673cc2d13c4d0192dc75b29845d770bc63d64..f17ea5f0ab797893621885b1cc9ae3dc423ec00f 100644 (file)
@@ -15,12 +15,18 @@ pixels_round = int_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()