test_utils.py
This file
Path
tests/test_utils.py
89 lines · 2.1 KiB · Python
Last changed by
Added links property to BaseResponse (#211)euri10before adoptioncad9c03
History of this fileTake it
added netrc support (#177)Can Sarıgölbefore adoption919e8d3
lines 1–2why, one step back1import os2Encoding detection in Response.json (#116)Yeray Diaz Diazbefore adoption5442006
lines 3–4why, one step back3import pytest4Added links property to BaseResponse (#211)euri10before adoptioncad9c03
line 5why, one step back5from httpx.utils import get_netrc_login, guess_json_utf, parse_header_linksEncoding detection in Response.json (#116)Yeray Diaz Diazbefore adoption5442006
lines 6–39why, one step back678@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):Use nox for automation and CI (#128)Seth Michael Larsonbefore adoption80dc3e2
line 40why, one step back40 data = "\ufeff{}".encode(encoding)Encoding detection in Response.json (#116)Yeray Diaz Diazbefore adoption5442006
line 41why, one step back41 assert guess_json_utf(data) == expectedadded netrc support (#177)Can Sarıgölbefore adoption919e8d3
lines 42–52why, one step back424344def 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 None52Fail unit tests without 100% coverage (#206)Can Sarıgölbefore adoption9536b76
lines 53–58why, one step back53 from httpx import utils5455 utils.NETRC_STATIC_FILES = ()56 os.environ["NETRC"] = ""57 assert utils.get_netrc_login("url") is None58added netrc support (#177)Can Sarıgölbefore adoption919e8d3
lines 59–66why, one step back5960def test_get_netrc_login():61 os.environ["NETRC"] = "tests/.netrc"62 assert get_netrc_login("netrcexample.org") == (63 "example-username",64 None,65 "example-password",66 )Added links property to BaseResponse (#211)euri10before adoptioncad9c03
lines 67–89why, one step back676869@pytest.mark.parametrize(70 "value, expected",71 (72 (73 '<http:/.../front.jpeg>; rel=front; type="image/jpeg"',74 [{"url": "http:/.../front.jpeg", "rel": "front", "type": "image/jpeg"}],75 ),76 ("<http:/.../front.jpeg>", [{"url": "http:/.../front.jpeg"}]),77 ("<http:/.../front.jpeg>;", [{"url": "http:/.../front.jpeg"}]),78 (79 '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;',80 [81 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},82 {"url": "http://.../back.jpeg"},83 ],84 ),85 ("", []),86 ),87)88def test_parse_header_links(value, expected):89 assert parse_header_links(value) == expected