Go to the documentation of this file.00001
00002
00003 from __future__ import absolute_import, division, with_statement
00004 import unittest
00005 import time
00006 from tornado.testing import AsyncTestCase, LogTrapTestCase
00007
00008
00009 class AsyncTestCaseTest(AsyncTestCase, LogTrapTestCase):
00010 def test_exception_in_callback(self):
00011 self.io_loop.add_callback(lambda: 1 / 0)
00012 try:
00013 self.wait()
00014 self.fail("did not get expected exception")
00015 except ZeroDivisionError:
00016 pass
00017
00018 def test_subsequent_wait_calls(self):
00019 """
00020 This test makes sure that a second call to wait()
00021 clears the first timeout.
00022 """
00023 self.io_loop.add_timeout(time.time() + 0.01, self.stop)
00024 self.wait(timeout=0.02)
00025 self.io_loop.add_timeout(time.time() + 0.03, self.stop)
00026 self.wait(timeout=0.1)
00027
00028
00029 class SetUpTearDownTest(unittest.TestCase):
00030 def test_set_up_tear_down(self):
00031 """
00032 This test makes sure that AsyncTestCase calls super methods for
00033 setUp and tearDown.
00034
00035 InheritBoth is a subclass of both AsyncTestCase and
00036 SetUpTearDown, with the ordering so that the super of
00037 AsyncTestCase will be SetUpTearDown.
00038 """
00039 events = []
00040 result = unittest.TestResult()
00041
00042 class SetUpTearDown(unittest.TestCase):
00043 def setUp(self):
00044 events.append('setUp')
00045
00046 def tearDown(self):
00047 events.append('tearDown')
00048
00049 class InheritBoth(AsyncTestCase, SetUpTearDown):
00050 def test(self):
00051 events.append('test')
00052
00053 InheritBoth('test').run(result)
00054 expected = ['setUp', 'test', 'tearDown']
00055 self.assertEqual(expected, events)
00056
00057 if __name__ == '__main__':
00058 unittest.main()