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


Python test_utils.run_briefly方法代码示例

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


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

示例1: test_make_ssl_transport

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_make_ssl_transport(self):
        m = mock.Mock()
        self.loop.add_reader = mock.Mock()
        self.loop.add_reader._is_coroutine = False
        self.loop.add_writer = mock.Mock()
        self.loop.remove_reader = mock.Mock()
        self.loop.remove_writer = mock.Mock()
        waiter = asyncio.Future(loop=self.loop)
        with test_utils.disable_logger():
            transport = self.loop._make_ssl_transport(
                m, asyncio.Protocol(), m, waiter)
            # execute the handshake while the logger is disabled
            # to ignore SSL handshake failure
            test_utils.run_briefly(self.loop)

        # Sanity check
        class_name = transport.__class__.__name__
        self.assertIn("ssl", class_name.lower())
        self.assertIn("transport", class_name.lower())

        transport.close()
        # execute pending callbacks to close the socket transport
        test_utils.run_briefly(self.loop) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:25,代码来源:test_selector_events.py

示例2: test_cancel_post_init

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_cancel_post_init(self):
        @asyncio.coroutine
        def cancel_make_transport():
            coro = self.loop.subprocess_exec(asyncio.SubprocessProtocol,
                                             *PROGRAM_BLOCKED)
            task = self.loop.create_task(coro)

            self.loop.call_soon(task.cancel)
            try:
                yield from task
            except asyncio.CancelledError:
                pass

        # ignore the log:
        # "Exception during subprocess creation, kill the subprocess"
        with test_utils.disable_logger():
            self.loop.run_until_complete(cancel_make_transport())
            test_utils.run_briefly(self.loop) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:20,代码来源:test_subprocess.py

示例3: test__write_ready_err

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test__write_ready_err(self, m_write, m_logexc):
        tr = self.write_pipe_transport()
        self.loop.add_writer(5, tr._write_ready)
        tr._buffer = [b'da', b'ta']
        m_write.side_effect = err = OSError()
        tr._write_ready()
        m_write.assert_called_with(5, b'data')
        self.assertFalse(self.loop.writers)
        self.assertFalse(self.loop.readers)
        self.assertEqual([], tr._buffer)
        self.assertTrue(tr._closing)
        m_logexc.assert_called_with(
            test_utils.MockPattern(
                'Fatal write error on pipe transport'
                '\nprotocol:.*\ntransport:.*'),
            exc_info=(OSError, MOCK_ANY, MOCK_ANY))
        self.assertEqual(1, tr._conn_lost)
        test_utils.run_briefly(self.loop)
        self.protocol.connection_lost.assert_called_with(err) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:21,代码来源:test_unix_events.py

示例4: test_cancel_both_task_and_inner_future

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_cancel_both_task_and_inner_future(self):
        f = asyncio.Future(loop=self.loop)

        @asyncio.coroutine
        def task():
            yield from f
            return 12

        t = asyncio.Task(task(), loop=self.loop)
        test_utils.run_briefly(self.loop)

        f.cancel()
        t.cancel()

        with self.assertRaises(asyncio.CancelledError):
            self.loop.run_until_complete(t)

        self.assertTrue(t.done())
        self.assertTrue(f.cancelled())
        self.assertTrue(t.cancelled()) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:22,代码来源:test_tasks.py

示例5: test_task_cancel_waiter_future

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_task_cancel_waiter_future(self):
        fut = asyncio.Future(loop=self.loop)

        @asyncio.coroutine
        def coro():
            yield from fut

        task = asyncio.Task(coro(), loop=self.loop)
        test_utils.run_briefly(self.loop)
        self.assertIs(task._fut_waiter, fut)

        task.cancel()
        test_utils.run_briefly(self.loop)
        self.assertRaises(
            asyncio.CancelledError, self.loop.run_until_complete, task)
        self.assertIsNone(task._fut_waiter)
        self.assertTrue(fut.cancelled()) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:19,代码来源:test_tasks.py

