]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
correct testcases 1023/head
authorAkihiro Yamazaki <yamazaki@iij.ad.jp>
Sun, 30 Mar 2014 14:15:46 +0000 (23:15 +0900)
committerAkihiro Yamazaki <yamazaki@iij.ad.jp>
Sun, 30 Mar 2014 14:15:46 +0000 (23:15 +0900)
tornado/test/concurrent_test.py
tornado/test/ioloop_test.py
tornado/test/template_test.py
tornado/test/testing_test.py
tornado/test/util_test.py

index edd70c9a7f275b93ec4589f490bf818d94da7067..5e93ad6a42ba5fd55a9f100a3fbd448085088e89 100644 (file)
@@ -163,10 +163,12 @@ class ReturnFutureTest(AsyncTestCase):
                 self.expected_frame = traceback.extract_tb(
                     sys.exc_info()[2], limit=1)[0]
                 raise
-        with self.assertRaises(ZeroDivisionError):
+        try:
             yield f()
-        tb = traceback.extract_tb(sys.exc_info()[2])
-        self.assertIn(self.expected_frame, tb)
+            self.fail("didn't get expected exception")
+        except ZeroDivisionError:
+            tb = traceback.extract_tb(sys.exc_info()[2])
+            self.assertIn(self.expected_frame, tb)
 
 # The following series of classes demonstrate and test various styles
 # of use, with and without generators and futures.
index b7d1f3a69b8a6b2886dc55d680444e424ca7beb3..ff26bde1e11699232166078c64c703d83418664b 100644 (file)
@@ -112,9 +112,12 @@ class TestIOLoop(AsyncTestCase):
         thread = threading.Thread(target=target)
         thread.start()
         closing.wait()
-        with self.assertRaisesRegexp(RuntimeError, "\AIOLoop is closing\Z"):
-            for i in range(1000):
+        for i in range(1000):
+            try:
                 other_ioloop.add_callback(lambda: None)
+            except RuntimeError as e:
+                self.assertEqual("IOLoop is closing", str(e))
+                break
 
     def test_handle_callback_exception(self):
         # IOLoop.handle_callback_exception can be overridden to catch
index 181008dc50b6dc947651eafb3d50e6d5b10a920c..32bbe42170680191f958f677ac8b13e9cf286226 100644 (file)
@@ -149,14 +149,20 @@ try{% set y = 1/x %}
         self.assertEqual(result, b"013456")
 
     def test_break_outside_loop(self):
-        with self.assertRaises(ParseError):
+        try:
             Template(utf8("{% break %}"))
+            raise Exception("Did not get expected exception")
+        except ParseError:
+            pass
 
     def test_break_in_apply(self):
         # This test verifies current behavior, although of course it would
         # be nice if apply didn't cause seemingly unrelated breakage
-        with self.assertRaises(ParseError):
+        try:
             Template(utf8("{% for i in [] %}{% apply foo %}{% break %}{% end %}{% end %}"))
+            raise Exception("Did not get expected exception")
+        except ParseError:
+            pass
 
     @unittest.skipIf(sys.version_info >= division.getMandatoryRelease(),
                      'no testable future imports')
