def test_raise_http_errors(self):
# HTTPDefaultErrorHandler should raise HTTPError if no error handler
# handled the error response
from mechanize import _response
h = mechanize.HTTPDefaultErrorHandler()
url = "http://example.com"
code = 500
msg = "Error"
request = mechanize.Request(url)
response = _response.test_response(url=url, code=code, msg=msg)
# case 1. it's not an HTTPError
try:
h.http_error_default(request, response, code, msg, response.info())
except mechanize.HTTPError as exc:
self.assert_(exc is not response)
self.assert_(exc.fp is response)
else:
self.assert_(False)
# case 2. response object is already an HTTPError, so just re-raise it
error = mechanize.HTTPError(url, code, msg, "fake headers", response)
try:
h.http_error_default(request, error, code, msg, error.info())
except mechanize.HTTPError as exc:
self.assert_(exc is error)
else:
self.assert_(False)
评论列表
文章目录