本文整理汇总了Python中aioxmpp.callbacks.TagDispatcher.add_callback方法的典型用法代码示例。如果您正苦于以下问题:Python TagDispatcher.add_callback方法的具体用法?Python TagDispatcher.add_callback怎么用?Python TagDispatcher.add_callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aioxmpp.callbacks.TagDispatcher
的用法示例。
在下文中一共展示了TagDispatcher.add_callback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_callback
# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import add_callback [as 别名]
def test_add_callback(self):
mock = unittest.mock.Mock()
nh = TagDispatcher()
nh.add_callback("tag", mock)
with self.assertRaisesRegex(ValueError,
"only one listener is allowed"):
nh.add_callback("tag", mock)
示例2: test_remove_listener
# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import add_callback [as 别名]
def test_remove_listener(self):
mock = unittest.mock.Mock()
nh = TagDispatcher()
nh.add_callback("tag", mock)
nh.remove_listener("tag")
with self.assertRaises(KeyError):
nh.unicast("tag", object())
mock.assert_not_called()
示例3: test_unicast_removes_for_true_result
# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import add_callback [as 别名]
def test_unicast_removes_for_true_result(self):
mock = unittest.mock.Mock()
mock.return_value = True
obj = object()
nh = TagDispatcher()
nh.add_callback("tag", mock)
nh.unicast("tag", obj)
with self.assertRaises(KeyError):
nh.unicast("tag", obj)
mock.assert_called_once_with(obj)
示例4: test_unicast
# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import add_callback [as 别名]
def test_unicast(self):
mock = unittest.mock.Mock()
mock.return_value = False
obj = object()
nh = TagDispatcher()
nh.add_callback("tag", mock)
nh.unicast("tag", obj)
nh.unicast("tag", obj)
self.assertSequenceEqual(
[
unittest.mock.call(obj),
unittest.mock.call(obj),
],
mock.mock_calls
)