summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorianb <devnull@localhost>2007-08-11 19:19:43 +0000
committerianb <devnull@localhost>2007-08-11 19:19:43 +0000
commita4238b8445432a8727f5b8904fa9e79c30c29f7e (patch)
tree59d6f3d265c3720e0a7f73c09ce801bcc14cb683
parent5e227aa05325cc571cdfb601630e46cb1c2e3e3e (diff)
downloadwebtest-a4238b8445432a8727f5b8904fa9e79c30c29f7e.tar.gz
Added a more useful __repr__ to TestResponse
-rw-r--r--webtest/__init__.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/webtest/__init__.py b/webtest/__init__.py
index 35dfaac..756bd24 100644
--- a/webtest/__init__.py
+++ b/webtest/__init__.py
@@ -688,6 +688,25 @@ class TestResponse(Response):
'\n'.join(['%s: %s' % (n, v) for n, v in self.headerlist]),
simple_body)
+ def __repr__(self):
+ # Specifically intended for doctests
+ if self.content_type:
+ ct = ' %s' % self.content_type
+ else:
+ ct = ''
+ if self.body:
+ br = repr(self.body)
+ if len(br) > 18:
+ br = br[:10]+'...'+br[-5:]
+ body = ' body=%s/%s' % (br, len(self.body))
+ else:
+ body = ' no body'
+ if self.location:
+ location = ' location: %s' % self.location
+ else:
+ location = ''
+ return ('<' + self.status + ct + location + body + '>')
+
def showbrowser(self):
"""
Show this response in a browser window (for debugging purposes,