Merge "Close the iterators in string_along."

This commit is contained in:
Jenkins 2016-08-31 00:15:33 +00:00 committed by Gerrit Code Review
commit dd30b9ef98
2 changed files with 25 additions and 2 deletions

View File

@ -3821,6 +3821,7 @@ def document_iters_to_http_response_body(ranges_iter, boundary, multipart,
# so if that finally block fires before we read response_body_iter,
# there's nothing there.
def string_along(useful_iter, useless_iter_iter, logger):
with closing_if_possible(useful_iter):
for x in useful_iter:
yield x

View File

@ -5703,6 +5703,28 @@ class TestDocumentItersToHTTPResponseBody(unittest.TestCase):
part2 + "\r\n" +
"--boundaryboundary--"))
def test_closed_part_iterator(self):
print('test')
useful_iter_mock = mock.MagicMock()
useful_iter_mock.__iter__.return_value = ['']
body_iter = utils.document_iters_to_http_response_body(
iter([{'part_iter': useful_iter_mock}]), 'dontcare',
multipart=False, logger=FakeLogger())
body = ''
for s in body_iter:
body += s
self.assertEqual(body, '')
useful_iter_mock.close.assert_called_once_with()
# Calling "close" on the mock will now raise an AttributeError
del useful_iter_mock.close
body_iter = utils.document_iters_to_http_response_body(
iter([{'part_iter': useful_iter_mock}]), 'dontcare',
multipart=False, logger=FakeLogger())
body = ''
for s in body_iter:
body += s
class TestPairs(unittest.TestCase):
def test_pairs(self):