示例6: test_shield_effect

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_shield_effect(self):
        # Cancelling outer() does not affect inner().
        proof = 0
        waiter = asyncio.Future(loop=self.loop)

        @asyncio.coroutine
        def inner():
            nonlocal proof
            yield from waiter
            proof += 1

        @asyncio.coroutine
        def outer():
            nonlocal proof
            yield from asyncio.shield(inner(), loop=self.loop)
            proof += 100

        f = asyncio.async(outer(), loop=self.loop)
        test_utils.run_briefly(self.loop)
        f.cancel()
        with self.assertRaises(asyncio.CancelledError):
            self.loop.run_until_complete(f)
        waiter.set_result(None)
        test_utils.run_briefly(self.loop)
        self.assertEqual(proof, 1) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:27,代码来源:test_tasks.py

示例7: test_exception_marking

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_exception_marking(self):
        # Test for the first line marked "Mark exception retrieved."

        @asyncio.coroutine
        def inner(f):
            yield from f
            raise RuntimeError('should not be ignored')

        a = asyncio.Future(loop=self.one_loop)
        b = asyncio.Future(loop=self.one_loop)

        @asyncio.coroutine
        def outer():
            yield from asyncio.gather(inner(a), inner(b), loop=self.one_loop)

        f = asyncio.async(outer(), loop=self.one_loop)
        test_utils.run_briefly(self.one_loop)
        a.set_result(None)
        test_utils.run_briefly(self.one_loop)
        b.set_result(None)
        test_utils.run_briefly(self.one_loop)
        self.assertIsInstance(f.exception(), RuntimeError) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:24,代码来源:test_tasks.py

示例8: test_dispatch_filter_decorator_single

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_dispatch_filter_decorator_single(self):
        recv = EventReceiver(loop=self.loop)
        cap_evt = None

        @event.filter_handler(self.evt_one, param2=456)
        def handler(evt, **kw):
            nonlocal cap_evt
            cap_evt = evt

        recv.add_event_handler(self.evt_one, handler)
        recv.dispatch_event(self.evt_one, param1=False, param2=123)
        test_utils.run_briefly(self.loop)
        self.assertIsNone(cap_evt)

        recv.dispatch_event(self.evt_one, param1=False, param2=456)
        test_utils.run_briefly(self.loop)
        self.assertIsNotNone(cap_evt)
        self.assertEqual(cap_evt.param2, 456) 
开发者ID:anki,项目名称:cozmo-python-sdk,代码行数:20,代码来源:test_event.py

示例9: test_dispatch_filter_decorator_multiple

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_dispatch_filter_decorator_multiple(self):
        recv = EventReceiver(loop=self.loop)
        cap_evt = None

        @event.filter_handler(self.evt_one, param2=456)
        @event.filter_handler(self.evt_one, param2=789)
        def handler(evt, **kw):
            nonlocal cap_evt
            cap_evt = evt

        recv.add_event_handler(self.evt_one, handler)

        for num in (123,456,234,789):
            cap_evt = None
            recv.dispatch_event(self.evt_one, param1=False, param2=num)
            test_utils.run_briefly(self.loop)
            if num in (123, 234):
                self.assertIsNone(cap_evt, msg="num=%d evt=%s" % (num, cap_evt))
            else:
                self.assertIsNotNone(cap_evt, msg="num=%d" % (num,))
                self.assertEqual(cap_evt.param2, num, msg="num=%d evt=%s" % (num, cap_evt)) 
开发者ID:anki,项目名称:cozmo-python-sdk,代码行数:23,代码来源:test_event.py

示例10: test_dispatch_filter_decorator_lambda

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_dispatch_filter_decorator_lambda(self):
        recv = EventReceiver(loop=self.loop)
        cap_evt = None

        @event.filter_handler(self.evt_one, param2=lambda val: val > 400)
        def handler(evt, **kw):
            nonlocal cap_evt
            cap_evt = evt

        recv.add_event_handler(self.evt_one, handler)

        for num in (123,456,234,789):
            cap_evt = None
            recv.dispatch_event(self.evt_one, param1=False, param2=num)
            test_utils.run_briefly(self.loop)
            if num in (123, 234):
                self.assertIsNone(cap_evt, msg="num=%d evt=%s" % (num, cap_evt))
            else:
                self.assertIsNotNone(cap_evt, msg="num=%d" % (num,))
                self.assertEqual(cap_evt.param2, num, msg="num=%d evt=%s" % (num, cap_evt)) 
开发者ID:anki,项目名称:cozmo-python-sdk,代码行数:22,代码来源:test_event.py

