8000 gh-61698: Use launchctl to detect macOS window manager in tests (#118… · python/cpython@ce740d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce740d4

Browse files
gh-61698: Use launchctl to detect macOS window manager in tests (#118390)
1 parent 4197a79 commit ce740d4

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Lib/test/support/__init__.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,16 @@ class USEROBJECTFLAGS(ctypes.Structure):
253253
# process not running under the same user id as the current console
254254
# user. To avoid that, raise an exception if the window manager
255255
# connection is not available.
256-
from ctypes import cdll, c_int, pointer, Structure
257-
from ctypes.util import find_library
258-
259-
app_services = cdll.LoadLibrary(find_library("ApplicationServices"))
260-
261-
if app_services.CGMainDisplayID() == 0:
262-
reason = "gui tests cannot run without OS X window manager"
256+
import subprocess
257+
try:
258+
rc = subprocess.run(["launchctl", "managername"],
259+
capture_output=True, check=True)
260+
managername = rc.stdout.decode("utf-8").strip()
261+
except subprocess.CalledProcessError:
262+
reason = "unable to detect macOS launchd job manager"
263263
else:
264-
class ProcessSerialNumber(Structure):
265-
_fields_ = [("highLongOfPSN", c_int),
266-
("lowLongOfPSN", c_int)]
267-
psn = ProcessSerialNumber()
268-
psn_p = pointer(psn)
269-
if ( (app_services.GetCurrentProcess(psn_p) < 0) or
270-
(app_services.SetFrontProcess(psn_p) < 0) ):
271-
reason = "cannot run without OS X gui process"
264+
if managername != "Aqua":
265+
reason = f"{managername=} -- can only run in a macOS GUI session"
272266

273267
# check on every platform whether tkinter can actually do anything
274268
if not reason:

0 commit comments

Comments
 (0)
0