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


Python AdHocSignal.connect方法代码示例

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


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

示例1: test_connect_does_not_use_weakref

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_does_not_use_weakref(self):
        signal = AdHocSignal()

        with unittest.mock.patch("weakref.ref") as ref:
            fun = unittest.mock.MagicMock()
            signal.connect(fun)
            self.assertFalse(ref.mock_calls)
开发者ID:horazont,项目名称:aioxmpp,代码行数:9,代码来源:test_callbacks.py

示例2: test_connect_spawn_emits_always

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_spawn_emits_always(self):
        signal = AdHocSignal()

        mock = CoroutineMock()

        @asyncio.coroutine
        def coro(*args, **kwargs):
            yield from mock(*args, **kwargs)

        signal.connect(coro, AdHocSignal.SPAWN_WITH_LOOP(None))
        signal.fire("a", 1, b="c")
        signal.fire("x")

        self.assertSequenceEqual(mock.mock_calls, [])

        run_coroutine(asyncio.sleep(0))

        run_coroutine(asyncio.sleep(0))

        self.assertSequenceEqual(
            mock.mock_calls,
            [
                unittest.mock.call("a", 1, b="c"),
                unittest.mock.call("x"),
            ]
        )
开发者ID:horazont,项目名称:aioxmpp,代码行数:28,代码来源:test_callbacks.py

示例3: test_connect_weak_uses_weakref

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_weak_uses_weakref(self):
        signal = AdHocSignal()

        with unittest.mock.patch("weakref.ref") as ref:
            fun = unittest.mock.MagicMock()
            signal.connect(fun, AdHocSignal.WEAK)
            ref.assert_called_once_with(fun)
开发者ID:horazont,项目名称:aioxmpp,代码行数:9,代码来源:test_callbacks.py

示例4: test_remove_callback_on_true_result

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_remove_callback_on_true_result(self):
        signal = AdHocSignal()

        fun = unittest.mock.MagicMock()
        fun.return_value = True

        signal.connect(fun)

        signal()

        self.assertSequenceEqual(
            [
                unittest.mock.call(),
            ],
            fun.mock_calls
        )

        signal()

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

示例5: test_fire_with_arguments

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_fire_with_arguments(self):
        signal = AdHocSignal()

        fun = unittest.mock.MagicMock()

        signal.connect(fun)

        signal("a", 1, foo=None)

        fun.assert_called_once_with("a", 1, foo=None)
开发者ID:horazont,项目名称:aioxmpp,代码行数:12,代码来源:test_callbacks.py

示例6: test_logger_on_connect

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_logger_on_connect(self):
        logger = unittest.mock.Mock()
        signal = AdHocSignal()
        signal.logger = logger

        a = unittest.mock.Mock()
        signal.connect(a)

        logger.debug.assert_called_with(
            "connecting %r with mode %r",
            a, signal.STRONG)
开发者ID:horazont,项目名称:aioxmpp,代码行数:13,代码来源:test_callbacks.py

示例7: test_connect_and_call

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_and_call(self):
        signal = AdHocSignal()

        fun = unittest.mock.MagicMock()
        fun.return_value = None

        signal.connect(fun)

        signal()

        fun.assert_called_once_with()
开发者ID:horazont,项目名称:aioxmpp,代码行数:13,代码来源:test_callbacks.py

示例8: test_fire_removes_stale_references

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_fire_removes_stale_references(self, ref):
        signal = AdHocSignal()

        fun = unittest.mock.MagicMock()
        fun.return_value = None
        ref().return_value = None

        signal.connect(fun, AdHocSignal.WEAK)

        signal.fire()

        self.assertFalse(signal._connections)
开发者ID:horazont,项目名称:aioxmpp,代码行数:14,代码来源:test_callbacks.py

示例9: test_connect_weak_uses_WeakMethod_for_methods

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_weak_uses_WeakMethod_for_methods(self):
        signal = AdHocSignal()

        class Foo:
            def meth(self):
                return None

        f = Foo()

        with unittest.mock.patch("weakref.WeakMethod") as ref:
            signal.connect(f.meth, AdHocSignal.WEAK)

        ref.assert_called_once_with(f.meth)
开发者ID:horazont,项目名称:aioxmpp,代码行数:15,代码来源:test_callbacks.py

示例10: test_connect_async

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_async(self):
        signal = AdHocSignal()

        mock = unittest.mock.MagicMock()
        fun = functools.partial(mock)

        signal.connect(fun, AdHocSignal.ASYNC_WITH_LOOP(None))
        signal.fire()

        mock.assert_not_called()

        run_coroutine(asyncio.sleep(0))

        mock.assert_called_once_with()
开发者ID:horazont,项目名称:aioxmpp,代码行数:16,代码来源:test_callbacks.py

示例11: test_logger_on_emit_with_exception

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_logger_on_emit_with_exception(self):
        logger = unittest.mock.Mock()
        signal = AdHocSignal()
        signal.logger = logger

        a = unittest.mock.Mock()
        signal.connect(a)

        a.side_effect = Exception()

        signal()

        logger.exception.assert_called_with(
            "listener attached to signal raised"
        )
开发者ID:horazont,项目名称:aioxmpp,代码行数:17,代码来源:test_callbacks.py

示例12: test_full_isolation

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_full_isolation(self):
        signal = AdHocSignal()

        base = unittest.mock.Mock()

        base.a.return_value = None
        base.a.side_effect = OSError()

        base.b.return_value = None
        base.b.side_effect = Exception()

        base.c.return_value = None

        base.d.return_value = None
        base.d.side_effect = ValueError()

        signal.connect(base.a)
        signal.connect(base.b)
        signal.connect(base.c)
        signal.connect(base.d)

        signal()

        self.assertSequenceEqual(
            base.mock_calls,
            [
                unittest.mock.call.a(),
                unittest.mock.call.b(),
                unittest.mock.call.c(),
                unittest.mock.call.d(),
            ]
        )

        signal()

        self.assertSequenceEqual(
            base.mock_calls,
            [
                unittest.mock.call.a(),
                unittest.mock.call.b(),
                unittest.mock.call.c(),
                unittest.mock.call.d(),
                unittest.mock.call.c(),
            ]
        )
开发者ID:horazont,项目名称:aioxmpp,代码行数:47,代码来源:test_callbacks.py

示例13: test_connect_and_fire

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_and_fire(self):
        signal = AdHocSignal()

        fun = unittest.mock.MagicMock()
        fun.return_value = None

        signal.connect(fun)

        signal.fire()
        signal.fire()

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

示例14: test_connect_auto_future_uses_set_result_with_None

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_auto_future_uses_set_result_with_None(self):
        signal = AdHocSignal()

        fut = unittest.mock.Mock()
        fut.done.return_value = False

        signal.connect(fut, AdHocSignal.AUTO_FUTURE)

        signal()
        signal()

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

示例15: test_connect_skips_if_future_is_done

# 需要导入模块: from aioxmpp.callbacks import AdHocSignal [as 别名]
# 或者: from aioxmpp.callbacks.AdHocSignal import connect [as 别名]
    def test_connect_skips_if_future_is_done(self):
        signal = AdHocSignal()

        obj = ValueError()

        fut = unittest.mock.Mock()
        fut.done.return_value = True

        signal.connect(fut, AdHocSignal.AUTO_FUTURE)

        signal("foo")
        signal(obj)

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


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