diff --git a/tests/test_requests.py b/tests/test_requests.py index a458bf9d..cc621a20 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1039,23 +1039,22 @@ class TestRequests: r = requests.Response() r.raw = io.BytesIO(b'the content') r.encoding = 'ascii' + chunks = r.iter_content(decode_unicode=True) assert all(isinstance(chunk, str) for chunk in chunks) + @pytest.mark.parametrize( + 'encoding, exception', ( + (None, TypeError), + ('invalid encoding', LookupError), + )) + def test_decode_unicode_encoding(self, encoding, exception): # raise an exception if encoding isn't set r = requests.Response() r.raw = io.BytesIO(b'the content') - r.encoding = None + r.encoding = encoding - with pytest.raises(TypeError): - chunks = r.iter_content(decode_unicode=True) - - # raises an exception if the encoding is garbage - r = requests.Response() - r.raw = io.BytesIO(b'the content') - r.encoding = 'invalid encoding' - - with pytest.raises(LookupError): + with pytest.raises(exception): chunks = r.iter_content(decode_unicode=True) def test_response_reason_unicode(self):