mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
added in type check for chunk_size
This commit is contained in:
@@ -685,6 +685,8 @@ class Response(object):
|
||||
|
||||
if self._content_consumed and isinstance(self._content, bool):
|
||||
raise StreamConsumedError()
|
||||
elif not isinstance(chunk_size, int):
|
||||
raise TypeError("chunk_size must be an int, it is instead a %s." % type(chunk_size))
|
||||
# simulate reading small chunks of the content
|
||||
reused_chunks = iter_slices(self._content, chunk_size)
|
||||
|
||||
|
||||
@@ -980,6 +980,20 @@ class TestRequests:
|
||||
chunks = r.iter_content(decode_unicode=True)
|
||||
assert all(isinstance(chunk, str) for chunk in chunks)
|
||||
|
||||
def test_response_chunk_size_int(self):
|
||||
"""Ensure that chunk_size is passed as an integer, otherwise
|
||||
raise a TypeError.
|
||||
"""
|
||||
r = requests.Response()
|
||||
r.raw = io.BytesIO(b'the content')
|
||||
chunks = r.iter_content(1)
|
||||
assert all(len(chunk) == 1 for chunk in chunks)
|
||||
|
||||
r = requests.Response()
|
||||
r.raw = io.BytesIO(b'the content')
|
||||
with pytest.raises(TypeError):
|
||||
chunks = r.iter_content("1024")
|
||||
|
||||
def test_request_and_response_are_pickleable(self, httpbin):
|
||||
r = requests.get(httpbin('get'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user