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


Python util.exec_test方法代码示例

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


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

示例1: test_undecorated_coroutine

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_undecorated_coroutine(self):
        namespace = exec_test(globals(), locals(), """
        class Test(AsyncTestCase):
            async def test_coro(self):
                pass
        """)

        test_class = namespace['Test']
        test = test_class('test_coro')
        result = unittest.TestResult()

        # Silence "RuntimeWarning: coroutine 'test_coro' was never awaited".
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            test.run(result)

        self.assertEqual(len(result.errors), 1)
        self.assertIn("should be decorated", result.errors[0][1]) 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:20,代码来源:testing_test.py

示例2: test_acquire_fifo_async_with

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_acquire_fifo_async_with(self):
        # Repeat the above test using `async with lock:`
        # instead of `with (yield lock.acquire()):`.
        lock = locks.Lock()
        self.assertTrue(lock.acquire().done())
        N = 5
        history = []

        namespace = exec_test(globals(), locals(), """
        async def f(idx):
            async with lock:
                history.append(idx)
        """)
        futures = [namespace['f'](i) for i in range(N)]
        lock.release()
        yield futures
        self.assertEqual(list(range(N)), history) 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:19,代码来源:locks_test.py

示例3: test_async_await_mixed_multi_native_yieldpoint

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_async_await_mixed_multi_native_yieldpoint(self):
        namespace = exec_test(globals(), locals(), """
        async def f1():
            await gen.Task(self.io_loop.add_callback)
            return 42
        """)

        @gen.coroutine
        def f2():
            yield gen.Task(self.io_loop.add_callback)
            raise gen.Return(43)

        f2(callback=(yield gen.Callback('cb')))
        results = yield [namespace['f1'](), gen.Wait('cb')]
        self.assertEqual(results, [42, 43])
        self.finished = True 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:18,代码来源:gen_test.py

示例4: test_native_coroutine

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_native_coroutine(self):
        namespace = exec_test(globals(), locals(), """
        @gen_test
        async def test(self):
            self.finished = True
        """)

        namespace['test'](self) 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:10,代码来源:testing_test.py

示例5: test_native_coroutine_timeout

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_native_coroutine_timeout(self):
        # Set a short timeout and exceed it.
        namespace = exec_test(globals(), locals(), """
        @gen_test(timeout=0.1)
        async def test(self):
            await gen.sleep(1)
        """)

        try:
            namespace['test'](self)
            self.fail("did not get expected exception")
        except ioloop.TimeoutError:
            self.finished = True 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:15,代码来源:testing_test.py

示例6: test_context_manager_async_await

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_context_manager_async_await(self):
        # Repeat the above test using 'async with'.
        sem = locks.Semaphore()

        namespace = exec_test(globals(), locals(), """
        async def f():
            async with sem as yielded:
                self.assertTrue(yielded is None)
        """)
        yield namespace['f']()

        # Semaphore was released and can be acquired again.
        self.assertTrue(sem.acquire().done()) 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:15,代码来源:locks_test.py

示例7: test_exception_logging_native_coro

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_exception_logging_native_coro(self):
        """The IOLoop examines exceptions from awaitables and logs them."""
        namespace = exec_test(globals(), locals(), """
        async def callback():
            self.io_loop.add_callback(self.stop)
            1 / 0
        """)
        with NullContext():
            self.io_loop.add_callback(namespace["callback"])
            with ExpectLog(app_log, "Exception in callback"):
                self.wait() 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:13,代码来源:ioloop_test.py

示例8: test_native_coroutine

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_native_coroutine(self):
        namespace = exec_test(globals(), locals(), """
        async def f():
            await gen.Task(self.io_loop.add_callback)
        """)
        self.io_loop.run_sync(namespace['f']) 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:8,代码来源:ioloop_test.py

示例9: test_async_return

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_async_return(self):
        namespace = exec_test(globals(), locals(), """
        @gen.coroutine
        def f():
            yield gen.Task(self.io_loop.add_callback)
            return 42
        """)
        result = yield namespace['f']()
        self.assertEqual(result, 42)
        self.finished = True 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:12,代码来源:gen_test.py

