def __str__(self):
return "HTTP %d: %s" % (self.code, self.message)
+ # There is a cyclic reference between self and self.response,
+ # which breaks the default __repr__ implementation.
+ # (especially on pypy, which doesn't have the same recursion
+ # detection as cpython).
+ __repr__ = __str__
+
class _RequestProxy(object):
"""Combines an object with a dictionary of defaults.
self.assertIsNot(e, e2)
self.assertEqual(e.code, e2.code)
- def test_str(self):
+ def test_plain_error(self):
e = HTTPError(403)
self.assertEqual(str(e), "HTTP 403: Forbidden")
+ self.assertEqual(repr(e), "HTTP 403: Forbidden")
+
+ def test_error_with_response(self):
+ resp = HTTPResponse(HTTPRequest('http://example.com/'), 403)
+ with self.assertRaises(HTTPError) as cm:
+ resp.rethrow()
+ e = cm.exception
+ self.assertEqual(str(e), "HTTP 403: Forbidden")
+ self.assertEqual(repr(e), "HTTP 403: Forbidden")