From 7b378cb74266ccea308a83c5b0f7129cb4962567 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 4 Mar 2014 17:46:58 -0500 Subject: [PATCH] Add tests for decode_unicode --- test_requests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test_requests.py b/test_requests.py index 17de849..65eb571 100755 --- a/test_requests.py +++ b/test_requests.py @@ -9,6 +9,7 @@ import os import pickle import unittest +import io import requests import pytest from requests.adapters import HTTPAdapter @@ -690,6 +691,26 @@ class RequestsTestCase(unittest.TestCase): assert next(iter(r)) io.close() + def test_response_decode_unicode(self): + """ + When called with decode_unicode, Response.iter_content should always + return unicode. + """ + r = requests.Response() + r._content_consumed = True + r._content = b'the content' + r.encoding = 'ascii' + + chunks = r.iter_content(decode_unicode=True) + assert all(isinstance(chunk, str) for chunk in chunks) + + # also for streaming + 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) + def test_request_and_response_are_pickleable(self): r = requests.get(httpbin('get')) -- 2.34.1