1
1
from pathlib import Path
2
+ import os
2
3
3
4
import pretend # type: ignore
4
5
from packaging .version import Version
9
10
10
11
def test_get_cache_dir (monkeypatch ):
11
12
# 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")
14
15
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" ))
16
18
monkeypatch .setattr (cache , "_get_pip_cache" , get_pip_cache )
17
19
18
20
# When `pip cache dir` works, we use it. In this case, it's mocked.
19
21
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")
21
23
22
24
23
25
def test_get_pip_cache ():
@@ -36,16 +38,17 @@ def test_get_cache_dir_pip_disabled_in_environment(monkeypatch):
36
38
monkeypatch .setenv ("PIP_NO_CACHE_DIR" , "1" )
37
39
38
40
# 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"
40
43
41
44
42
45
def test_get_cache_dir_old_pip (monkeypatch ):
43
46
# Check the case where we have an old `pip`
44
47
monkeypatch .setattr (cache , "_PIP_VERSION" , Version ("1.0.0" ))
45
48
46
49
# 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")
49
52
50
53
# In this case, we can't query `pip` to figure out where its HTTP cache is
51
54
# Instead, we use `~/.pip-audit-cache`
0 commit comments