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

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 = "\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 None5253    from httpx import utils5455    utils.NETRC_STATIC_FILES = ()56    os.environ["NETRC"] = ""57    assert utils.get_netrc_login("url") is None585960def 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    )