Python tornado.testing.AsyncTestCase() Examples
The following are 30
code examples of tornado.testing.AsyncTestCase().
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 |
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])
Example #2
Source File: testing_test.py From pySINDy with MIT License | 6 votes |
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])
Example #3
Source File: testing_test.py From teleport with Apache License 2.0 | 6 votes |
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])
Example #4
Source File: testing_test.py From tornado-zh with MIT License | 6 votes |
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])
Example #5
Source File: ioloop_test.py From viewfinder with Apache License 2.0 | 6 votes |
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.
Example #6
Source File: ioloop_test.py From viewfinder with Apache License 2.0 | 6 votes |
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.
Example #7
Source File: testing_test.py From EventGhost with GNU General Public License v2.0 | 6 votes |
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])
Example #8
Source File: test_tornado.py From gremlinclient with MIT License | 6 votes |
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 #9
Source File: testing_test.py From pySINDy with MIT License | 5 votes |
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])
Example #10
Source File: ioloop_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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.
Example #11
Source File: testing_test.py From pySINDy with MIT License | 5 votes |
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)
Example #12
Source File: testing_test.py From pySINDy with MIT License | 5 votes |
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])
Example #13
Source File: testing_test.py From pySINDy with MIT License | 5 votes |
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)
Example #14
Source File: ioloop_test.py From pySINDy with MIT License | 5 votes |
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()
Example #15
Source File: ioloop_test.py From pySINDy with MIT License | 5 votes |
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.
Example #16
Source File: testing_test.py From honeything with GNU General Public License v3.0 | 5 votes |
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)
Example #17
Source File: base.py From tredis with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): super(AsyncTestCase, self).setUp() self.client = self.get_client() self._execute_result = None
Example #18
Source File: testing_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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])
Example #19
Source File: testing_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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)
Example #20
Source File: testing_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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])
Example #21
Source File: testing_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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)
Example #22
Source File: ioloop_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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.
Example #23
Source File: testing_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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])
Example #24
Source File: testing_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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])
Example #25
Source File: testing_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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)
Example #26
Source File: testing_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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])
Example #27
Source File: testing_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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)
Example #28
Source File: testing_test.py From tornado-zh with MIT License | 5 votes |
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])
Example #29
Source File: testing_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
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)
Example #30
Source File: testing_test.py From tornado-zh with MIT License | 5 votes |
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)