test_utils.py
This file
Path
tests/test_utils.py
39 lines · 799 bytes · Python
Last changed by
Encoding detection in Response.json (#116)Yeray Diaz Diazbefore adoption5442006
History of this fileTake it
1import pytest23from http3.utils import guess_json_utf456@pytest.mark.parametrize(7 "encoding",8 (9 "utf-32",10 "utf-8-sig",11 "utf-16",12 "utf-8",13 "utf-16-be",14 "utf-16-le",15 "utf-32-be",16 "utf-32-le",17 ),18)19def test_encoded(encoding):20 data = "{}".encode(encoding)21 assert guess_json_utf(data) == encoding222324def test_bad_utf_like_encoding():25 assert guess_json_utf(b"\x00\x00\x00\x00") is None262728@pytest.mark.parametrize(29 ("encoding", "expected"),30 (31 ("utf-16-be", "utf-16"),32 ("utf-16-le", "utf-16"),33 ("utf-32-be", "utf-32"),34 ("utf-32-le", "utf-32"),35 ),36)37def test_guess_by_bom(encoding, expected):38 data = u"\ufeff{}".encode(encoding)39 assert guess_json_utf(data) == expected