Python tornado.testing.gen_test() Examples

The following are 30 code examples of tornado.testing.gen_test(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tornado.testing , or try the search function .
Example #1
Source File: testing_test.py    From tornado-zh with MIT License 6 votes vote down vote up
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 
Example #2
Source File: test_tornado.py    From gremlinclient with MIT License 6 votes vote down vote up
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() 
Example #3
Source File: test_tornado.py    From gremlinclient with MIT License 6 votes vote down vote up
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) 
Example #4
Source File: iostream_test.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
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() 
Example #5
Source File: testing_test.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #6
Source File: testing_test.py    From opendevops with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #7
Source File: testing_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
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 
Example #8
Source File: testing_test.py    From tornado-zh with MIT License 6 votes vote down vote up
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 
Example #9
Source File: testing_test.py    From teleport with Apache License 2.0 6 votes vote down vote up
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 
Example #10
Source File: testing_test.py    From pySINDy with MIT License 6 votes vote down vote up
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 
Example #11
Source File: iostream_test.py    From tornado-zh with MIT License 6 votes vote down vote up
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() 
Example #12
Source File: iostream_test.py    From tornado-zh with MIT License 6 votes vote down vote up
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() 
Example #13
Source File: testing_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def test_native_coroutine_timeout(self):
        # Set a short timeout and exceed it.
        @gen_test(timeout=0.1)
        async def test(self):
            await gen.sleep(1)

        try:
            test(self)
            self.fail("did not get expected exception")
        except ioloop.TimeoutError:
            self.finished = True 
Example #14
Source File: testing_test.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #15
Source File: testing_test.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #16
Source File: testing_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
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 
Example #17
Source File: testing_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
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 
Example #18
Source File: testing_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def test_no_timeout_environment_variable(self):
        @gen_test(timeout=0.01)
        def test_short_timeout(self):
            yield gen.sleep(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 
Example #19
Source File: testing_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def test_with_method_args(self):
        @gen_test
        def test_with_args(self, *args):
            self.assertEqual(args, ("test",))
            yield gen.moment

        test_with_args(self, "test")
        self.finished = True 
Example #20
Source File: testing_test.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def test_native_coroutine(self):
        @gen_test
        async def test(self):
            self.finished = True

        test(self) 
Example #21
Source File: testing_test.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #22
Source File: testing_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def test_native_coroutine(self):
        namespace = exec_test(globals(), locals(), """
        @gen_test
        async def test(self):
            self.finished = True
        """)

        namespace['test'](self) 
Example #23
Source File: testing_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
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 
Example #24
Source File: test_tornado.py    From gremlinclient with MIT License 5 votes vote down vote up
def test_wrong_protocol_exception(self):
        graph = GraphDatabase("wss://localhost:8182/")
        with self.assertRaises(RuntimeError):
            connection = yield graph.connect()

    # Check this out
    # @gen_test
    # def test_bad_host_exception(self):
    #     graph = GraphDatabase("ws://locaost:8182/")
    #     with self.assertRaises(RuntimeError):
    #         connection = yield graph.connect() 
Example #25
Source File: testing_test.py    From pySINDy with MIT License 5 votes vote down vote up
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 
Example #26
Source File: testing_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_native_coroutine(self):
        namespace = exec_test(globals(), locals(), """
        @gen_test
        async def test(self):
            self.finished = True
        """)

        namespace['test'](self) 
Example #27
Source File: testing_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_with_method_args(self):
        @gen_test
        def test_with_args(self, *args):
            self.assertEqual(args, ('test',))
            yield gen.moment

        test_with_args(self, 'test')
        self.finished = True 
Example #28
Source File: testing_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_no_timeout_environment_variable(self):
        @gen_test(timeout=0.01)
        def test_short_timeout(self):
            yield gen.sleep(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 
Example #29
Source File: testing_test.py    From pySINDy with MIT License 5 votes vote down vote up
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 
Example #30
Source File: testing_test.py    From pySINDy with MIT License 5 votes vote down vote up
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