Skip to content
Myr

added in type check for chunk_size

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by Nate Prewitt · parent 1f681d8 · Browse files · 2 files+16 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−0 removed

  • tests:+14 added−0 removed
  • other:+2 added−0 removed

2 files+16 added−0 removed

modified:requests/models.py+2 added
683 unmodified lines
684 self._content_consumed = True685686 if self._content_consumed and isinstance(self._content, bool):687 raise StreamConsumedError()688 elif not isinstance(chunk_size, int):689 raise TypeError("chunk_size must be an int, it is instead a %s." % type(chunk_size))690 # simulate reading small chunks of the content691 reused_chunks = iter_slices(self._content, chunk_size)692693 stream_chunks = generate()
168 unmodified lines
modified:tests/test_requests.py+14 added
978 unmodified lines
979 r.encoding = 'ascii'980 chunks = r.iter_content(decode_unicode=True)981 assert all(isinstance(chunk, str) for chunk in chunks)982983 def test_response_chunk_size_int(self):984 """Ensure that chunk_size is passed as an integer, otherwise985 raise a TypeError.986 """987 r = requests.Response()988 r.raw = io.BytesIO(b'the content')989 chunks = r.iter_content(1)990 assert all(len(chunk) == 1 for chunk in chunks)991992 r = requests.Response()993 r.raw = io.BytesIO(b'the content')994 with pytest.raises(TypeError):995 chunks = r.iter_content("1024")996997 def test_request_and_response_are_pickleable(self, httpbin):998 r = requests.get(httpbin('get'))9991000 # verify we can pickle the original request
711 unmodified lines