Merge lp:~vila/bzr/1184021 into lp:bzr

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6576
Proposed branch: lp:~vila/bzr/1184021
Merge into: lp:bzr
Diff against target: 68 lines (+19/-3)
2 files modified
bzrlib/tests/test_http_response.py (+11/-3)
bzrlib/transport/http/response.py (+8/-0)
To merge this branch: bzr merge lp:~vila/bzr/1184021
Reviewer Review Type Date Requested Status
Jelmer Vernooij Pending
bzr-core Pending
Review via email: mp+165720@code.launchpad.net

Commit message

Add __iter__ to http ResponseFile

Description of the change

Tests for jelmer's fix for bug #1184021, as straight forward than the fix so I'll just let jelmer approve and land ;)

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/tests/test_http_response.py'
--- bzrlib/tests/test_http_response.py 2012-08-04 11:16:14 +0000
+++ bzrlib/tests/test_http_response.py 2013-05-24 23:55:31 +0000
@@ -75,6 +75,17 @@
75 pass75 pass
7676
7777
78class TestResponseFileIter(tests.TestCase):
79
80 def test_iter_empty(self):
81 f = response.ResponseFile('empty', StringIO())
82 self.assertEqual([], list(f))
83
84 def test_iter_many(self):
85 f = response.ResponseFile('many', StringIO('0\n1\nboo!\n'))
86 self.assertEqual(['0\n', '1\n', 'boo!\n'], list(f))
87
88
78class TestHTTPConnection(tests.TestCase):89class TestHTTPConnection(tests.TestCase):
7990
80 def test_cleanup_pipe(self):91 def test_cleanup_pipe(self):
@@ -137,7 +148,6 @@
137148
138 def test_read_zero(self):149 def test_read_zero(self):
139 f = self._file150 f = self._file
140 start = self.first_range_start
141 self.assertEquals('', f.read(0))151 self.assertEquals('', f.read(0))
142 f.seek(10, 1)152 f.seek(10, 1)
143 self.assertEquals('', f.read(0))153 self.assertEquals('', f.read(0))
@@ -371,13 +381,11 @@
371381
372 def test_seek_across_ranges(self):382 def test_seek_across_ranges(self):
373 f = self._file383 f = self._file
374 start = self.first_range_start
375 f.seek(126) # skip the two first ranges384 f.seek(126) # skip the two first ranges
376 self.assertEquals('AB', f.read(2))385 self.assertEquals('AB', f.read(2))
377386
378 def test_checked_read_dont_overflow_buffers(self):387 def test_checked_read_dont_overflow_buffers(self):
379 f = self._file388 f = self._file
380 start = self.first_range_start
381 # We force a very low value to exercise all code paths in _checked_read389 # We force a very low value to exercise all code paths in _checked_read
382 f._discarded_buf_size = 8390 f._discarded_buf_size = 8
383 f.seek(126) # skip the two first ranges391 f.seek(126) # skip the two first ranges
384392
=== modified file 'bzrlib/transport/http/response.py'
--- bzrlib/transport/http/response.py 2012-04-06 11:38:05 +0000
+++ bzrlib/transport/http/response.py 2013-05-24 23:55:31 +0000
@@ -38,6 +38,7 @@
38 """A wrapper around the http socket containing the result of a GET request.38 """A wrapper around the http socket containing the result of a GET request.
3939
40 Only read() and seek() (forward) are supported.40 Only read() and seek() (forward) are supported.
41
41 """42 """
42 def __init__(self, path, infile):43 def __init__(self, path, infile):
43 """Constructor.44 """Constructor.
@@ -71,6 +72,13 @@
71 self._pos += len(data)72 self._pos += len(data)
72 return data73 return data
7374
75 def __iter__(self):
76 while True:
77 line = self.readline()
78 if not line:
79 return
80 yield line
81
74 def tell(self):82 def tell(self):
75 return self._pos83 return self._pos
7684