def test_errors(self):
h = HTTPErrorProcessor()
o = h.parent = MockOpener()
req = Request("http://example.com")
# all 2xx are passed through
r = mechanize._response.test_response()
newr = h.http_response(req, r)
self.assertTrue(r is newr)
self.assertTrue(not hasattr(o, "proto")) # o.error not called
r = mechanize._response.test_response(code=202, msg="Accepted")
newr = h.http_response(req, r)
self.assertTrue(r is newr)
self.assertTrue(not hasattr(o, "proto")) # o.error not called
r = mechanize._response.test_response(code=206, msg="Partial content")
newr = h.http_response(req, r)
self.assertTrue(r is newr)
self.assertTrue(not hasattr(o, "proto")) # o.error not called
# anything else calls o.error (and MockOpener returns None, here)
r = mechanize._response.test_response(code=502, msg="Bad gateway")
self.assertTrue(h.http_response(req, r) is None)
self.assertEqual(o.proto, "http") # o.error called
self.assertEqual(o.args, (req, r, 502, "Bad gateway", AlwaysEqual()))
评论列表
文章目录