Files
cthulhu/tests/native_webscripts.py

44 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Verify notification metadata on a private X server and accessibility bus."""
import os
from pathlib import Path
import subprocess
import sys
def main() -> None:
if sys.argv[1:] == ["--inside"]:
environment = dict(os.environ, CTHULHU_NATIVE_WEBSCRIPTS="1")
environment.setdefault("GOCACHE", "/tmp/cthulhu-cache")
subprocess.run(
["go", "test", "./internal/atspi", "-run", "^TestNativeWebScriptNotificationCapture$",
"-count=1", "-v", "-timeout=30s"],
cwd=Path(__file__).resolve().parents[1], env=environment, check=True, timeout=35,
)
return
readFd, writeFd = os.pipe()
server = subprocess.Popen(
["Xvfb", "-displayfd", str(writeFd), "-screen", "0", "800x600x24", "-nolisten", "tcp"],
pass_fds=(writeFd,), stderr=subprocess.DEVNULL,
)
os.close(writeFd)
try:
with os.fdopen(readFd) as reader:
display = reader.readline().strip()
if not display:
raise RuntimeError("Xvfb failed to start")
environment = dict(os.environ, DISPLAY=":" + display, XDG_SESSION_TYPE="x11")
for key in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
environment.pop(key, None)
subprocess.run(
["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
env=environment, check=True, timeout=45,
)
finally:
server.terminate()
server.wait(timeout=3)
if __name__ == "__main__":
main()