Skip to content

Commit 878ae88

Browse files
committed
Refactor tests' hard-coded *nix-style paths
Signed-off-by: Jack Leightcap <jack.leightcap@trailofbits.com>
1 parent a0b4f11 commit 878ae88

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

test/test_cache.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
import os
23

34
import pretend # type: ignore
45
from packaging.version import Version
@@ -9,15 +10,16 @@
910

1011
def test_get_cache_dir(monkeypatch):
1112
# When we supply a cache directory, always use that
12-
cache_dir = _get_cache_dir(Path("/tmp/foo/cache_dir"))
13-
assert str(cache_dir) == "/tmp/foo/cache_dir"
13+
cache_dir = _get_cache_dir(os.path.join("tmp", "foo", "cache_dir"))
14+
assert str(cache_dir) == os.path.join("tmp", "foo", "cache_dir")
1415

15-
get_pip_cache = pretend.call_recorder(lambda: "/fake/pip/cache/dir")
16+
get_pip_cache = pretend.call_recorder(
17+
lambda: os.path.join("fake", "pip", "cache", "dir"))
1618
monkeypatch.setattr(cache, "_get_pip_cache", get_pip_cache)
1719

1820
# When `pip cache dir` works, we use it. In this case, it's mocked.
1921
cache_dir = _get_cache_dir(None, use_pip=True)
20-
assert str(cache_dir) == "/fake/pip/cache/dir"
22+
assert str(cache_dir) == os.path.join("fake", "pip", "cache", "dir")
2123

2224

2325
def test_get_pip_cache():
@@ -36,16 +38,17 @@ def test_get_cache_dir_pip_disabled_in_environment(monkeypatch):
3638
monkeypatch.setenv("PIP_NO_CACHE_DIR", "1")
3739

3840
# Even with use_pip=True, we avoid pip's cache if the environment tells us to.
39-
assert _get_cache_dir(None, use_pip=True) == Path.home() / ".pip-audit-cache"
41+
assert _get_cache_dir(
42+
None, use_pip=True) == Path.home() / ".pip-audit-cache"
4043

4144

4245
def test_get_cache_dir_old_pip(monkeypatch):
4346
# Check the case where we have an old `pip`
4447
monkeypatch.setattr(cache, "_PIP_VERSION", Version("1.0.0"))
4548

4649
# When we supply a cache directory, always use that
47-
cache_dir = _get_cache_dir(Path("/tmp/foo/cache_dir"))
48-
assert str(cache_dir) == "/tmp/foo/cache_dir"
50+
cache_dir = _get_cache_dir(os.path.join("tmp", "foo", "cache_dir"))
51+
assert str(cache_dir) == os.path.join("tmp", "foo", "cache_dir")
4952

5053
# In this case, we can't query `pip` to figure out where its HTTP cache is
5154
# Instead, we use `~/.pip-audit-cache`

0 commit comments

Comments
 (0)