mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Parametrized decode response tests
This commit is contained in:
+9
-10
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user