adding in slice_length fix and test for chunk_size=None (#3370)

This commit is contained in:
Nate Prewitt
2016-07-02 14:56:20 -06:00
committed by Ian Cordasco
parent bd9e8f2271
commit 71050e9ab9
2 changed files with 10 additions and 2 deletions
+2
View File
@@ -384,6 +384,8 @@ def stream_decode_response_unicode(iterator, r):
def iter_slices(string, slice_length):
"""Iterate over slices of a string."""
pos = 0
if slice_length is None or slice_length <= 0:
slice_length = len(string)
while pos < len(string):
yield string[pos:pos + slice_length]
pos += slice_length
+8 -2
View File
@@ -378,10 +378,16 @@ def test_get_encoding_from_headers(value, expected):
('', 0),
('T', 1),
('Test', 4),
('Cont', 0),
('Other', -5),
('Content', None),
))
def test_iter_slices(value, length):
assert len(list(iter_slices(value, 1))) == length
if length is None or (length <= 0 and len(value) > 0):
# Reads all content at once
assert len(list(iter_slices(value, length))) == 1
else:
assert len(list(iter_slices(value, 1))) == length
@pytest.mark.parametrize(
'value, expected', (