示例10: test_async_early_return

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_async_early_return(self):
        # A yield statement exists but is not executed, which means
        # this function "returns" via an exception.  This exception
        # doesn't happen before the exception handling is set up.
        namespace = exec_test(globals(), locals(), """
        @gen.coroutine
        def f():
            if True:
                return 42
            yield gen.Task(self.io_loop.add_callback)
        """)
        result = yield namespace['f']()
        self.assertEqual(result, 42)
        self.finished = True 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:16,代码来源:gen_test.py

示例11: test_async_await

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_async_await(self):
        # This test verifies that an async function can await a
        # yield-based gen.coroutine, and that a gen.coroutine
        # (the test method itself) can yield an async function.
        namespace = exec_test(globals(), locals(), """
        async def f():
            await gen.Task(self.io_loop.add_callback)
            return 42
        """)
        result = yield namespace['f']()
        self.assertEqual(result, 42)
        self.finished = True 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:14,代码来源:gen_test.py

示例12: test_iterator_async_await

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_iterator_async_await(self):
        # Recreate the previous test with py35 syntax. It's a little clunky
        # because of the way the previous test handles an exception on
        # a single iteration.
        futures = [Future(), Future(), Future(), Future()]
        self.finish_coroutines(0, futures)
        self.finished = False

        namespace = exec_test(globals(), locals(), """
        async def f():
            i = 0
            g = gen.WaitIterator(*futures)
            try:
                async for r in g:
                    if i == 0:
                        self.assertEqual(r, 24, 'iterator value incorrect')
                        self.assertEqual(g.current_index, 2, 'wrong index')
                    else:
                        raise Exception("expected exception on iteration 1")
                    i += 1
            except ZeroDivisionError:
                i += 1
            async for r in g:
                if i == 2:
                    self.assertEqual(r, 42, 'iterator value incorrect')
                    self.assertEqual(g.current_index, 1, 'wrong index')
                elif i == 3:
                    self.assertEqual(r, 84, 'iterator value incorrect')
                    self.assertEqual(g.current_index, 3, 'wrong index')
                else:
                    raise Exception("didn't expect iteration %d" % i)
                i += 1
            self.finished = True
        """)
        yield namespace['f']()
        self.assertTrue(self.finished) 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:38,代码来源:gen_test.py

示例13: get_handlers

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def get_handlers(self):
        class NativeFlowControlHandler(BaseFlowControlHandler):
            data_received = exec_test(globals(), locals(), """
            async def data_received(self, data):
                with self.in_method('data_received'):
                    await gen.Task(IOLoop.current().add_callback)
            """)["data_received"]
        return [('/', NativeFlowControlHandler, dict(test=self))] 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:10,代码来源:web_test.py

示例14: test_asyncio_yield_from

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_asyncio_yield_from(self):
        # Test that we can use asyncio coroutines with 'yield from'
        # instead of asyncio.async(). This requires python 3.3 syntax.
        namespace = exec_test(globals(), locals(), """
        @gen.coroutine
        def f():
            event_loop = asyncio.get_event_loop()
            x = yield from event_loop.run_in_executor(None, lambda: 42)
            return x
        """)
        result = yield namespace['f']()
        self.assertEqual(result, 42) 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:14,代码来源:asyncio_test.py

示例15: test_native_body_producer_content_length

# 需要导入模块: from tornado.test import util [as 别名]
# 或者: from tornado.test.util import exec_test [as 别名]
def test_native_body_producer_content_length(self):
        namespace = exec_test(globals(), locals(), """
        async def body_producer(write):
            await write(b'1234')
            await gen.Task(IOLoop.current().add_callback)
            await write(b'5678')
        """)
        response = self.fetch("/echo_post", method="POST",
                              body_producer=namespace["body_producer"],
                              headers={'Content-Length': '8'})
        response.rethrow()
        self.assertEqual(response.body, b"12345678") 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:14,代码来源:simple_httpclient_test.py


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