From 79fa2b6073b67ae0351cad5b792f2be815e60c68 Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Fri, 13 Apr 2001 14:57:44 +0000 Subject: Add test for SF bug #405427 --- Lib/test/output/test_httplib | 5 +++++ Lib/test/test_httplib.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 Lib/test/output/test_httplib create mode 100644 Lib/test/test_httplib.py 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" -- cgit v0.12