]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Fix JSON wrong encoding tests on big endian platforms (#1781)
authorMichał Górny <mgorny@gentoo.org>
Thu, 5 Aug 2021 16:05:38 +0000 (18:05 +0200)
committerGitHub <noreply@github.com>
Thu, 5 Aug 2021 16:05:38 +0000 (17:05 +0100)
Fix test_json_without_specified_encoding_*_error tests on big endian
platforms.  The tests wrongly assume that data encoded as "utf-32-be"
can not be decoded as "utf-32".  This is true on little endian platforms
but on big endian platforms "utf-32" is equivalent to "utf-32-be".
To avoid the problem, explicitly decode as "utf-32-le", as this should
trigger the expected exception independently of platform's endianness.

tests/models/test_responses.py

index f1815dcad525a31a1cad20935623ad73ca92a39c..b7c2d57cd3d8c341ef69366ef696b4f146faf3b3 100644 (file)
@@ -735,7 +735,7 @@ def test_json_without_specified_encoding_decode_error():
     content = json.dumps(data).encode("utf-32-be")
     headers = {"Content-Type": "application/json"}
     # force incorrect guess from `guess_json_utf` to trigger error
-    with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):
+    with mock.patch("httpx._models.guess_json_utf", return_value="utf-32-le"):
         response = httpx.Response(
             200,
             content=content,
@@ -750,7 +750,7 @@ def test_json_without_specified_encoding_value_error():
     content = json.dumps(data).encode("utf-32-be")
     headers = {"Content-Type": "application/json"}
     # force incorrect guess from `guess_json_utf` to trigger error
-    with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):
+    with mock.patch("httpx._models.guess_json_utf", return_value="utf-32-le"):
         response = httpx.Response(200, content=content, headers=headers)
         with pytest.raises(json.decoder.JSONDecodeError):
             response.json()