Skip to content
Myr

Fix JSON wrong encoding tests on big endian platforms (#1781)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Michał Górny · committed by GitHub · parent 8c64e0c · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • tests:+2 added−2 removed

1 file+2 added−2 removed

modified:tests/models/test_responses.py+2 added-2 removed
733 unmodified lines
734 data = {"greeting": "hello", "recipient": "world"}735 content = json.dumps(data).encode("utf-32-be")736 headers = {"Content-Type": "application/json"}737 # force incorrect guess from `guess_json_utf` to trigger error738 with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):738 with mock.patch("httpx._models.guess_json_utf", return_value="utf-32-le"):739 response = httpx.Response(740 200,741 content=content,742 headers=headers,
6 unmodified lines
749 data = {"greeting": "hello", "recipient": "world"}750 content = json.dumps(data).encode("utf-32-be")751 headers = {"Content-Type": "application/json"}752 # force incorrect guess from `guess_json_utf` to trigger error753 with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):753 with mock.patch("httpx._models.guess_json_utf", return_value="utf-32-le"):754 response = httpx.Response(200, content=content, headers=headers)755 with pytest.raises(json.decoder.JSONDecodeError):756 response.json()757
134 unmodified lines