#!/usr/bin/env python3 """Private X11/AT-SPI proof for foreground and background progress output.""" import os from pathlib import Path import subprocess import sys from native_test_session import run_private_session def main(): if len(sys.argv) == 2 and sys.argv[1] == "--inside": environment = dict(os.environ, CTHULHU_NATIVE_PROGRESS="1") environment.setdefault("GOCACHE", "/tmp/cthulhu-cache") subprocess.run(["go", "test", "./internal/app", "-run", "^TestNativeProgressBars$", "-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", "1024x768x24", "-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") environment = dict(os.environ, DISPLAY=":" + display, XDG_SESSION_TYPE="x11", GDK_BACKEND="x11", GTK_MODULES="gail:atk-bridge", GIO_USE_VFS="local") for name in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"): environment.pop(name, None) run_private_session(["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()