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


Python coroutines._DEBUG属性代码示例

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


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

示例1: test_yield_from_corowrapper

# 需要导入模块: from asyncio import coroutines [as 别名]
# 或者: from asyncio.coroutines import _DEBUG [as 别名]
def test_yield_from_corowrapper(self):
        old_debug = asyncio.coroutines._DEBUG
        asyncio.coroutines._DEBUG = True
        try:
            @asyncio.coroutine
            def t1():
                return (yield from t2())

            @asyncio.coroutine
            def t2():
                f = asyncio.Future(loop=self.loop)
                asyncio.Task(t3(f), loop=self.loop)
                return (yield from f)

            @asyncio.coroutine
            def t3(f):
                f.set_result((1, 2, 3))

            task = asyncio.Task(t1(), loop=self.loop)
            val = self.loop.run_until_complete(task)
            self.assertEqual(val, (1, 2, 3))
        finally:
            asyncio.coroutines._DEBUG = old_debug 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:25,代码来源:test_tasks.py

示例2: set_coroutine_debug

# 需要导入模块: from asyncio import coroutines [as 别名]
# 或者: from asyncio.coroutines import _DEBUG [as 别名]
def set_coroutine_debug(enabled):
    coroutines = asyncio.coroutines

    old_debug = coroutines._DEBUG
    try:
        coroutines._DEBUG = enabled
        yield
    finally:
        coroutines._DEBUG = old_debug 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_tasks.py

示例3: test_env_var_debug

# 需要导入模块: from asyncio import coroutines [as 别名]
# 或者: from asyncio.coroutines import _DEBUG [as 别名]
def test_env_var_debug(self):
        aio_path = os.path.dirname(os.path.dirname(asyncio.__file__))

        code = '\n'.join((
            'import asyncio.coroutines',
            'print(asyncio.coroutines._DEBUG)'))

        # Test with -E to not fail if the unit test was run with
        # PYTHONASYNCIODEBUG set to a non-empty string
        sts, stdout, stderr = assert_python_ok('-E', '-c', code,
                                               PYTHONPATH=aio_path)
        self.assertEqual(stdout.rstrip(), b'False')

        sts, stdout, stderr = assert_python_ok('-c', code,
                                               PYTHONASYNCIODEBUG='',
                                               PYTHONPATH=aio_path)
        self.assertEqual(stdout.rstrip(), b'False')

        sts, stdout, stderr = assert_python_ok('-c', code,
                                               PYTHONASYNCIODEBUG='1',
                                               PYTHONPATH=aio_path)
        self.assertEqual(stdout.rstrip(), b'True')

        sts, stdout, stderr = assert_python_ok('-E', '-c', code,
                                               PYTHONASYNCIODEBUG='1',
                                               PYTHONPATH=aio_path)
        self.assertEqual(stdout.rstrip(), b'False') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:29,代码来源:test_tasks.py

示例4: test_coroutine_never_yielded

# 需要导入模块: from asyncio import coroutines [as 别名]
# 或者: from asyncio.coroutines import _DEBUG [as 别名]
def test_coroutine_never_yielded(self, m_log):
        debug = asyncio.coroutines._DEBUG
        try:
            asyncio.coroutines._DEBUG = True
            @asyncio.coroutine
            def coro_noop():
                pass
        finally:
            asyncio.coroutines._DEBUG = debug

        tb_filename = __file__
        tb_lineno = sys._getframe().f_lineno + 2
        # create a coroutine object but don't use it
        coro_noop()
        support.gc_collect()

        self.assertTrue(m_log.error.called)
        message = m_log.error.call_args[0][0]
        func_filename, func_lineno = test_utils.get_function_source(coro_noop)
        regex = (r'^<CoroWrapper %s\(\) .* at %s:%s, .*> '
                    r'was never yielded from\n'
                 r'Coroutine object created at \(most recent call last\):\n'
                 r'.*\n'
                 r'  File "%s", line %s, in test_coroutine_never_yielded\n'
                 r'    coro_noop\(\)$'
                 % (re.escape(coro_noop.__qualname__),
                    re.escape(func_filename), func_lineno,
                    re.escape(tb_filename), tb_lineno))

        self.assertRegex(message, re.compile(regex, re.DOTALL)) 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:32,代码来源:test_tasks.py

