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
Ejemplo n.º 2
0
    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 = lambda: None
        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_mock2(self, monkeypatch):
     """Test GLib.GError exception"""
     monkeypatch.setattr(Gio.DBusConnection, 'new_for_address_sync',
                         Mock(return_value=1))
     conn = Connection()
     conn.connect_dbus()
     assert conn.connection is not None
 def test_mock1(self, monkeypatch):
     """Test GLib.GError exception"""
     monkeypatch.setattr(Gio.DBusConnection, 'new_for_address_sync',
                         Mock(side_effect=GLib.GError))
     conn = Connection()
     with pytest.raises(ConnectionError):
         conn.connect_dbus()
Ejemplo n.º 5
0
 def test_mock2(self, monkeypatch):
     """Test GLib.GError exception"""
     monkeypatch.setattr(
         Gio.DBusConnection, 'new_for_address_sync',
         Mock(return_value=1))
     conn = Connection()
     conn.connect_dbus()
     assert conn.connection is not None
Ejemplo n.º 6
0
 def test_mock1(self, monkeypatch):
     """Test GLib.GError exception"""
     monkeypatch.setattr(
         Gio.DBusConnection,
         'new_for_address_sync',
         Mock(side_effect=GLib.GError))
     conn = Connection()
     with pytest.raises(ConnectionError):
         conn.connect_dbus()
Ejemplo n.º 7
0
    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)
    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)
Ejemplo n.º 9
0
    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()

        def test_cb():
            """ Dummy callback. """
            pass
        with pytest.raises(ConnectionError):
            conn.signal_subscribe(test_cb)
Ejemplo n.º 10
0
 def test_bad_address3(self):
     """Test if wrong address is given - 3"""
     address = 'unix:path'
     conn = Connection(address=address)
     with pytest.raises(ConnectionError):
         conn.connect_dbus()
Ejemplo n.º 11
0
 def test_bad_address2(self):
     """Test if wrong address is given - 2"""
     address = 'unix:temp=gstswitch'
     conn = Connection(address=address)
     with pytest.raises(ConnectionError):
         conn.connect_dbus()
Ejemplo n.º 12
0
 def test_bad_address(self):
     """Test if wrong address is given - 1"""
     address = "unix:path=gstswitch"
     conn = Connection(address=address)
     with pytest.raises(ConnectionError):
         conn.connect_dbus()
Ejemplo n.º 13
0
 def test_bad_address(self):
     """Test if wrong address is given - 1"""
     address = 'unix:path=gstswitch'
     conn = Connection(address=address)
     with pytest.raises(ConnectionError):
         conn.connect_dbus()