Skip to content

Commit

Permalink
tests/py: Move portal DUT environment to caller
Browse files Browse the repository at this point in the history
This way it becomes reusable when we want to start more components.
  • Loading branch information
swick committed Oct 28, 2024
1 parent 948d0b3 commit 02c500c
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,23 @@ def start_xdp(self):
Start the xdg-desktop-portal process
"""

portal_dir = Path(os.getenv("G_TEST_BUILDDIR", "tests")) / "portals" / "test"

if not portal_dir.exists():
raise FileNotFoundError(
f"{portal_dir} does not exist, try running from meson build dir or setting G_TEST_SRCDIR"
)

env = os.environ.copy()
env["G_DEBUG"] = "fatal-criticals"
env["XDG_DESKTOP_PORTAL_DIR"] = portal_dir
env["XDG_CURRENT_DESKTOP"] = "test"
env["XDG_DESKTOP_PORTAL_TEST_APP_ID"] = self.app_id

self.start_dbus_monitor()
self.start_portal_frontend()
self.start_portal_frontend(env)

def start_portal_frontend(self):
def start_portal_frontend(self, env):
# This roughly resembles test-portals.c and glib's test behavior
# but preferences in-tree testing by running pytest in meson's
# project_build_root
Expand All @@ -435,7 +448,7 @@ def start_portal_frontend(self):
portal_frontend = Path(libexecdir) / "xdg-desktop-portal"
else:
portal_frontend = (
Path(os.getenv("G_TEST_BUILDDIR") or "tests")
Path(os.getenv("G_TEST_BUILDDIR", "tests"))
/ ".."
/ "src"
/ "xdg-desktop-portal"
Expand All @@ -446,20 +459,7 @@ def start_portal_frontend(self):
f"{portal_frontend} does not exist, try running from meson build dir or setting G_TEST_BUILDDIR"
)

portal_dir = Path(os.getenv("G_TEST_BUILDDIR") or "tests") / "portals" / "test"
if not portal_dir.exists():
raise FileNotFoundError(
f"{portal_dir} does not exist, try running from meson build dir or setting G_TEST_SRCDIR"
)

argv = [portal_frontend]
env = os.environ.copy()
env["G_DEBUG"] = "fatal-criticals"
env["XDG_DESKTOP_PORTAL_DIR"] = portal_dir
env["XDG_CURRENT_DESKTOP"] = "test"
env["XDG_DESKTOP_PORTAL_TEST_APP_ID"] = self.app_id

portal_frontend = subprocess.Popen(argv, env=env)
portal_frontend = subprocess.Popen([portal_frontend], env=env)

for _ in range(50):
if self.dbus_test_case.dbus_con.name_has_owner(
Expand All @@ -478,8 +478,7 @@ def start_dbus_monitor(self):
if not os.getenv("XDP_DBUS_MONITOR"):
return

argv = ["dbus-monitor", "--session"]
self.dbus_monitor = subprocess.Popen(argv)
self.dbus_monitor = subprocess.Popen(["dbus-monitor", "--session"])

def tear_down(self):
if self.dbus_monitor:
Expand Down

0 comments on commit 02c500c

Please sign in to comment.