示例5: test_task_repr

# 需要导入模块: from asyncio import coroutines [as 别名]
# 或者: from asyncio.coroutines import _DEBUG [as 别名]
def test_task_repr(self):
        self.loop.set_debug(False)

        @asyncio.coroutine
        def notmuch():
            yield from []
            return 'abc'

        # test coroutine function
        self.assertEqual(notmuch.__name__, 'notmuch')
        if PY35:
            self.assertEqual(notmuch.__qualname__,
                             'TaskTests.test_task_repr.<locals>.notmuch')
        self.assertEqual(notmuch.__module__, __name__)

        filename, lineno = test_utils.get_function_source(notmuch)
        src = "%s:%s" % (filename, lineno)

        # test coroutine object
        gen = notmuch()
        if coroutines._DEBUG or PY35:
            coro_qualname = 'TaskTests.test_task_repr.<locals>.notmuch'
        else:
            coro_qualname = 'notmuch'
        self.assertEqual(gen.__name__, 'notmuch')
        if PY35:
            self.assertEqual(gen.__qualname__,
                             coro_qualname)

        # test pending Task
        t = asyncio.Task(gen, loop=self.loop)
        t.add_done_callback(Dummy())

        coro = format_coroutine(coro_qualname, 'running', src,
                                t._source_traceback, generator=True)
        self.assertEqual(repr(t),
                         '<Task pending %s cb=[<Dummy>()]>' % coro)

        # test cancelling Task
        t.cancel()  # Does not take immediate effect!
        self.assertEqual(repr(t),
                         '<Task cancelling %s cb=[<Dummy>()]>' % coro)

        # test cancelled Task
        self.assertRaises(asyncio.CancelledError,
                          self.loop.run_until_complete, t)
        coro = format_coroutine(coro_qualname, 'done', src,
                                t._source_traceback)
        self.assertEqual(repr(t),
                         '<Task cancelled %s>' % coro)

        # test finished Task
        t = asyncio.Task(notmuch(), loop=self.loop)
        self.loop.run_until_complete(t)
        coro = format_coroutine(coro_qualname, 'done', src,
                                t._source_traceback)
        self.assertEqual(repr(t),
                         "<Task finished %s result='abc'>" % coro) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:60,代码来源:test_tasks.py

示例6: test_corowrapper_mocks_generator

# 需要导入模块: from asyncio import coroutines [as 别名]
# 或者: from asyncio.coroutines import _DEBUG [as 别名]
def test_corowrapper_mocks_generator(self):

        def check():
            # A function that asserts various things.
            # Called twice, with different debug flag values.

            @asyncio.coroutine
            def coro():
                # The actual coroutine.
                self.assertTrue(gen.gi_running)
                yield from fut

            # A completed Future used to run the coroutine.
            fut = asyncio.Future(loop=self.loop)
            fut.set_result(None)

            # Call the coroutine.
            gen = coro()

            # Check some properties.
            self.assertTrue(asyncio.iscoroutine(gen))
            self.assertIsInstance(gen.gi_frame, types.FrameType)
            self.assertFalse(gen.gi_running)
            self.assertIsInstance(gen.gi_code, types.CodeType)

            # Run it.
            self.loop.run_until_complete(gen)

            # The frame should have changed.
            self.assertIsNone(gen.gi_frame)

        # Save debug flag.
        old_debug = asyncio.coroutines._DEBUG
        try:
            # Test with debug flag cleared.
            asyncio.coroutines._DEBUG = False
            check()

            # Test with debug flag set.
            asyncio.coroutines._DEBUG = True
            check()

        finally:
            # Restore original debug flag.
            asyncio.coroutines._DEBUG = old_debug 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:47,代码来源:test_tasks.py


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