From 55e511dd10bc696fce683b4d507fb66d6ef09704 Mon Sep 17 00:00:00 2001 From: Michael Hunsinger Date: Thu, 15 Sep 2016 21:25:23 -0600 Subject: [PATCH] Parametrized decode response tests --- tests/test_requests.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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):