cpython: b58b0c5c7e96 (original) (raw)
Mercurial > cpython
changeset 71242:b58b0c5c7e96 3.2
Issue #8716: Instead of relying on Aqua Tk exceptions to detect lack of OS X window manager connection in tk tests, use OS X Application Services API calls instead. [#8716]
Ned Deily nad@acm.org | |
---|---|
date | Tue, 05 Jul 2011 19:09:37 -0700 |
parents | 807921ba241d |
children | 2f7e353f9e83 4e83d8f6d496 |
files | Lib/tkinter/test/support.py |
diffstat | 1 files changed, 35 insertions(+), 25 deletions(-)[+] [-] Lib/tkinter/test/support.py 60 |
line wrap: on
line diff
--- a/Lib/tkinter/test/support.py +++ b/Lib/tkinter/test/support.py @@ -1,38 +1,48 @@ -import subprocess import sys -from test import support import tkinter import unittest -_tk_available = None +_tk_unavailable = None def check_tk_availability(): """Check that Tk is installed and available."""
- if _tk_unavailable is None:
_tk_unavailable = False[](#l1.21)
if sys.platform == 'darwin':[](#l1.22)
# The Aqua Tk implementations on OS X can abort the process if[](#l1.23)
# being called in an environment where a window server connection[](#l1.24)
# cannot be made, for instance when invoked by a buildbot or ssh[](#l1.25)
# process not running under the same user id as the current console[](#l1.26)
# user. To avoid that, raise an exception if the window manager[](#l1.27)
# connection is not available.[](#l1.28)
from ctypes import cdll, c_int, pointer, Structure[](#l1.29)
from ctypes.util import find_library[](#l1.30)
app_services = cdll.LoadLibrary(find_library("ApplicationServices"))[](#l1.32)
- if sys.platform == 'darwin':
# The Aqua Tk implementations on OS X can abort the process if[](#l1.35)
# being called in an environment where a window server connection[](#l1.36)
# cannot be made, for instance when invoked by a buildbot or ssh[](#l1.37)
# process not running under the same user id as the current console[](#l1.38)
# user. Instead, try to initialize Tk under a subprocess.[](#l1.39)
p = subprocess.Popen([](#l1.40)
[sys.executable, '-c', 'import tkinter; tkinter.Button()'],[](#l1.41)
stdout=subprocess.PIPE, stderr=subprocess.PIPE)[](#l1.42)
stderr = support.strip_python_stderr(p.communicate()[1])[](#l1.43)
if stderr or p.returncode:[](#l1.44)
raise unittest.SkipTest("tk cannot be initialized: %s" % stderr)[](#l1.45)
- else:
try:[](#l1.47)
tkinter.Button()[](#l1.48)
except tkinter.TclError as msg:[](#l1.49)
# assuming tk is not available[](#l1.50)
raise unittest.SkipTest("tk not available: %s" % msg)[](#l1.51)
if app_services.CGMainDisplayID() == 0:[](#l1.52)
_tk_unavailable = "cannot run without OS X window manager"[](#l1.53)
else:[](#l1.54)
class ProcessSerialNumber(Structure):[](#l1.55)
_fields_ = [("highLongOfPSN", c_int),[](#l1.56)
("lowLongOfPSN", c_int)][](#l1.57)
psn = ProcessSerialNumber()[](#l1.58)
psn_p = pointer(psn)[](#l1.59)
if ( (app_services.GetCurrentProcess(psn_p) < 0) or[](#l1.60)
(app_services.SetFrontProcess(psn_p) < 0) ):[](#l1.61)
_tk_unavailable = "cannot run without OS X gui process"[](#l1.62)
else: # not OS X[](#l1.63)
import tkinter[](#l1.64)
try:[](#l1.65)
tkinter.Button()[](#l1.66)
except tkinter.TclError as msg:[](#l1.67)
# assuming tk is not available[](#l1.68)
_tk_unavailable = "tk not available: %s" % msg[](#l1.69)