本文整理汇总了Python中gstswitch.connection.Connection.signal_subscribe方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.signal_subscribe方法的具体用法?Python Connection.signal_subscribe怎么用?Python Connection.signal_subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gstswitch.connection.Connection
的用法示例。
在下文中一共展示了Connection.signal_subscribe方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handler_passed_to_gio
# 需要导入模块: from gstswitch.connection import Connection [as 别名]
# 或者: from gstswitch.connection.Connection import signal_subscribe [as 别名]
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
示例2: test_handler_not_callable
# 需要导入模块: from gstswitch.connection import Connection [as 别名]
# 或者: from gstswitch.connection.Connection import signal_subscribe [as 别名]
def test_handler_not_callable(self, monkeypatch):
"""Test if handler is not callable"""
conn = Connection()
test_cbs = ['', None, [], {}]
for test_cb in test_cbs:
with pytest.raises(ValueError):
conn.signal_subscribe(test_cb)
示例3: test_gio_error_is_converted
# 需要导入模块: from gstswitch.connection import Connection [as 别名]
# 或者: from gstswitch.connection.Connection import signal_subscribe [as 别名]
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)
示例4: test_gio_error_is_converted
# 需要导入模块: from gstswitch.connection import Connection [as 别名]
# 或者: from gstswitch.connection.Connection import signal_subscribe [as 别名]
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)