Skip to content

Commit

Permalink
Refactor tests' hard-coded *nix-style paths
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Leightcap <[email protected]>
  • Loading branch information
jleightcap committed May 1, 2023
1 parent a0b4f11 commit 878ae88
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions test/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
import os

import pretend # type: ignore
from packaging.version import Version
Expand All @@ -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():
Expand All @@ -36,16 +38,17 @@ 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):
# Check the case where we have an old `pip`
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`
Expand Down

0 comments on commit 878ae88

Please sign in to comment.