def test_handler_passed_to_gio(self, monkeypatch):
        """Test if handler is correctly passed to Gio"""

        monkeypatch.setattr(Gio.DBusConnection, 'new_for_address_sync',
                            Mock(return_value=Gio.DBusConnection()))

        signal_subscribe_mock = Mock()
        monkeypatch.setattr(Gio.DBusConnection, 'signal_subscribe',
                            signal_subscribe_mock)

        conn = Connection()
        conn.connect_dbus()
        test_cb = Mock()

        conn.signal_subscribe(test_cb)

        # test that Gio's signal_subscribe method is called once
        # and passed the callback as-is
        signal_subscribe_mock.assert_called_once()

        # pylint does not recognize Mock.call_args as sequence and won't
        # allow us to unpack it. Disabling the warning because we know what
        # we're doing here

        # pylint: disable=unpacking-non-sequence
        args, _ = signal_subscribe_mock.call_args
        assert args[6] == test_cb
    def test_gio_error_is_converted(self, monkeypatch):
        """Test if handler is correctly passed to Gio"""

        monkeypatch.setattr(Gio.DBusConnection, 'new_for_address_sync',
                            Mock(return_value=Gio.DBusConnection()))

        monkeypatch.setattr(Gio.DBusConnection, 'signal_subscribe',
                            Mock(side_effect=GLib.GError('Boom!')))

        conn = Connection()
        conn.connect_dbus()
        test_cb = Mock()

        with pytest.raises(ConnectionError):
            conn.signal_subscribe(test_cb)