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


Python testing.AsyncTestCase方法代碼示例

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


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

示例1: test_undecorated_coroutine

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

示例2: test_remove_timeout_cleanup

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_remove_timeout_cleanup(self):
        # Add and remove enough callbacks to trigger cleanup.
        # Not a very thorough test, but it ensures that the cleanup code
        # gets executed and doesn't blow up.  This test is only really useful
        # on PollIOLoop subclasses, but it should run silently on any
        # implementation.
        for i in range(2000):
            timeout = self.io_loop.add_timeout(self.io_loop.time() + 3600,
                                               lambda: None)
            self.io_loop.remove_timeout(timeout)
        # HACK: wait two IOLoop iterations for the GC to happen.
        self.io_loop.add_callback(lambda: self.io_loop.add_callback(self.stop))
        self.wait()


# Deliberately not a subclass of AsyncTestCase so the IOLoop isn't
# automatically set as current. 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:19,代碼來源:ioloop_test.py

示例3: test_script_exception

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [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

示例4: test_undecorated_generator

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_undecorated_generator(self):
        class Test(AsyncTestCase):
            def test_gen(self):
                yield
        test = Test('test_gen')
        result = unittest.TestResult()
        test.run(result)
        self.assertEqual(len(result.errors), 1)
        self.assertIn("should be decorated", result.errors[0][1]) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:11,代碼來源:testing_test.py

示例5: test_undecorated_generator_with_skip

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_undecorated_generator_with_skip(self):
        class Test(AsyncTestCase):
            @unittest.skip("don't run this")
            def test_gen(self):
                yield
        test = Test('test_gen')
        result = unittest.TestResult()
        test.run(result)
        self.assertEqual(len(result.errors), 0)
        self.assertEqual(len(result.skipped), 1) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:12,代碼來源:testing_test.py

示例6: test_other_return

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_other_return(self):
        class Test(AsyncTestCase):
            def test_other_return(self):
                return 42
        test = Test('test_other_return')
        result = unittest.TestResult()
        test.run(result)
        self.assertEqual(len(result.errors), 1)
        self.assertIn("Return value from test method ignored", result.errors[0][1]) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:11,代碼來源:testing_test.py

示例7: test_set_up_tear_down

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_set_up_tear_down(self):
        """
        This test makes sure that AsyncTestCase calls super methods for
        setUp and tearDown.

        InheritBoth is a subclass of both AsyncTestCase and
        SetUpTearDown, with the ordering so that the super of
        AsyncTestCase will be SetUpTearDown.
        """
        events = []
        result = unittest.TestResult()

        class SetUpTearDown(unittest.TestCase):
            def setUp(self):
                events.append('setUp')

            def tearDown(self):
                events.append('tearDown')

        class InheritBoth(AsyncTestCase, SetUpTearDown):
            def test(self):
                events.append('test')

        InheritBoth('test').run(result)
        expected = ['setUp', 'test', 'tearDown']
        self.assertEqual(expected, events) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:28,代碼來源:testing_test.py

示例8: test_remove_handler_from_handler

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_remove_handler_from_handler(self):
        # Create two sockets with simultaneous read events.
        client, server = socket.socketpair()
        try:
            client.send(b'abc')
            server.send(b'abc')

            # After reading from one fd, remove the other from the IOLoop.
            chunks = []

            def handle_read(fd, events):
                chunks.append(fd.recv(1024))
                if fd is client:
                    self.io_loop.remove_handler(server)
                else:
                    self.io_loop.remove_handler(client)
            self.io_loop.add_handler(client, handle_read, self.io_loop.READ)
            self.io_loop.add_handler(server, handle_read, self.io_loop.READ)
            self.io_loop.call_later(0.03, self.stop)
            self.wait()

            # Only one fd was read; the other was cleanly removed.
            self.assertEqual(chunks, [b'abc'])
        finally:
            client.close()
            server.close()


# Deliberately not a subclass of AsyncTestCase so the IOLoop isn't
# automatically set as current. 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:32,代碼來源:ioloop_test.py

示例9: test_exception_logging

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_exception_logging(self):
        """Uncaught exceptions get logged by the IOLoop."""
        # Use a NullContext to keep the exception from being caught by
        # AsyncTestCase.
        with NullContext():
            self.io_loop.add_callback(lambda: 1 / 0)
            self.io_loop.add_callback(self.stop)
            with ExpectLog(app_log, "Exception in callback"):
                self.wait() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:11,代碼來源:ioloop_test.py

示例10: test_undecorated_generator

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_undecorated_generator(self):
        class Test(AsyncTestCase):
            def test_gen(self):
                yield

        test = Test("test_gen")
        result = unittest.TestResult()
        test.run(result)
        self.assertEqual(len(result.errors), 1)
        self.assertIn("should be decorated", result.errors[0][1]) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:12,代碼來源:testing_test.py

示例11: test_undecorated_coroutine

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_undecorated_coroutine(self):
        class Test(AsyncTestCase):
            async def test_coro(self):
                pass

        test = Test("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:opendevops-cn,項目名稱:opendevops,代碼行數:17,代碼來源:testing_test.py

示例12: test_undecorated_generator_with_skip

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_undecorated_generator_with_skip(self):
        class Test(AsyncTestCase):
            @unittest.skip("don't run this")
            def test_gen(self):
                yield

        test = Test("test_gen")
        result = unittest.TestResult()
        test.run(result)
        self.assertEqual(len(result.errors), 0)
        self.assertEqual(len(result.skipped), 1) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:13,代碼來源:testing_test.py

示例13: test_other_return

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_other_return(self):
        class Test(AsyncTestCase):
            def test_other_return(self):
                return 42

        test = Test("test_other_return")
        result = unittest.TestResult()
        test.run(result)
        self.assertEqual(len(result.errors), 1)
        self.assertIn("Return value from test method ignored", result.errors[0][1]) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:12,代碼來源:testing_test.py

示例14: test_set_up_tear_down

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_set_up_tear_down(self):
        """
        This test makes sure that AsyncTestCase calls super methods for
        setUp and tearDown.

        InheritBoth is a subclass of both AsyncTestCase and
        SetUpTearDown, with the ordering so that the super of
        AsyncTestCase will be SetUpTearDown.
        """
        events = []
        result = unittest.TestResult()

        class SetUpTearDown(unittest.TestCase):
            def setUp(self):
                events.append("setUp")

            def tearDown(self):
                events.append("tearDown")

        class InheritBoth(AsyncTestCase, SetUpTearDown):
            def test(self):
                events.append("test")

        InheritBoth("test").run(result)
        expected = ["setUp", "test", "tearDown"]
        self.assertEqual(expected, events) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:28,代碼來源:testing_test.py

示例15: test_init_close_race

# 需要導入模塊: from tornado import testing [as 別名]
# 或者: from tornado.testing import AsyncTestCase [as 別名]
def test_init_close_race(self):
        # Regression test for #2367
        def f():
            for i in range(10):
                loop = IOLoop()
                loop.close()

        yield gen.multi([self.io_loop.run_in_executor(None, f) for i in range(2)])


# Deliberately not a subclass of AsyncTestCase so the IOLoop isn't
# automatically set as current. 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:14,代碼來源:ioloop_test.py


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