示例11: test_obj_receiver_filter

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_obj_receiver_filter(self):
        cap_evt = None

        class filtered_receiver(event.Dispatcher):
            @event.filter_handler(self.evt_one, param2=456)
            def recv_evt_one(self, evt, **kw):
                nonlocal cap_evt
                cap_evt = evt

        recv = filtered_receiver(loop=self.loop)
        recv.dispatch_event(self.evt_one, param1=False, param2=100)
        test_utils.run_briefly(self.loop)
        self.assertIsNone(cap_evt)

        recv.dispatch_event(self.evt_one, param1=False, param2=456)
        test_utils.run_briefly(self.loop)
        self.assertIsNotNone(cap_evt)
        self.assertEqual(cap_evt.param2, 456) 
开发者ID:anki,项目名称:cozmo-python-sdk,代码行数:20,代码来源:test_event.py

示例12: test_dispatch_parents_to_handler

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_dispatch_parents_to_handler(self):
        # Test dispatching an event subclass to a handler listening to the parent
        recv = EventReceiver(loop=self.loop)
        cap_evts = []
        def capture(evt, **kw):
            nonlocal cap_evts
            cap_evts.append(evt)

        recv.add_event_handler(self.evt_one, capture)
        recv.dispatch_event(self.evt_child2, param1=False, param2=234, param5=567)
        test_utils.run_briefly(self.loop)

        # only the most specific event (EvtChild2) should of been sent to the handler
        self.assertEqual(1, len(cap_evts))
        cap_evt = cap_evts[0]
        self.assertIsInstance(cap_evt, self.evt_child2)
        self.assertEqual(cap_evt.param5, 567) 
开发者ID:anki,项目名称:cozmo-python-sdk,代码行数:19,代码来源:test_event.py

示例13: test_handler_disable_implicit

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_handler_disable_implicit(self):
        count = 0
        def handler(evt, **kw):
            nonlocal count
            count += 1

        recv = event.Dispatcher(loop=self.loop)
        hnd = recv.add_event_handler(self.evt_one, handler)
        # call twice
        recv.dispatch_event(self.evt_one, param1=False, param2=123)
        recv.dispatch_event(self.evt_one, param1=False, param2=123)

        # should no longer be dispatched
        hnd.disable()
        recv.dispatch_event(self.evt_one, param1=False, param2=123)
        test_utils.run_briefly(self.loop)

        self.assertEqual(count, 2) 
开发者ID:anki,项目名称:cozmo-python-sdk,代码行数:20,代码来源:test_event.py

示例14: test_handler_disable_explicit

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_handler_disable_explicit(self):
        count = 0
        def handler(evt, **kw):
            nonlocal count
            count += 1

        recv = event.Dispatcher(loop=self.loop)
        hnd = recv.add_event_handler(self.evt_one, handler)

        # call twice
        recv.dispatch_event(self.evt_one, param1=False, param2=123)
        recv.dispatch_event(self.evt_one, param1=False, param2=123)

        # should no longer be dispatched
        recv.remove_event_handler(self.evt_one, hnd)
        recv.dispatch_event(self.evt_one, param1=False, param2=123)
        test_utils.run_briefly(self.loop)

        self.assertEqual(count, 2) 
开发者ID:anki,项目名称:cozmo-python-sdk,代码行数:21,代码来源:test_event.py

示例15: test_dispatch_to_children

# 需要导入模块: from asyncio import test_utils [as 别名]
# 或者: from asyncio.test_utils import run_briefly [as 别名]
def test_dispatch_to_children(self):
        class Target(event.Dispatcher):
            def __init__(self, **kw):
                super().__init__(**kw)
                self.count = 0

            def recv_evt_one(self, *a, **kw):
                print("TRAP", self)
                self.count += 1

        parent = Target(loop=self.loop)
        child1 = Target(loop=self.loop)
        child2 = Target(loop=self.loop)
        other = Target(loop=self.loop)
        parent._add_child_dispatcher(child1)
        parent._add_child_dispatcher(child2)

        parent.dispatch_event(self.evt_one, param1=False, param2=123)
        test_utils.run_briefly(self.loop)

        self.assertEqual(parent.count, 1)
        self.assertEqual(child1.count, 1)
        self.assertEqual(child2.count, 1)
        self.assertEqual(other.count, 0) 
开发者ID:anki,项目名称:cozmo-python-sdk,代码行数:26,代码来源:test_event.py


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