summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorNed Deily <nad@acm.org>2011-07-04 05:27:16 (GMT)
committerNed Deily <nad@acm.org>2011-07-04 05:27:16 (GMT)
commitefa384aa2786e68bcd51c2b2fc52483bf59b5fed (patch)
tree88b9d6be60dbf3bf086e210f8017a24489ce6475 /Lib/tkinter
parentbc9d8f838b604565da23fba8ae97e0cd23aa7414 (diff)
parent4143535d865b103ebe6cbce51287a63f9538afd3 (diff)
downloadcpython-efa384aa2786e68bcd51c2b2fc52483bf59b5fed.zip
cpython-efa384aa2786e68bcd51c2b2fc52483bf59b5fed.tar.gz
cpython-efa384aa2786e68bcd51c2b2fc52483bf59b5fed.tar.bz2
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).
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/test/support.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/tkinter/test/support.py b/Lib/tkinter/test/support.py
index 97212fb..20bd412 100644
--- 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: