Skip to content
Myr

test_utils.py

This file

Path

tests/test_utils.py

66 lines · 1.4 KiB · Python

Last changed by

Fail unit tests without 100% coverage (#206)Can Sarıgölbefore adoption9536b76

History of this file

Take it

added netrc support (#177)Can Sarıgölbefore adoption919e8d3

lines 1–2why, one step back
1import os
2

Encoding detection in Response.json (#116)Yeray Diaz Diazbefore adoption5442006

lines 3–4why, one step back
3import pytest
4

added netrc support (#177)Can Sarıgölbefore adoption919e8d3

line 5why, one step back
5from httpx.utils import get_netrc_login, guess_json_utf

Encoding detection in Response.json (#116)Yeray Diaz Diazbefore adoption5442006

lines 6–39why, one step back
6
78@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 back
40 data = "\ufeff{}".encode(encoding)

Encoding detection in Response.json (#116)Yeray Diaz Diazbefore adoption5442006

line 41why, one step back
41 assert guess_json_utf(data) == expected

added netrc support (#177)Can Sarıgölbefore adoption919e8d3

lines 42–52why, one step back
42
4344def 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 None52

Fail unit tests without 100% coverage (#206)Can Sarıgölbefore adoption9536b76

lines 53–58why, one step back
53 from httpx import utils
5455 utils.NETRC_STATIC_FILES = ()56 os.environ["NETRC"] = ""57 assert utils.get_netrc_login("url") is None58

added netrc support (#177)Can Sarıgölbefore adoption919e8d3

lines 59–66why, one step back
59
60def 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 )