Skip to content

Commit

Permalink
Merge pull request tornadoweb#1023 from zakkie/feature/fix-testcase
Browse files Browse the repository at this point in the history
put assertion outside of the exception handler
  • Loading branch information
bdarnell committed Mar 31, 2014
2 parents 7508e21 + 32c7a32 commit c20ab35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 3 additions & 4 deletions tornado/test/httpclient_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,10 @@ def test_future_interface(self):

@gen_test
def test_future_http_error(self):
try:
with self.assertRaises(HTTPError) as context:
yield self.http_client.fetch(self.get_url('/notfound'))
except HTTPError as e:
self.assertEqual(e.code, 404)
self.assertEqual(e.response.code, 404)
self.assertEqual(context.exception.code, 404)
self.assertEqual(context.exception.response.code, 404)

@gen_test
def test_reuse_request_from_response(self):
Expand Down
7 changes: 7 additions & 0 deletions tornado/test/template_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def test_error_line_number_expression(self):
"""})
try:
loader.load("test.html").generate()
self.fail("did not get expected exception")
except ZeroDivisionError:
self.assertTrue("# test.html:2" in traceback.format_exc())

Expand All @@ -192,6 +193,7 @@ def test_error_line_number_directive(self):
"""})
try:
loader.load("test.html").generate()
self.fail("did not get expected exception")
except ZeroDivisionError:
self.assertTrue("# test.html:2" in traceback.format_exc())

Expand All @@ -202,6 +204,7 @@ def test_error_line_number_module(self):
}, namespace={"_tt_modules": ObjectDict({"Template": lambda path, **kwargs: loader.load(path).generate(**kwargs)})})
try:
loader.load("base.html").generate()
self.fail("did not get expected exception")
except ZeroDivisionError:
exc_stack = traceback.format_exc()
self.assertTrue('# base.html:1' in exc_stack)
Expand All @@ -214,6 +217,7 @@ def test_error_line_number_include(self):
})
try:
loader.load("base.html").generate()
self.fail("did not get expected exception")
except ZeroDivisionError:
self.assertTrue("# sub.html:1 (via base.html:1)" in
traceback.format_exc())
Expand All @@ -225,6 +229,7 @@ def test_error_line_number_extends_base_error(self):
})
try:
loader.load("sub.html").generate()
self.fail("did not get expected exception")
except ZeroDivisionError:
exc_stack = traceback.format_exc()
self.assertTrue("# base.html:1" in exc_stack)
Expand All @@ -240,6 +245,7 @@ def test_error_line_number_extends_sub_error(self):
"""})
try:
loader.load("sub.html").generate()
self.fail("did not get expected exception")
except ZeroDivisionError:
self.assertTrue("# sub.html:4 (via base.html:1)" in
traceback.format_exc())
Expand All @@ -252,6 +258,7 @@ def test_multi_includes(self):
})
try:
loader.load("a.html").generate()
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())
Expand Down

0 comments on commit c20ab35

Please sign in to comment.