]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add test for SF bug #405427
authorJeremy Hylton <jeremy@alum.mit.edu>
Fri, 13 Apr 2001 14:57:44 +0000 (14:57 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Fri, 13 Apr 2001 14:57:44 +0000 (14:57 +0000)
Lib/test/output/test_httplib [new file with mode: 0644]
Lib/test/test_httplib.py [new file with mode: 0644]

diff --git a/Lib/test/output/test_httplib b/Lib/test/output/test_httplib
new file mode 100644 (file)
index 0000000..ed235c2
--- /dev/null
@@ -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 (file)
index 0000000..aef65a6
--- /dev/null
@@ -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"