test case added, indent fixed

This commit is contained in:
Benny 2017-05-08 23:53:41 +08:00
parent 3f0e662358
commit 1a2a0931ed
2 changed files with 22 additions and 4 deletions

View File

@ -43,11 +43,24 @@ def handler_6(request, arg):
raise e from ValueError("{}".format(arg)) raise e from ValueError("{}".format(arg))
return text(foo) return text(foo)
@exception_handler_app.route('/7')
def handler_7(request):
# raise an IndexError
a = [1,2,3]
return text( a[3] )
@exception_handler_app.exception(NotFound, ServerError) @exception_handler_app.exception(NotFound, ServerError)
def handler_exception(request, exception): def handler_exception(request, exception):
return text("OK") return text("OK")
@exception_handler_app.exception(NotFound, ServerError)
def handler_exception(request, exception):
return text("OK")
@exception_handler_app.exception_base( LookupError )
def handler_exception(request, exception):
# LookupError can catch IndexError
return text("Caught by LookupError")
def test_invalid_usage_exception_handler(): def test_invalid_usage_exception_handler():
request, response = exception_handler_app.test_client.get('/1') request, response = exception_handler_app.test_client.get('/1')
@ -112,6 +125,11 @@ def test_chained_exception_handler():
"ZeroDivisionError: division by zero " "ZeroDivisionError: division by zero "
"while handling path /6/0") == summary_text "while handling path /6/0") == summary_text
def test_chained_exception_base_handler():
request, response = exception_handler_app.test_client.get(
'/7', debug=True)
assert response.status == 200
assert response.body == b'Caught by LookupError'
def test_exception_handler_lookup(): def test_exception_handler_lookup():
class CustomError(Exception): class CustomError(Exception):