]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Add test for explicitly setting the encoding to use
authorTom Christie <tom@tomchristie.com>
Tue, 30 Apr 2019 15:37:10 +0000 (16:37 +0100)
committerTom Christie <tom@tomchristie.com>
Tue, 30 Apr 2019 15:37:10 +0000 (16:37 +0100)
tests/models/test_responses.py

index a1376ee101a7a2d9c264c43bceeab6fdaa8d2f9f..83de2671ff0cc0bed2059c73891cd88d713101fb 100644 (file)
@@ -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"