]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
put assertion outside of the exception handler
authorAkihiro Yamazaki <yamazaki@iij.ad.jp>
Thu, 27 Mar 2014 00:37:29 +0000 (09:37 +0900)
committerAkihiro Yamazaki <yamazaki@iij.ad.jp>
Thu, 27 Mar 2014 00:37:29 +0000 (09:37 +0900)
tornado/test/concurrent_test.py
tornado/test/httpclient_test.py
tornado/test/ioloop_test.py
tornado/test/template_test.py
tornado/test/testing_test.py
tornado/test/util_test.py

index 5e93ad6a42ba5fd55a9f100a3fbd448085088e89..2506ef45e05a782ca48c7f807605a50d09d8789f 100644 (file)
@@ -168,7 +168,7 @@ class ReturnFutureTest(AsyncTestCase):
             self.fail("didn't get expected exception")
         except ZeroDivisionError:
             tb = traceback.extract_tb(sys.exc_info()[2])
-            self.assertIn(self.expected_frame, tb)
+        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 7ffddbc3597a19874b5ee40eac48e616ed9f0eb7..984f5e0c579ce2745ffc4045ce8fcc8350dcbdbe 100644 (file)
@@ -359,8 +359,9 @@ Transfer-Encoding: chunked
         try:
             yield self.http_client.fetch(self.get_url('/notfound'))
         except HTTPError as e:
-            self.assertEqual(e.code, 404)
-            self.assertEqual(e.response.code, 404)
+            got_exception = e
+        self.assertEqual(got_exception.code, 404)
+        self.assertEqual(got_exception.response.code, 404)
 
     @gen_test
     def test_reuse_request_from_response(self):
index ff26bde1e11699232166078c64c703d83418664b..bd069c2497878b91acaf569851dba2bf4b9ac61d 100644 (file)
@@ -116,8 +116,9 @@ class TestIOLoop(AsyncTestCase):
             try:
                 other_ioloop.add_callback(lambda: None)
             except RuntimeError as e:
-                self.assertEqual("IOLoop is closing", str(e))
+                got_exception = e
                 break
+        self.assertEqual("IOLoop is closing", str(got_exception))
 
     def test_handle_callback_exception(self):
         # IOLoop.handle_callback_exception can be overridden to catch
index f3a9e059076392d63bbe3b901ef799d8f7dc0f03..c1b1e48eca3d21574d192f375fe07a850db6fc44 100644 (file)
@@ -183,7 +183,8 @@ three
         try:
             loader.load("test.html").generate()
         except ZeroDivisionError:
-            self.assertTrue("# test.html:2" in traceback.format_exc())
+            exc_stack = traceback.format_exc()
+        self.assertTrue("# test.html:2" in exc_stack)
 
     def test_error_line_number_directive(self):
         loader = DictLoader({"test.html": """one
@@ -193,7 +194,8 @@ three{%end%}
         try:
             loader.load("test.html").generate()
         except ZeroDivisionError:
-            self.assertTrue("# test.html:2" in traceback.format_exc())
+            exc_stack = traceback.format_exc()
+        self.assertTrue("# test.html:2" in exc_stack)
 
     def test_error_line_number_module(self):
         loader = DictLoader({
@@ -204,8 +206,8 @@ three{%end%}
             loader.load("base.html").generate()
         except ZeroDivisionError:
             exc_stack = traceback.format_exc()
-            self.assertTrue('# base.html:1' in exc_stack)
-            self.assertTrue('# sub.html:1' in exc_stack)
+        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({
@@ -215,8 +217,8 @@ three{%end%}
         try:
             loader.load("base.html").generate()
         except ZeroDivisionError:
-            self.assertTrue("# sub.html:1 (via base.html:1)" in
-                            traceback.format_exc())
+            exc_stack = traceback.format_exc()
+        self.assertTrue("# sub.html:1 (via base.html:1)" in exc_stack)
 
     def test_error_line_number_extends_base_error(self):
         loader = DictLoader({
@@ -241,8 +243,8 @@ three{%end%}
         try:
             loader.load("sub.html").generate()
         except ZeroDivisionError:
-            self.assertTrue("# sub.html:4 (via base.html:1)" in
-                            traceback.format_exc())
+            exc_stack = traceback.format_exc()
+        self.assertTrue("# sub.html:4 (via base.html:1)" in exc_stack)
 
     def test_multi_includes(self):
         loader = DictLoader({
@@ -253,8 +255,8 @@ three{%end%}
         try:
             loader.load("a.html").generate()
         except ZeroDivisionError:
-            self.assertTrue("# c.html:1 (via b.html:1, a.html:1)" in
-                            traceback.format_exc())
+            exc_stack = traceback.format_exc()
+        self.assertTrue("# c.html:1 (via b.html:1, a.html:1)" in exc_stack)
 
 
 class AutoEscapeTest(unittest.TestCase):
index aabdaced723179626825d1fdda21a482fca294a5..ef545e762a5e7c35cadc6980a5cb4d27d1253336 100644 (file)
@@ -155,11 +155,12 @@ class GenTest(AsyncTestCase):
             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())
+            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.finished = True
 
index 41ccbb9a584018294988bcdd09c26b583f0a2ea3..fa965fbe1079db0c43536b3cf71256647e05aac7 100644 (file)
@@ -30,7 +30,8 @@ class RaiseExcInfoTest(unittest.TestCase):
             raise_exc_info(exc_info)
             self.fail("didn't get expected exception")
         except TwoArgException as e:
-            self.assertIs(e, exc_info[1])
+            got_exception = e
+        self.assertIs(got_exception, exc_info[1])
 
 
 class TestConfigurable(Configurable):