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 17, 2024
1 parent 1bf660f commit 796f9f4
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,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 @@ -444,6 +445,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 @@ -478,6 +480,43 @@ 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 @@ -493,6 +532,10 @@ def tearDown(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]:
self._terminate_mock_p (server.process)
for server in self.busses[dbusmock.BusType.SESSION]:
Expand Down

0 comments on commit 796f9f4

Please sign in to comment.