:right-sidebar: True TestDBus =================================================================== .. currentmodule:: gi.repository.Gio .. versionadded:: 2.34 .. class:: TestDBus(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` :Constructors: :: TestDBus(**properties) new(flags:Gio.TestDBusFlags) -> Gio.TestDBus Constructors ------------ .. rst-class:: interim-class .. class:: TestDBus :no-index: .. classmethod:: new(flags: ~gi.repository.Gio.TestDBusFlags) -> ~gi.repository.Gio.TestDBus Create a new :obj:`~gi.repository.Gio.TestDBus` object. :param flags: a :obj:`~gi.repository.Gio.TestDBusFlags` Methods ------- .. rst-class:: interim-class .. class:: TestDBus :no-index: .. method:: add_service_dir(path: str) -> None Add a path where dbus-daemon will look up .service files. This can't be called after :func:`~gi.repository.Gio.TestDBus.up`. :param path: path to a directory containing .service files .. method:: down() -> None Stop the session bus started by :func:`~gi.repository.Gio.TestDBus.up`. This will wait for the singleton returned by :func:`~gi.repository.Gio.bus_get` or :func:`~gi.repository.Gio.bus_get_sync` to be destroyed. This is done to ensure that the next unit test won't get a leaked singleton from this test. .. method:: get_bus_address() -> str | None Get the address on which dbus-daemon is running. If :func:`~gi.repository.Gio.TestDBus.up` has not been called yet, :const:`None` is returned. This can be used with :func:`~gi.repository.Gio.DBusConnection.new_for_address`. .. method:: get_flags() -> ~gi.repository.Gio.TestDBusFlags Get the flags of the :obj:`~gi.repository.Gio.TestDBus` object. .. method:: stop() -> None Stop the session bus started by :func:`~gi.repository.Gio.TestDBus.up`. Unlike :func:`~gi.repository.Gio.TestDBus.down`, this won't verify the :obj:`~gi.repository.Gio.DBusConnection` singleton returned by :func:`~gi.repository.Gio.bus_get` or :func:`~gi.repository.Gio.bus_get_sync` is destroyed. Unit tests wanting to verify behaviour after the session bus has been stopped can use this function but should still call :func:`~gi.repository.Gio.TestDBus.down` when done. .. method:: unset() -> None Unset DISPLAY and DBUS_SESSION_BUS_ADDRESS env variables to ensure the test won't use user's session bus. This is useful for unit tests that want to verify behaviour when no session bus is running. It is not necessary to call this if unit test already calls :func:`~gi.repository.Gio.TestDBus.up` before acquiring the session bus. .. method:: up() -> None Start a dbus-daemon instance and set DBUS_SESSION_BUS_ADDRESS. After this call, it is safe for unit tests to start sending messages on the session bus. If this function is called from setup callback of :func:`~gi.repository.GLib.test_add`, :func:`~gi.repository.Gio.TestDBus.down` must be called in its teardown callback. If this function is called from unit test's main(), then :func:`~gi.repository.Gio.TestDBus.down` must be called after :func:`~gi.repository.GLib.test_run`. Properties ---------- .. rst-class:: interim-class .. class:: TestDBus :no-index: .. attribute:: props.flags :type: ~gi.repository.Gio.TestDBusFlags :obj:`~gi.repository.Gio.TestDBusFlags` specifying the behaviour of the D-Bus session. .. versionadded:: 2.34