diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-08-08 16:25:27 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-08-08 16:25:27 (GMT) |
commit | 37d3d9aa9692da71d2d66b90d60baa593456a880 (patch) | |
tree | fb1a14dbebba17ffd80e3218df08699a2d6979e8 /Lib | |
parent | e3f76168a96c939564e03064f4f9f43e96a3bacb (diff) | |
download | cpython-37d3d9aa9692da71d2d66b90d60baa593456a880.zip cpython-37d3d9aa9692da71d2d66b90d60baa593456a880.tar.gz cpython-37d3d9aa9692da71d2d66b90d60baa593456a880.tar.bz2 |
Add test case for the HTTPResponse being an iterable. Follow-up of issue #4608.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_urllib2_localnet.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index b478996..de8a521 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -308,8 +308,9 @@ def GetRequestHandler(responses): def do_GET(self): body = self.send_head() - if body: - self.wfile.write(body) + while body: + done = self.wfile.write(body) + body = body[done:] def do_POST(self): content_length = self.headers["Content-Length"] @@ -501,6 +502,25 @@ class TestUrlopen(BaseTestCase): urllib.request.urlopen, "http://sadflkjsasf.i.nvali.d./") + def test_iteration(self): + expected_response = b"pycon 2008..." + handler = self.start_server([(200, [], expected_response)]) + data = urllib.request.urlopen("http://localhost:%s" % handler.port) + for line in data: + self.assertEqual(line, expected_response) + + def test_line_iteration(self): + lines = [b"We\n", b"got\n", b"here\n", b"verylong " * 8192 + b"\n"] + expected_response = b"".join(lines) + handler = self.start_server([(200, [], expected_response)]) + data = urllib.request.urlopen("http://localhost:%s" % handler.port) + for index, line in enumerate(data): + self.assertEqual(line, lines[index], + "Fetched line number %s doesn't match expected:\n" + " Expected length was %s, got %s" % + (index, len(lines[index]), len(line))) + self.assertEqual(index + 1, len(lines)) + def test_main(): support.run_unittest(ProxyAuthTests, TestUrlopen) |