test_utils.py
This file
Path
tests/test_utils.py
60 lines · 1.2 KiB · Python
Last changed by
added netrc support (#177)Can Sarıgölbefore adoption919e8d3
History of this fileTake it
1import os23import pytest45from httpx.utils import get_netrc_login, guess_json_utf678@pytest.mark.parametrize(9 "encoding",10 (11 "utf-32",12 "utf-8-sig",13 "utf-16",14 "utf-8",15 "utf-16-be",16 "utf-16-le",17 "utf-32-be",18 "utf-32-le",19 ),20)21def test_encoded(encoding):22 data = "{}".encode(encoding)23 assert guess_json_utf(data) == encoding242526def test_bad_utf_like_encoding():27 assert guess_json_utf(b"\x00\x00\x00\x00") is None282930@pytest.mark.parametrize(31 ("encoding", "expected"),32 (33 ("utf-16-be", "utf-16"),34 ("utf-16-le", "utf-16"),35 ("utf-32-be", "utf-32"),36 ("utf-32-le", "utf-32"),37 ),38)39def test_guess_by_bom(encoding, expected):40 data = u"\ufeff{}".encode(encoding)41 assert guess_json_utf(data) == expected424344def test_bad_get_netrc_login():45 assert get_netrc_login("url") is None4647 os.environ["NETRC"] = "tests/.netrc"48 assert get_netrc_login("url") is None4950 os.environ["NETRC"] = "wrongpath"51 assert get_netrc_login("url") is None525354def test_get_netrc_login():55 os.environ["NETRC"] = "tests/.netrc"56 assert get_netrc_login("netrcexample.org") == (57 "example-username",58 None,59 "example-password",60 )