diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/output/test_httplib | 5 | ||||
-rw-r--r-- | Lib/test/test_httplib.py | 31 |
2 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/output/test_httplib b/Lib/test/output/test_httplib new file mode 100644 index 0000000..ed235c2 --- /dev/null +++ b/Lib/test/output/test_httplib @@ -0,0 +1,5 @@ +test_httplib +reply: 'HTTP/1.1 200 Ok\r\n' +Text +reply: 'HTTP/1.1 400.100 Not Ok\r\n' +BadStatusLine raised as expected diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py new file mode 100644 index 0000000..aef65a6 --- /dev/null +++ b/Lib/test/test_httplib.py @@ -0,0 +1,31 @@ +from test.test_support import verify,verbose +import httplib +import StringIO + +class FakeSocket: + def __init__(self, text): + self.text = text + + def makefile(self, mode, bufsize=None): + if mode != 'r' and mode != 'rb': + raise UnimplementedFileMode() + return StringIO.StringIO(self.text) + +# Test HTTP status lines + +body = "HTTP/1.1 200 Ok\r\n\r\nText" +sock = FakeSocket(body) +resp = httplib.HTTPResponse(sock,1) +resp.begin() +print resp.read() +resp.close() + +body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText" +sock = FakeSocket(body) +resp = httplib.HTTPResponse(sock,1) +try: + resp.begin() +except httplib.BadStatusLine: + print "BadStatusLine raised as expected" +else: + print "Expect BadStatusLine" |