[Python-checkins] cpython (3.2): Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
ned.deily
python-checkins at python.org
Mon Jul 4 07:31:30 CEST 2011
http://hg.python.org/cpython/rev/279488f5a171
changeset: 71185:279488f5a171
branch: 3.2
parent: 71181:97707459bb5a
user: Ned Deily <nad at acm.org>
date: Sun Jul 03 21:56:48 2011 -0700
summary:
Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
test_tk or test_ttk_guionly under a username that is not currently logged
in to the console windowserver (as may be the case under buildbot or ssh).
files:
Lib/test/test_tk.py | 12 ++-----
Lib/test/test_ttk_guionly.py | 4 ++
Lib/tkinter/test/support.py | 36 ++++++++++++++++++++++++
Misc/NEWS | 8 +++++
4 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/Lib/test/test_tk.py b/Lib/test/test_tk.py
--- a/Lib/test/test_tk.py
+++ b/Lib/test/test_tk.py
@@ -2,15 +2,11 @@
# Skip test if _tkinter wasn't built.
support.import_module('_tkinter')
-import tkinter
+# Skip test if tk cannot be initialized.
+from tkinter.test.support import check_tk_availability
+check_tk_availability()
+
from tkinter.test import runtktests
-import unittest
-
-try:
- tkinter.Button()
-except tkinter.TclError as msg:
- # assuming tk is not available
- raise unittest.SkipTest("tk not available: %s" % msg)
def test_main(enable_gui=False):
if enable_gui:
diff --git a/Lib/test/test_ttk_guionly.py b/Lib/test/test_ttk_guionly.py
--- a/Lib/test/test_ttk_guionly.py
+++ b/Lib/test/test_ttk_guionly.py
@@ -5,6 +5,10 @@
# Skip this test if _tkinter wasn't built.
support.import_module('_tkinter')
+# Skip test if tk cannot be initialized.
+from tkinter.test.support import check_tk_availability
+check_tk_availability()
+
from _tkinter import TclError
from tkinter import ttk
from tkinter.test import runtktests
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
@@ -1,6 +1,42 @@
+import subprocess
+import sys
+from test import support
import tkinter
+import unittest
+
+_tk_available = None
+
+def check_tk_availability():
+ """Check that Tk is installed and available."""
+ global _tk_available
+
+ if _tk_available is not None:
+ return
+
+ if sys.platform == 'darwin':
+ # The Aqua Tk implementations on OS X can abort the process if
+ # being called in an environment where a window server connection
+ # cannot be made, for instance when invoked by a buildbot or ssh
+ # process not running under the same user id as the current console
+ # user. Instead, try to initialize Tk under a subprocess.
+ p = subprocess.Popen(
+ [sys.executable, '-c', 'import tkinter; tkinter.Button()'],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stderr = support.strip_python_stderr(p.communicate()[1])
+ if stderr or p.returncode:
+ raise unittest.SkipTest("tk cannot be initialized: %s" % stderr)
+ else:
+ try:
+ tkinter.Button()
+ except tkinter.TclError as msg:
+ # assuming tk is not available
+ raise unittest.SkipTest("tk not available: %s" % msg)
+
+ _tk_available = True
+ return
def get_tk_root():
+ check_tk_availability() # raise exception if tk unavailable
try:
root = tkinter._default_root
except AttributeError:
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,6 +35,14 @@
C-API
-----
+Tests
+-----
+
+- Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
+ test_tk or test_ttk_guionly under a username that is not currently logged
+ in to the console windowserver (as may be the case under buildbot or ssh).
+
+
What's New in Python 3.2.1 release candidate 2?
===============================================
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list