Use relative tests directory references (#1052)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Use relative tests directory references * Use absolute TESTS_DIR
authored by Florimond Manca · committed by GitHub · parent ff93a01 · Browse files · 5 files·+29 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Tom Christie <tom@tomchristie.com>
Diff stats
5 files+29 added−17 removed
- tests:+29 added−17 removed
Provenance
- Commit
09672a9- Tree
50bab28- Author
Florimond Manca <florimond.manca@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
ff93a01
5 files changed+29 added−17 removed
modified:tests/client/test_auth.py+5 added-3 removed
16 unmodified lines17 Response,18 )19 from httpx._content_streams import ContentStream, JSONStream20 21+from ..common import FIXTURES_DIR22 23+24 def get_header_value(headers, key, default=None):25 lookup = key.encode("ascii").lower()26 for header_key, header_value in headers:27 if header_key.lower() == lookup:206 unmodified lines234 235 236 @pytest.mark.asyncio237 async def test_netrc_auth() -> None:236- os.environ["NETRC"] = "tests/.netrc"238+ os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")239 url = "http://netrcexample.org"240 241 client = AsyncClient(transport=AsyncMockTransport())242 response = await client.get(url)5 unmodified lines248 249 250 @pytest.mark.asyncio251 async def test_auth_header_has_priority_over_netrc() -> None:250- os.environ["NETRC"] = "tests/.netrc"252+ os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")253 url = "http://netrcexample.org"254 255 client = AsyncClient(transport=AsyncMockTransport())256 response = await client.get(url, headers={"Authorization": "Override"})3 unmodified lines260 261 262 @pytest.mark.asyncio263 async def test_trust_env_auth() -> None:262- os.environ["NETRC"] = "tests/.netrc"264+ os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")265 url = "http://netrcexample.org"266 267 client = AsyncClient(transport=AsyncMockTransport(), trust_env=False)268 response = await client.get(url)342 unmodified linesadded:tests/fixtures/.netrc+3 added
1+machine netrcexample.org2+login example-username3+password example-passworddeleted:tests/.netrc-3 removed
1-machine netrcexample.org2-login example-username3-password example-passwordadded:tests/common.py+4 added
1+import pathlib2+3+TESTS_DIR = pathlib.Path(__file__).parent4+FIXTURES_DIR = TESTS_DIR / "fixtures"modified:tests/test_utils.py+17 added-11 removed
14 unmodified lines15 should_not_be_proxied,16 )17 from tests.utils import override_log_level18 19+from .common import FIXTURES_DIR, TESTS_DIR20 21+22 @pytest.mark.parametrize(23 "encoding",24 (25 "utf-32",29 unmodified lines55 assert guess_json_utf(data) == expected56 57 58 def test_bad_get_netrc_login():57- netrc_info = NetRCInfo(["tests/does-not-exist"])59+ netrc_info = NetRCInfo([str(FIXTURES_DIR / "does-not-exist")])60 assert netrc_info.get_credentials("netrcexample.org") is None61 62 63 def test_get_netrc_login():62- netrc_info = NetRCInfo(["tests/.netrc"])64+ netrc_info = NetRCInfo([str(FIXTURES_DIR / ".netrc")])65 expected_credentials = (66 "example-username",67 "example-password",68 )69 assert netrc_info.get_credentials("netrcexample.org") == expected_credentials70 71 72 def test_get_netrc_unknown():71- netrc_info = NetRCInfo(["tests/.netrc"])73+ netrc_info = NetRCInfo([str(FIXTURES_DIR / ".netrc")])74 assert netrc_info.get_credentials("nonexistant.org") is None75 76 77 @pytest.mark.parametrize(60 unmodified lines138 def test_get_ssl_cert_file():139 # Two environments is not set.140 assert get_ca_bundle_from_env() is None141 140- os.environ["SSL_CERT_DIR"] = "tests/"142+ os.environ["SSL_CERT_DIR"] = str(TESTS_DIR)143 # SSL_CERT_DIR is correctly set, SSL_CERT_FILE is not set.142- assert get_ca_bundle_from_env() == "tests"144+ ca_bundle = get_ca_bundle_from_env()145+ assert ca_bundle is not None and ca_bundle.endswith("tests")146 147 del os.environ["SSL_CERT_DIR"]145- os.environ["SSL_CERT_FILE"] = "tests/test_utils.py"148+ os.environ["SSL_CERT_FILE"] = str(TESTS_DIR / "test_utils.py")149 # SSL_CERT_FILE is correctly set, SSL_CERT_DIR is not set.147- assert get_ca_bundle_from_env() == "tests/test_utils.py"150+ ca_bundle = get_ca_bundle_from_env()151+ assert ca_bundle is not None and ca_bundle.endswith("tests/test_utils.py")152 153 os.environ["SSL_CERT_FILE"] = "wrongfile"154 # SSL_CERT_FILE is set with wrong file, SSL_CERT_DIR is not set.155 assert get_ca_bundle_from_env() is None2 unmodified lines158 os.environ["SSL_CERT_DIR"] = "wrongpath"159 # SSL_CERT_DIR is set with wrong path, SSL_CERT_FILE is not set.160 assert get_ca_bundle_from_env() is None161 158- os.environ["SSL_CERT_DIR"] = "tests/"159- os.environ["SSL_CERT_FILE"] = "tests/test_utils.py"162+ os.environ["SSL_CERT_DIR"] = str(TESTS_DIR)163+ os.environ["SSL_CERT_FILE"] = str(TESTS_DIR / "test_utils.py")164 # Two environments is correctly set.161- assert get_ca_bundle_from_env() == "tests/test_utils.py"165+ ca_bundle = get_ca_bundle_from_env()166+ assert ca_bundle is not None and ca_bundle.endswith("tests/test_utils.py")167 168 os.environ["SSL_CERT_FILE"] = "wrongfile"169 # Two environments is set but SSL_CERT_FILE is not a file.165- assert get_ca_bundle_from_env() == "tests"170+ ca_bundle = get_ca_bundle_from_env()171+ assert ca_bundle is not None and ca_bundle.endswith("tests")172 173 os.environ["SSL_CERT_DIR"] = "wrongpath"174 # Two environments is set but both are not correct.175 assert get_ca_bundle_from_env() is None121 unmodified lines