diff options
author | Ned Deily <nad@acm.org> | 2011-07-04 04:52:35 (GMT) |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2011-07-04 04:52:35 (GMT) |
commit | 46268c49f66903aca8f7546e398249df9141758b (patch) | |
tree | 0e3e4b4eeb3d6825b6004f37249a255fbe484198 | |
parent | 9a7a4cc3a7e0e6dc259e5bc18ca0e1d88f418be6 (diff) | |
download | cpython-46268c49f66903aca8f7546e398249df9141758b.zip cpython-46268c49f66903aca8f7546e398249df9141758b.tar.gz cpython-46268c49f66903aca8f7546e398249df9141758b.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).
-rw-r--r-- | Lib/lib-tk/test/runtktests.py | 32 | ||||
-rw-r--r-- | Lib/test/test_tk.py | 12 | ||||
-rw-r--r-- | Lib/test/test_ttk_guionly.py | 17 | ||||
-rw-r--r-- | Misc/NEWS | 4 |
4 files changed, 49 insertions, 16 deletions
diff --git a/Lib/lib-tk/test/runtktests.py b/Lib/lib-tk/test/runtktests.py index 402c342..041814d 100644 --- a/Lib/lib-tk/test/runtktests.py +++ b/Lib/lib-tk/test/runtktests.py @@ -10,10 +10,42 @@ import os import sys import unittest import importlib +import subprocess import test.test_support this_dir_path = os.path.abspath(os.path.dirname(__file__)) +_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 = test.test_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 is_package(path): for name in os.listdir(path): if name in ('__init__.py', '__init__.pyc', '__init.pyo'): diff --git a/Lib/test/test_tk.py b/Lib/test/test_tk.py index 49ca53f..8625db2 100644 --- a/Lib/test/test_tk.py +++ b/Lib/test/test_tk.py @@ -1,18 +1,9 @@ import os -import unittest from test import test_support # Skip test if _tkinter wasn't built. test_support.import_module('_tkinter') -import Tkinter - -try: - Tkinter.Button() -except Tkinter.TclError, msg: - # assuming tk is not available - raise unittest.SkipTest("tk not available: %s" % msg) - this_dir = os.path.dirname(os.path.abspath(__file__)) lib_tk_test = os.path.abspath(os.path.join(this_dir, os.path.pardir, 'lib-tk', 'test')) @@ -20,6 +11,9 @@ lib_tk_test = os.path.abspath(os.path.join(this_dir, os.path.pardir, with test_support.DirsOnSysPath(lib_tk_test): import runtktests +# Skip test if tk cannot be initialized. +runtktests.check_tk_availability() + def test_main(enable_gui=False): if enable_gui: if test_support.use_resources is None: diff --git a/Lib/test/test_ttk_guionly.py b/Lib/test/test_ttk_guionly.py index 60a57f0..e0368be 100644 --- a/Lib/test/test_ttk_guionly.py +++ b/Lib/test/test_ttk_guionly.py @@ -5,6 +5,16 @@ from test import test_support # Skip this test if _tkinter wasn't built. test_support.import_module('_tkinter') +this_dir = os.path.dirname(os.path.abspath(__file__)) +lib_tk_test = os.path.abspath(os.path.join(this_dir, os.path.pardir, + 'lib-tk', 'test')) + +with test_support.DirsOnSysPath(lib_tk_test): + import runtktests + +# Skip test if tk cannot be initialized. +runtktests.check_tk_availability() + import ttk from _tkinter import TclError @@ -14,13 +24,6 @@ except TclError, msg: # assuming ttk is not available raise unittest.SkipTest("ttk not available: %s" % msg) -this_dir = os.path.dirname(os.path.abspath(__file__)) -lib_tk_test = os.path.abspath(os.path.join(this_dir, os.path.pardir, - 'lib-tk', 'test')) - -with test_support.DirsOnSysPath(lib_tk_test): - import runtktests - def test_main(enable_gui=False): if enable_gui: if test_support.use_resources is None: @@ -83,6 +83,10 @@ Build 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). + - Issue #12141: Install a copy of template C module file so that test_build_ext of test_distutils is no longer silently skipped when run outside of a build directory. |