From: Jeremy Hylton Date: Fri, 13 Apr 2001 14:57:44 +0000 (+0000) Subject: Add test for SF bug #405427 X-Git-Tag: v2.1c1~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=79fa2b6073b67ae0351cad5b792f2be815e60c68;p=thirdparty%2FPython%2Fcpython.git Add test for SF bug #405427 --- diff --git a/Lib/test/output/test_httplib b/Lib/test/output/test_httplib new file mode 100644 index 000000000000..ed235c2ac62c --- /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 000000000000..aef65a68112e --- /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"