當前位置: 首頁>>代碼示例>>Python>>正文


Python TagDispatcher.add_callback方法代碼示例

本文整理匯總了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)
開發者ID:horazont,項目名稱:aioxmpp,代碼行數:10,代碼來源:test_callbacks.py

示例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()
開發者ID:horazont,項目名稱:aioxmpp,代碼行數:10,代碼來源:test_callbacks.py

示例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)
開發者ID:horazont,項目名稱:aioxmpp,代碼行數:14,代碼來源:test_callbacks.py

示例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
        )
開發者ID:horazont,項目名稱:aioxmpp,代碼行數:19,代碼來源:test_callbacks.py


注:本文中的aioxmpp.callbacks.TagDispatcher.add_callback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。