flatpak / libportal

libportal - Flatpak portal library
https://libportal.org
GNU Lesser General Public License v3.0
82 stars 40 forks source link

test: add a pytest/dbusmock-based test suite #99

Closed whot closed 2 years ago

whot commented 2 years ago

Using python and dbusmock makes it trivial to add a large number of tests for libportal only, without requiring an actual portal implementation for the Portal interface to be tested.

Included here is the wallpaper portal as an example, hooked into meson test. A helper script is provided too for those lacking meson devenv,

  $ ./test/gir-testenv.sh
  $ cd test
  $ pytest --verbose --log-level=DEBUG [... other pytest arguments ...]

The test setup uses dbusmock interface templates (see pyportaltest/templates) to handle the actual DBus calls.

Because DBus uses a singleton for the session bus, we need libportal to specifically connect to the address given in the environment - otherwise starting mock dbus services has no effect.

This test suite depends on dbusmock commit 4a191d8ba293: "mockobject: allow sending signals with extra details"

Without this, the EmitSignalDetailed() method does not exist/work, but without this method we cannot receive signals.

whot commented 2 years ago

Just ftr, I squashed in the changes requested above together with a bit of cleanup in the tests to bring them slightly closer to how https://github.com/flatpak/xdg-desktop-portal/pull/764 looks atm. Frustratingly, all these test suites are very close but not the same so they can't be fully re-used (the Xdp one provides the impl, this one here provides the portal.

GeorgesStavracas commented 2 years ago

Thanks, it looks great