当前位置: 首页>>代码示例>>Python>>正文


Python TagDispatcher.unicast方法代码示例

本文整理汇总了Python中aioxmpp.callbacks.TagDispatcher.unicast方法的典型用法代码示例。如果您正苦于以下问题:Python TagDispatcher.unicast方法的具体用法?Python TagDispatcher.unicast怎么用?Python TagDispatcher.unicast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aioxmpp.callbacks.TagDispatcher的用法示例。


在下文中一共展示了TagDispatcher.unicast方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_close

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [as 别名]
    def test_close(self):
        data = unittest.mock.Mock()
        error1 = unittest.mock.Mock()
        error2 = unittest.mock.Mock()

        l1 = TagListener(data, error1)
        l2 = TagListener(data, error2)

        obj = object()

        nh = TagDispatcher()
        nh.add_listener("tag1", l1)
        nh.add_listener("tag2", l2)

        nh.close_all(obj)

        data.assert_not_called()
        error1.assert_called_once_with(obj)
        error2.assert_called_once_with(obj)

        with self.assertRaises(KeyError):
            nh.remove_listener("tag1")
        with self.assertRaises(KeyError):
            nh.remove_listener("tag2")
        with self.assertRaises(KeyError):
            nh.unicast("tag1", None)
        with self.assertRaises(KeyError):
            nh.unicast("tag2", None)
开发者ID:horazont,项目名称:aioxmpp,代码行数:30,代码来源:test_callbacks.py

示例2: test_add_listener_skips_invalid

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [as 别名]
    def test_add_listener_skips_invalid(self):
        mock = unittest.mock.Mock()

        l1 = unittest.mock.Mock()
        l1.is_valid.return_value = True

        l2 = TagListener(mock)

        nh = TagDispatcher()
        nh.add_listener("tag", l1)
        l1.is_valid.return_value = False
        nh.add_listener("tag", l2)

        obj = object()
        nh.unicast("tag", obj)
        self.assertSequenceEqual(
            [
                unittest.mock.call.is_valid(),
            ],
            l1.mock_calls
        )

        self.assertSequenceEqual(
            [
                unittest.mock.call(obj),
            ],
            mock.mock_calls
        )
开发者ID:horazont,项目名称:aioxmpp,代码行数:30,代码来源:test_callbacks.py

示例3: test_add_callback_async

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [as 别名]
    def test_add_callback_async(self, AsyncTagListener):
        AsyncTagListener().is_valid.return_value = True
        AsyncTagListener.mock_calls.clear()

        data = unittest.mock.Mock()
        loop = unittest.mock.Mock()
        obj = object()

        nh = TagDispatcher()
        nh.add_callback_async("tag", data, loop=loop)

        self.assertSequenceEqual(
            [
                unittest.mock.call(data, loop=loop)
            ],
            AsyncTagListener.mock_calls
        )
        del AsyncTagListener.mock_calls[:]

        nh.unicast("tag", obj)

        self.assertSequenceEqual(
            [
                unittest.mock.call().is_valid(),
                unittest.mock.call().data(obj),
                unittest.mock.call().data().__bool__(),
            ],
            AsyncTagListener.mock_calls
        )
开发者ID:horazont,项目名称:aioxmpp,代码行数:31,代码来源:test_callbacks.py

示例4: test_remove_listener

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [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

示例5: test_unicast_fails_for_invalid

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [as 别名]
 def test_unicast_fails_for_invalid(self):
     obj = object()
     l = unittest.mock.Mock()
     l.is_valid.return_value = False
     nh = TagDispatcher()
     nh.add_listener("tag", l)
     with self.assertRaises(KeyError):
         nh.unicast("tag", obj)
开发者ID:horazont,项目名称:aioxmpp,代码行数:10,代码来源:test_callbacks.py

示例6: test_unicast_removes_for_true_result

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [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

示例7: test_unicast

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [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

示例8: test_unicast_to_cancelled_oneshot

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [as 别名]
    def test_unicast_to_cancelled_oneshot(self):
        mock = unittest.mock.Mock()
        obj = object()

        l = OneshotTagListener(mock)

        nh = TagDispatcher()
        nh.add_listener("tag", l)

        l.cancel()

        with self.assertRaises(KeyError):
            nh.unicast("tag", obj)

        self.assertSequenceEqual(
            [],
            mock.mock_calls
        )
开发者ID:horazont,项目名称:aioxmpp,代码行数:20,代码来源:test_callbacks.py

示例9: test_broadcast_error_to_cancelled_oneshot

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [as 别名]
    def test_broadcast_error_to_cancelled_oneshot(self):
        data = unittest.mock.Mock()
        error = unittest.mock.Mock()
        obj = object()

        l = OneshotTagListener(data, error)

        nh = TagDispatcher()
        nh.add_listener("tag", l)

        l.cancel()

        nh.broadcast_error(obj)
        with self.assertRaises(KeyError):
            nh.unicast("tag", obj)

        self.assertSequenceEqual(
            [],
            error.mock_calls
        )
        self.assertFalse(data.mock_calls)
开发者ID:horazont,项目名称:aioxmpp,代码行数:23,代码来源:test_callbacks.py

示例10: test_add_future

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [as 别名]
    def test_add_future(self):
        mock = unittest.mock.Mock()
        mock.done.return_value = False
        obj = object()

        nh = TagDispatcher()
        nh.add_future("tag", mock)
        nh.unicast("tag", obj)
        with self.assertRaises(KeyError):
            # futures must be oneshots
            nh.unicast("tag", obj)

        nh.add_future("tag", mock)
        nh.broadcast_error(obj)
        with self.assertRaises(KeyError):
            # futures must be oneshots
            nh.unicast("tag", obj)

        self.assertSequenceEqual(
            [
                unittest.mock.call.done(),
                unittest.mock.call.set_result(obj),
                unittest.mock.call.done(),
                unittest.mock.call.set_exception(obj),
            ],
            mock.mock_calls
        )
开发者ID:horazont,项目名称:aioxmpp,代码行数:29,代码来源:test_callbacks.py

示例11: test_unicast_fails_for_nonexistent

# 需要导入模块: from aioxmpp.callbacks import TagDispatcher [as 别名]
# 或者: from aioxmpp.callbacks.TagDispatcher import unicast [as 别名]
 def test_unicast_fails_for_nonexistent(self):
     obj = object()
     nh = TagDispatcher()
     with self.assertRaises(KeyError):
         nh.unicast("tag", obj)
开发者ID:horazont,项目名称:aioxmpp,代码行数:7,代码来源:test_callbacks.py


注:本文中的aioxmpp.callbacks.TagDispatcher.unicast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。