當前位置: 首頁>>代碼示例>>Python>>正文


Python testing.gen_test方法代碼示例

本文整理匯總了Python中tornado.testing.gen_test方法的典型用法代碼示例。如果您正苦於以下問題:Python testing.gen_test方法的具體用法?Python testing.gen_test怎麽用?Python testing.gen_test使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.testing的用法示例。


在下文中一共展示了testing.gen_test方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_future_delayed_close_callback

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_future_delayed_close_callback(self):
        # Same as test_delayed_close_callback, but with the future interface.
        server, client = self.make_iostream_pair()

        # We can't call make_iostream_pair inside a gen_test function
        # because the ioloop is not reentrant.
        @gen_test
        def f(self):
            server.write(b"12")
            chunks = []
            chunks.append((yield client.read_bytes(1)))
            server.close()
            chunks.append((yield client.read_bytes(1)))
            self.assertEqual(chunks, [b"1", b"2"])
        try:
            f(self)
        finally:
            server.close()
            client.close() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:21,代碼來源:iostream_test.py

示例2: test_timeout

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_timeout(self):
        # Set a short timeout and exceed it.
        @gen_test(timeout=0.1)
        def test(self):
            yield gen.Task(self.io_loop.add_timeout, self.io_loop.time() + 1)

        # This can't use assertRaises because we need to inspect the
        # exc_info triple (and not just the exception object)
        try:
            test(self)
            self.fail("did not get expected exception")
        except ioloop.TimeoutError:
            # The stack trace should blame the add_timeout line, not just
            # unrelated IOLoop/testing internals.
            self.assertIn(
                "gen.Task(self.io_loop.add_timeout, self.io_loop.time() + 1)",
                traceback.format_exc())

        self.finished = True 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:21,代碼來源:testing_test.py

示例3: test_timeout

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_timeout(self):
        # Set a short timeout and exceed it.
        @gen_test(timeout=0.1)
        def test(self):
            yield gen.sleep(1)

        # This can't use assertRaises because we need to inspect the
        # exc_info triple (and not just the exception object)
        try:
            test(self)
            self.fail("did not get expected exception")
        except ioloop.TimeoutError:
            # The stack trace should blame the add_timeout line, not just
            # unrelated IOLoop/testing internals.
            self.assertIn("gen.sleep(1)", traceback.format_exc())

        self.finished = True 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:19,代碼來源:testing_test.py

示例4: test_timeout

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_timeout(self):
        # Set a short timeout and exceed it.
        @gen_test(timeout=0.1)
        def test(self):
            yield gen.sleep(1)

        # This can't use assertRaises because we need to inspect the
        # exc_info triple (and not just the exception object)
        try:
            test(self)
            self.fail("did not get expected exception")
        except ioloop.TimeoutError:
            # The stack trace should blame the add_timeout line, not just
            # unrelated IOLoop/testing internals.
            self.assertIn(
                "gen.sleep(1)",
                traceback.format_exc())

        self.finished = True 
開發者ID:tp4a,項目名稱:teleport,代碼行數:21,代碼來源:testing_test.py

示例5: test_null_read_on_closed

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_null_read_on_closed(self):
        connection = yield self.graph.connect()
        # build connection
        connection.close()
        stream = Stream(connection, None, "processor", None, None, "stephen",
                        "password", False, False, Future)
        with self.assertRaises(RuntimeError):
            msg = yield stream.read()

    # @gen_test
    # def test_creditials_error(self):
    #     graph = GraphDatabase("ws://localhost:8182/",
    #                             username="stephen",
    #                             password="passwor")
    #     connection = yield graph.connect()
    #     resp = connection.send("1 + 1")
    #     with self.assertRaises(RuntimeError):
    #         msg = yield resp.read()
    #     connection.conn.close() 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:21,代碼來源:test_tornado.py

示例6: test_script_exception

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_script_exception(self):
        with self.assertRaises(RuntimeError):
            stream = yield submit("ws://localhost:8182/",
                                  "throw new Exception('error')",
                                   password="password", username="stephen")
            yield stream.read()


# class TestDeserialization(AsyncTestCase):
#
#     @gen_test
#     def test_complex_map_bindings(self):
#         stream = yield submit("ws://localhost:8182/",
#                               "x.b",
#                               bindings={"x":{'f': {'foo': 'bar'}, 'b': ['bar', None, 1.5, {'b': 1}]}},
#                               password="password", username="stephen")
#         resp = yield stream.read()
#         self.assertEqual(resp.data[0], 'bar')
#         self.assertIsNone(resp.data[1])
#         self.assertEqual(resp.data[3]['b'], 1) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:22,代碼來源:test_tornado.py

示例7: test_no_timeout

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_no_timeout(self):
        # A test that does not exceed its timeout should succeed.
        @gen_test(timeout=1)
        def test(self):
            time = self.io_loop.time
            yield gen.Task(self.io_loop.add_timeout, time() + 0.1)

        test(self)
        self.finished = True 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:11,代碼來源:testing_test.py

示例8: test_timeout_environment_variable

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_timeout_environment_variable(self):
        @gen_test(timeout=0.5)
        def test_long_timeout(self):
            time = self.io_loop.time
            yield gen.Task(self.io_loop.add_timeout, time() + 0.25)

        # Uses provided timeout of 0.5 seconds, doesn't time out.
        with set_environ('ASYNC_TEST_TIMEOUT', '0.1'):
            test_long_timeout(self)

        self.finished = True 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:13,代碼來源:testing_test.py

示例9: test_no_timeout_environment_variable

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_no_timeout_environment_variable(self):
        @gen_test(timeout=0.01)
        def test_short_timeout(self):
            time = self.io_loop.time
            yield gen.Task(self.io_loop.add_timeout, time() + 1)

        # Uses environment-variable timeout of 0.1, times out.
        with set_environ('ASYNC_TEST_TIMEOUT', '0.1'):
            with self.assertRaises(ioloop.TimeoutError):
                test_short_timeout(self)

        self.finished = True 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:14,代碼來源:testing_test.py

示例10: test_with_method_kwargs

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_with_method_kwargs(self):
        @gen_test
        def test_with_kwargs(self, **kwargs):
            self.assertDictEqual(kwargs, {'test': 'test'})
            yield gen.Task(self.io_loop.add_callback)

        test_with_kwargs(self, test='test')
        self.finished = True 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:testing_test.py

示例11: test_native_coroutine

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_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:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:testing_test.py

示例12: test_native_coroutine_timeout

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_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:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:testing_test.py

示例13: test_with_method_args

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_with_method_args(self):
        @gen_test
        def test_with_args(self, *args):
            self.assertEqual(args, ('test',))
            yield gen.Task(self.io_loop.add_callback)

        test_with_args(self, 'test')
        self.finished = True 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:testing_test.py

示例14: test_no_timeout

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_no_timeout(self):
        # A test that does not exceed its timeout should succeed.
        @gen_test(timeout=1)
        def test(self):
            yield gen.sleep(0.1)

        test(self)
        self.finished = True 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:10,代碼來源:testing_test.py

示例15: test_timeout_environment_variable

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import gen_test [as 別名]
def test_timeout_environment_variable(self):
        @gen_test(timeout=0.5)
        def test_long_timeout(self):
            yield gen.sleep(0.25)

        # Uses provided timeout of 0.5 seconds, doesn't time out.
        with set_environ("ASYNC_TEST_TIMEOUT", "0.1"):
            test_long_timeout(self)

        self.finished = True 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:12,代碼來源:testing_test.py


注:本文中的tornado.testing.gen_test方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。