From 878ae88a816705a50d29369b7b9dd5098c6f990d Mon Sep 17 00:00:00 2001 From: Jack Leightcap Date: Mon, 1 May 2023 11:09:07 -0400 Subject: [PATCH] Refactor tests' hard-coded *nix-style paths Signed-off-by: Jack Leightcap --- test/test_cache.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/test_cache.py b/test/test_cache.py index d6c80190..9635c2fa 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -1,4 +1,5 @@ from pathlib import Path +import os import pretend # type: ignore from packaging.version import Version @@ -9,15 +10,16 @@ def test_get_cache_dir(monkeypatch): # When we supply a cache directory, always use that - cache_dir = _get_cache_dir(Path("/tmp/foo/cache_dir")) - assert str(cache_dir) == "/tmp/foo/cache_dir" + cache_dir = _get_cache_dir(os.path.join("tmp", "foo", "cache_dir")) + assert str(cache_dir) == os.path.join("tmp", "foo", "cache_dir") - get_pip_cache = pretend.call_recorder(lambda: "/fake/pip/cache/dir") + get_pip_cache = pretend.call_recorder( + lambda: os.path.join("fake", "pip", "cache", "dir")) monkeypatch.setattr(cache, "_get_pip_cache", get_pip_cache) # When `pip cache dir` works, we use it. In this case, it's mocked. cache_dir = _get_cache_dir(None, use_pip=True) - assert str(cache_dir) == "/fake/pip/cache/dir" + assert str(cache_dir) == os.path.join("fake", "pip", "cache", "dir") def test_get_pip_cache(): @@ -36,7 +38,8 @@ def test_get_cache_dir_pip_disabled_in_environment(monkeypatch): monkeypatch.setenv("PIP_NO_CACHE_DIR", "1") # Even with use_pip=True, we avoid pip's cache if the environment tells us to. - assert _get_cache_dir(None, use_pip=True) == Path.home() / ".pip-audit-cache" + assert _get_cache_dir( + None, use_pip=True) == Path.home() / ".pip-audit-cache" def test_get_cache_dir_old_pip(monkeypatch): @@ -44,8 +47,8 @@ def test_get_cache_dir_old_pip(monkeypatch): monkeypatch.setattr(cache, "_PIP_VERSION", Version("1.0.0")) # When we supply a cache directory, always use that - cache_dir = _get_cache_dir(Path("/tmp/foo/cache_dir")) - assert str(cache_dir) == "/tmp/foo/cache_dir" + cache_dir = _get_cache_dir(os.path.join("tmp", "foo", "cache_dir")) + assert str(cache_dir) == os.path.join("tmp", "foo", "cache_dir") # In this case, we can't query `pip` to figure out where its HTTP cache is # Instead, we use `~/.pip-audit-cache`