Skip to content

Commit b7dff85

Browse files
[3.13] gh-61698: Use launchctl to detect macOS window manager in tests (GH-118390) (#125392)
(cherry picked from commit ce740d4) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent bcadaf2 commit b7dff85

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

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

0 commit comments

Comments
 (0)