From: Akihiro Yamazaki Date: Thu, 27 Mar 2014 00:37:29 +0000 (+0900) Subject: put assertion outside of the exception handler X-Git-Tag: v4.0.0b1~98^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccbe5a2787c2721f2aa0b7f5f08f89183aef2415;p=thirdparty%2Ftornado.git put assertion outside of the exception handler --- diff --git a/tornado/test/concurrent_test.py b/tornado/test/concurrent_test.py index 5e93ad6a4..2506ef45e 100644 --- a/tornado/test/concurrent_test.py +++ b/tornado/test/concurrent_test.py @@ -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. diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index 7ffddbc35..984f5e0c5 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -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): diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index ff26bde1e..bd069c249 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -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 diff --git a/tornado/test/template_test.py b/tornado/test/template_test.py index f3a9e0590..c1b1e48ec 100644 --- a/tornado/test/template_test.py +++ b/tornado/test/template_test.py @@ -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): diff --git a/tornado/test/testing_test.py b/tornado/test/testing_test.py index aabdaced7..ef545e762 100644 --- a/tornado/test/testing_test.py +++ b/tornado/test/testing_test.py @@ -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 diff --git a/tornado/test/util_test.py b/tornado/test/util_test.py index 41ccbb9a5..fa965fbe1 100644 --- a/tornado/test/util_test.py +++ b/tornado/test/util_test.py @@ -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):