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 17, 2024
1 parent 07cf7b2 commit 1bf660f
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,27 @@ def start_xdp(self):
Start the xdg-desktop-portal process
"""

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"
)

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 @@ -448,20 +465,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("org.freedesktop.portal.Desktop"):
Expand All @@ -478,8 +482,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 tearDown(self):
if self.dbus_monitor:
Expand Down

0 comments on commit 1bf660f

Please sign in to comment.