From: Tom Christie Date: Tue, 30 Apr 2019 15:37:10 +0000 (+0100) Subject: Add test for explicitly setting the encoding to use X-Git-Tag: 0.3.0~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd9823e59c7f7ca322aa035b8f59717935e3f103;p=thirdparty%2Fhttpx.git Add test for explicitly setting the encoding to use --- diff --git a/tests/models/test_responses.py b/tests/models/test_responses.py index a1376ee1..83de2671 100644 --- a/tests/models/test_responses.py +++ b/tests/models/test_responses.py @@ -36,6 +36,16 @@ def test_response_default_encoding(): assert response.encoding == "utf-8" +def test_response_set_explicit_encoding(): + headers = {"Content-Type": "text-plain; charset=utf-8"} # Deliberately incorrect charset + response = httpcore.Response( + 200, content="Latin 1: ÿ".encode("latin-1"), headers=headers + ) + response.encoding = 'latin-1' + assert response.text == "Latin 1: ÿ" + assert response.encoding == "latin-1" + + def test_response_force_encoding(): response = httpcore.Response(200, content="Snowman: ☃".encode("utf-8")) response.encoding = "iso-8859-1"