mirror of https://github.com/python/cpython
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).
This commit is contained in:
commit
efa384aa27
|
@ -2,15 +2,11 @@ from test import support
|
||||||
# Skip test if _tkinter wasn't built.
|
# Skip test if _tkinter wasn't built.
|
||||||
support.import_module('_tkinter')
|
support.import_module('_tkinter')
|
||||||
|
|
||||||
import tkinter
|
# Skip test if tk cannot be initialized.
|
||||||
from tkinter.test import runtktests
|
from tkinter.test.support import check_tk_availability
|
||||||
import unittest
|
check_tk_availability()
|
||||||
|
|
||||||
try:
|
from tkinter.test import runtktests
|
||||||
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):
|
def test_main(enable_gui=False):
|
||||||
if enable_gui:
|
if enable_gui:
|
||||||
|
|
|
@ -5,6 +5,10 @@ from test import support
|
||||||
# Skip this test if _tkinter wasn't built.
|
# Skip this test if _tkinter wasn't built.
|
||||||
support.import_module('_tkinter')
|
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 TclError
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from tkinter.test import runtktests
|
from tkinter.test import runtktests
|
||||||
|
|
|
@ -1,6 +1,42 @@
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from test import support
|
||||||
import tkinter
|
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():
|
def get_tk_root():
|
||||||
|
check_tk_availability() # raise exception if tk unavailable
|
||||||
try:
|
try:
|
||||||
root = tkinter._default_root
|
root = tkinter._default_root
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
|
@ -973,6 +973,10 @@ Extension Modules
|
||||||
Tests
|
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 #12407: Explicitly skip test_capi.EmbeddingTest under Windows.
|
- Issue #12407: Explicitly skip test_capi.EmbeddingTest under Windows.
|
||||||
|
|
||||||
- Issue #12400: regrtest -W doesn't rerun the tests twice anymore, but captures
|
- Issue #12400: regrtest -W doesn't rerun the tests twice anymore, but captures
|
||||||
|
|
Loading…
Reference in New Issue