@@ -174,50 +180,58 @@ class StackTraceTest(unittest.TestCase):
 two{{1/0}}
 three
         """})
-        with self.assertRaises(ZeroDivisionError):
+        try:
             loader.load("test.html").generate()
-        exc_stack = traceback.format_exc()
-        self.assertTrue("# test.html:2" in exc_stack)
+            self.fail("did not get expected exception")
+        except ZeroDivisionError:
+            self.assertTrue("# test.html:2" in traceback.format_exc())
 
     def test_error_line_number_directive(self):
         loader = DictLoader({"test.html": """one
 two{%if 1/0%}
 three{%end%}
         """})
-        with self.assertRaises(ZeroDivisionError):
+        try:
             loader.load("test.html").generate()
-        exc_stack = traceback.format_exc()
-        self.assertTrue("# test.html:2" in exc_stack)
+            self.fail("did not get expected exception")
+        except ZeroDivisionError:
+            self.assertTrue("# test.html:2" in traceback.format_exc())
 
     def test_error_line_number_module(self):
         loader = DictLoader({
             "base.html": "{% module Template('sub.html') %}",
             "sub.html": "{{1/0}}",
         }, namespace={"_tt_modules": ObjectDict({"Template": lambda path, **kwargs: loader.load(path).generate(**kwargs)})})
-        with self.assertRaises(ZeroDivisionError):
+        try:
             loader.load("base.html").generate()
-        exc_stack = traceback.format_exc()
-        self.assertTrue('# base.html:1' in exc_stack)
-        self.assertTrue('# sub.html:1' in exc_stack)
+            self.fail("did not get expected exception")
+        except ZeroDivisionError:
+            exc_stack = traceback.format_exc()
+            self.assertTrue('# base.html:1' in exc_stack)
+            self.assertTrue('# sub.html:1' in exc_stack)
 
     def test_error_line_number_include(self):
         loader = DictLoader({
             "base.html": "{% include 'sub.html' %}",
             "sub.html": "{{1/0}}",
         })
-        with self.assertRaises(ZeroDivisionError):
+        try:
             loader.load("base.html").generate()
-        exc_stack = traceback.format_exc()
-        self.assertTrue("# sub.html:1 (via base.html:1)" in exc_stack)
+            self.fail("did not get expected exception")
+        except ZeroDivisionError:
+            self.assertTrue("# sub.html:1 (via base.html:1)" in
+                            traceback.format_exc())
 
     def test_error_line_number_extends_base_error(self):
         loader = DictLoader({
             "base.html": "{{1/0}}",
             "sub.html": "{% extends 'base.html' %}",
         })
-        with self.assertRaises(ZeroDivisionError):
+        try:
             loader.load("sub.html").generate()
-        exc_stack = traceback.format_exc()
+            self.fail("did not get expected exception")
+        except ZeroDivisionError:
+            exc_stack = traceback.format_exc()
         self.assertTrue("# base.html:1" in exc_stack)
 
     def test_error_line_number_extends_sub_error(self):
@@ -229,10 +243,12 @@ three{%end%}
 {{1/0}}
 {% end %}
             """})
-        with self.assertRaises(ZeroDivisionError):
+        try:
             loader.load("sub.html").generate()
-        exc_stack = traceback.format_exc()
-        self.assertTrue("# sub.html:4 (via base.html:1)" in exc_stack)
+            self.fail("did not get expected exception")
+        except ZeroDivisionError:
+            self.assertTrue("# sub.html:4 (via base.html:1)" in
+                            traceback.format_exc())
 
     def test_multi_includes(self):
         loader = DictLoader({
@@ -240,10 +256,12 @@ three{%end%}
             "b.html": "{% include 'c.html' %}",
             "c.html": "{{1/0}}",
         })
-        with self.assertRaises(ZeroDivisionError):
+        try:
             loader.load("a.html").generate()
-        exc_stack = traceback.format_exc()
-        self.assertTrue("# c.html:1 (via b.html:1, a.html:1)" in exc_stack)
+            self.fail("did not get expected exception")
+        except ZeroDivisionError:
+            self.assertTrue("# c.html:1 (via b.html:1, a.html:1)" in
+                            traceback.format_exc())
 
 
 class AutoEscapeTest(unittest.TestCase):
index 92eb9a48d3bc80f34e2011248822b84c7ea61fb7..aabdaced723179626825d1fdda21a482fca294a5 100644 (file)
@@ -28,8 +28,11 @@ def set_environ(name, value):
 class AsyncTestCaseTest(AsyncTestCase):
     def test_exception_in_callback(self):
         self.io_loop.add_callback(lambda: 1 / 0)
-        with self.assertRaises(ZeroDivisionError):
+        try:
             self.wait()
+            self.fail("did not get expected exception")
+        except ZeroDivisionError:
+            pass
 
     def test_wait_timeout(self):
         time = self.io_loop.time
@@ -148,14 +151,15 @@ class GenTest(AsyncTestCase):
 
         # This can't use assertRaises because we need to inspect the
         # exc_info triple (and not just the exception object)
-        with self.assertRaises(ioloop.TimeoutError):
+        try:
             test(self)
-        exc_stack = traceback.format_exc()
-        # 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)",
-            exc_stack)
+            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
 
index fab94e7dc9023ccdcb3b6deef359db78841f7036..41ccbb9a584018294988bcdd09c26b583f0a2ea3 100644 (file)
@@ -26,9 +26,11 @@ class RaiseExcInfoTest(unittest.TestCase):
             raise TwoArgException(1, 2)
         except TwoArgException:
             exc_info = sys.exc_info()
-        with self.assertRaises(TwoArgException) as context:
+        try:
             raise_exc_info(exc_info)
-        self.assertIs(context.exception, exc_info[1])
+            self.fail("didn't get expected exception")
+        except TwoArgException as e:
+            self.assertIs(e, exc_info[1])
 
 
 class TestConfigurable(Configurable):