From: Florimond Manca Date: Thu, 16 Jul 2020 14:28:31 +0000 (+0200) Subject: Use relative tests directory references (#1052) X-Git-Tag: 0.14.0~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09672a99dd49e95fcf8f7dda25f39c423bfa6163;p=thirdparty%2Fhttpx.git Use relative tests directory references (#1052) * Use relative tests directory references * Use absolute TESTS_DIR Co-authored-by: Tom Christie --- diff --git a/tests/client/test_auth.py b/tests/client/test_auth.py index 13184a06..29b6f20b 100644 --- a/tests/client/test_auth.py +++ b/tests/client/test_auth.py @@ -18,6 +18,8 @@ from httpx import ( ) from httpx._content_streams import ContentStream, JSONStream +from ..common import FIXTURES_DIR + def get_header_value(headers, key, default=None): lookup = key.encode("ascii").lower() @@ -233,7 +235,7 @@ async def test_custom_auth() -> None: @pytest.mark.asyncio async def test_netrc_auth() -> None: - os.environ["NETRC"] = "tests/.netrc" + os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc") url = "http://netrcexample.org" client = AsyncClient(transport=AsyncMockTransport()) @@ -247,7 +249,7 @@ async def test_netrc_auth() -> None: @pytest.mark.asyncio async def test_auth_header_has_priority_over_netrc() -> None: - os.environ["NETRC"] = "tests/.netrc" + os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc") url = "http://netrcexample.org" client = AsyncClient(transport=AsyncMockTransport()) @@ -259,7 +261,7 @@ async def test_auth_header_has_priority_over_netrc() -> None: @pytest.mark.asyncio async def test_trust_env_auth() -> None: - os.environ["NETRC"] = "tests/.netrc" + os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc") url = "http://netrcexample.org" client = AsyncClient(transport=AsyncMockTransport(), trust_env=False) diff --git a/tests/common.py b/tests/common.py new file mode 100644 index 00000000..064c25a6 --- /dev/null +++ b/tests/common.py @@ -0,0 +1,4 @@ +import pathlib + +TESTS_DIR = pathlib.Path(__file__).parent +FIXTURES_DIR = TESTS_DIR / "fixtures" diff --git a/tests/.netrc b/tests/fixtures/.netrc similarity index 100% rename from tests/.netrc rename to tests/fixtures/.netrc diff --git a/tests/test_utils.py b/tests/test_utils.py index 334bff9a..70fc1d62 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -16,6 +16,8 @@ from httpx._utils import ( ) from tests.utils import override_log_level +from .common import FIXTURES_DIR, TESTS_DIR + @pytest.mark.parametrize( "encoding", @@ -54,12 +56,12 @@ def test_guess_by_bom(encoding, expected): def test_bad_get_netrc_login(): - netrc_info = NetRCInfo(["tests/does-not-exist"]) + netrc_info = NetRCInfo([str(FIXTURES_DIR / "does-not-exist")]) assert netrc_info.get_credentials("netrcexample.org") is None def test_get_netrc_login(): - netrc_info = NetRCInfo(["tests/.netrc"]) + netrc_info = NetRCInfo([str(FIXTURES_DIR / ".netrc")]) expected_credentials = ( "example-username", "example-password", @@ -68,7 +70,7 @@ def test_get_netrc_login(): def test_get_netrc_unknown(): - netrc_info = NetRCInfo(["tests/.netrc"]) + netrc_info = NetRCInfo([str(FIXTURES_DIR / ".netrc")]) assert netrc_info.get_credentials("nonexistant.org") is None @@ -137,14 +139,16 @@ def test_get_ssl_cert_file(): # Two environments is not set. assert get_ca_bundle_from_env() is None - os.environ["SSL_CERT_DIR"] = "tests/" + os.environ["SSL_CERT_DIR"] = str(TESTS_DIR) # SSL_CERT_DIR is correctly set, SSL_CERT_FILE is not set. - assert get_ca_bundle_from_env() == "tests" + ca_bundle = get_ca_bundle_from_env() + assert ca_bundle is not None and ca_bundle.endswith("tests") del os.environ["SSL_CERT_DIR"] - os.environ["SSL_CERT_FILE"] = "tests/test_utils.py" + os.environ["SSL_CERT_FILE"] = str(TESTS_DIR / "test_utils.py") # SSL_CERT_FILE is correctly set, SSL_CERT_DIR is not set. - assert get_ca_bundle_from_env() == "tests/test_utils.py" + ca_bundle = get_ca_bundle_from_env() + assert ca_bundle is not None and ca_bundle.endswith("tests/test_utils.py") os.environ["SSL_CERT_FILE"] = "wrongfile" # SSL_CERT_FILE is set with wrong file, SSL_CERT_DIR is not set. @@ -155,14 +159,16 @@ def test_get_ssl_cert_file(): # SSL_CERT_DIR is set with wrong path, SSL_CERT_FILE is not set. assert get_ca_bundle_from_env() is None - os.environ["SSL_CERT_DIR"] = "tests/" - os.environ["SSL_CERT_FILE"] = "tests/test_utils.py" + os.environ["SSL_CERT_DIR"] = str(TESTS_DIR) + os.environ["SSL_CERT_FILE"] = str(TESTS_DIR / "test_utils.py") # Two environments is correctly set. - assert get_ca_bundle_from_env() == "tests/test_utils.py" + ca_bundle = get_ca_bundle_from_env() + assert ca_bundle is not None and ca_bundle.endswith("tests/test_utils.py") os.environ["SSL_CERT_FILE"] = "wrongfile" # Two environments is set but SSL_CERT_FILE is not a file. - assert get_ca_bundle_from_env() == "tests" + ca_bundle = get_ca_bundle_from_env() + assert ca_bundle is not None and ca_bundle.endswith("tests") os.environ["SSL_CERT_DIR"] = "wrongpath" # Two environments is set but both are not correct.