Skip to content

Commit

Permalink
tests/py: Start the permission store
Browse files Browse the repository at this point in the history
We now isolate the test environment so that the permission store will
start with an empty state but.
  • Loading branch information
swick committed Oct 28, 2024
1 parent 02c500c commit 2a74332
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def __init__(
self.dbus_test_case = dbus_test_case
self.portal_name = portal_name
self.portal_frontend = None
self.permission_store = None
self.dbus_monitor = None
self.portal_interfaces: Dict[str, dbus.Interface] = {}
self.app_id = app_id
Expand Down Expand Up @@ -438,6 +439,7 @@ def start_xdp(self):

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

def start_portal_frontend(self, env):
# This roughly resembles test-portals.c and glib's test behavior
Expand Down Expand Up @@ -474,6 +476,45 @@ def start_portal_frontend(self, env):

self.portal_frontend = portal_frontend

def start_permission_store(self, env):
"""
Start the xdg-permission-store process
"""

# 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
libexecdir = os.getenv("LIBEXECDIR")
if libexecdir:
permission_store_path = Path(libexecdir) / "xdg-permission-store"
else:
permission_store_path = (
Path(os.getenv("G_TEST_BUILDDIR") or "tests")
/ ".."
/ "document-portal"
/ "xdg-permission-store"
)

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

permission_store = subprocess.Popen([permission_store_path], env=env)

for _ in range(50):
if self.dbus_test_case.dbus_con.name_has_owner(
"org.freedesktop.impl.portal.PermissionStore"
):
break
time.sleep(0.1)
else:
assert (
False
), "Timeout while waiting for xdg-permission-store to claim the bus"

self.permission_store = permission_store

def start_dbus_monitor(self):
if not os.getenv("XDP_DBUS_MONITOR"):
return
Expand All @@ -489,6 +530,10 @@ def tear_down(self):
self.portal_frontend.terminate()
self.portal_frontend.wait()

if self.permission_store:
self.permission_store.terminate()
self.permission_store.wait()

for server in self.busses[dbusmock.BusType.SYSTEM].values():
self._terminate_mock_p(server.process)
for server in self.busses[dbusmock.BusType.SESSION].values():
Expand Down

0 comments on commit 2a74332

Please sign in to comment.