@@ -15,11 +15,30 @@ def cache_dir(script):
15
15
return result .stdout .strip ()
16
16
17
17
18
+ @pytest .fixture
19
+ def http_cache_dir (cache_dir ):
20
+ return os .path .normcase (os .path .join (cache_dir , 'http' ))
21
+
22
+
18
23
@pytest .fixture
19
24
def wheel_cache_dir (cache_dir ):
20
25
return os .path .normcase (os .path .join (cache_dir , 'wheels' ))
21
26
22
27
28
+ @pytest .fixture
29
+ def http_cache_files (http_cache_dir ):
30
+ destination = os .path .join (http_cache_dir , 'arbitrary' , 'pathname' )
31
+
32
+ if not os .path .exists (destination ):
33
+ return []
34
+
35
+ filenames = glob (os .path .join (destination , '*' ))
36
+ files = []
37
+ for filename in filenames :
38
+ files .append (os .path .join (destination , filename ))
39
+ return files
40
+
41
+
23
42
@pytest .fixture
24
43
def wheel_cache_files (wheel_cache_dir ):
25
44
destination = os .path .join (wheel_cache_dir , 'arbitrary' , 'pathname' )
@@ -34,6 +53,24 @@ def wheel_cache_files(wheel_cache_dir):
34
53
return files
35
54
36
55
56
+ @pytest .fixture
57
+ def populate_http_cache (http_cache_dir ):
58
+ destination = os .path .join (http_cache_dir , 'arbitrary' , 'pathname' )
59
+ os .makedirs (destination )
60
+
61
+ files = [
62
+ ('aaaaaaaaa' , os .path .join (destination , 'aaaaaaaaa' )),
63
+ ('bbbbbbbbb' , os .path .join (destination , 'bbbbbbbbb' )),
64
+ ('ccccccccc' , os .path .join (destination , 'ccccccccc' )),
65
+ ]
66
+
67
+ for _name , filename in files :
68
+ with open (filename , 'w' ):
69
+ pass
70
+
71
+ return files
72
+
73
+
37
74
@pytest .fixture
38
75
def populate_wheel_cache (wheel_cache_dir ):
39
76
destination = os .path .join (wheel_cache_dir , 'arbitrary' , 'pathname' )
@@ -83,6 +120,29 @@ def list_matches_wheel_abspath(wheel_name, result):
83
120
and os .path .exists (l ), lines ))
84
121
85
122
123
+ @pytest .fixture
124
+ def remove_matches_http (http_cache_dir ):
125
+ """Returns True if any line in `result`, which should be the output of
126
+ a `pip cache purge` call, matches `http_filename`.
127
+
128
+ E.g., If http_filename is `aaaaaaaaa`, it searches for a line equal to
129
+ `Removed <http files cache dir>/arbitrary/pathname/aaaaaaaaa`.
130
+ """
131
+
132
+ def _remove_matches_http (http_filename , result ):
133
+ lines = result .stdout .splitlines ()
134
+
135
+ # The "/arbitrary/pathname/" bit is an implementation detail of how
136
+ # the `populate_http_cache` fixture is implemented.
137
+ path = os .path .join (
138
+ http_cache_dir , 'arbitrary' , 'pathname' , http_filename ,
139
+ )
140
+ expected = 'Removed {}' .format (path )
141
+ return expected in lines
142
+
143
+ return _remove_matches_http
144
+
145
+
86
146
@pytest .fixture
87
147
def remove_matches_wheel (wheel_cache_dir ):
88
148
"""Returns True if any line in `result`, which should be the output of
@@ -124,11 +184,17 @@ def test_cache_dir_too_many_args(script, cache_dir):
124
184
assert 'ERROR: Too many arguments' in result .stderr .splitlines ()
125
185
126
186
127
- @pytest .mark .usefixtures ("populate_wheel_cache" )
128
- def test_cache_info (script , wheel_cache_dir , wheel_cache_files ):
187
+ @pytest .mark .usefixtures ("populate_http_cache" , "populate_wheel_cache" )
188
+ def test_cache_info (
189
+ script , http_cache_dir , wheel_cache_dir , wheel_cache_files
190
+ ):
129
191
result = script .pip ('cache' , 'info' )
130
192
131
- assert 'Location: {}' .format (wheel_cache_dir ) in result .stdout
193
+ assert (
194
+ 'Package index page cache location: {}' .format (http_cache_dir )
195
+ in result .stdout
196
+ )
197
+ assert 'Wheels location: {}' .format (wheel_cache_dir ) in result .stdout
132
198
num_wheels = len (wheel_cache_files )
133
199
assert 'Number of wheels: {}' .format (num_wheels ) in result .stdout
134
200
@@ -265,21 +331,28 @@ def test_cache_remove_name_and_version_match(script, remove_matches_wheel):
265
331
assert not remove_matches_wheel ('zzz-7.8.9' , result )
266
332
267
333
268
- @pytest .mark .usefixtures ("populate_wheel_cache" )
269
- def test_cache_purge (script , remove_matches_wheel ):
270
- """Running `pip cache purge` should remove all cached wheels."""
334
+ @pytest .mark .usefixtures ("populate_http_cache" , "populate_wheel_cache" )
335
+ def test_cache_purge (script , remove_matches_http , remove_matches_wheel ):
336
+ """Running `pip cache purge` should remove all cached http files and
337
+ wheels."""
271
338
result = script .pip ('cache' , 'purge' , '--verbose' )
272
339
340
+ assert remove_matches_http ('aaaaaaaaa' , result )
341
+ assert remove_matches_http ('bbbbbbbbb' , result )
342
+ assert remove_matches_http ('ccccccccc' , result )
343
+
273
344
assert remove_matches_wheel ('yyy-1.2.3' , result )
274
345
assert remove_matches_wheel ('zzz-4.5.6' , result )
275
346
assert remove_matches_wheel ('zzz-4.5.7' , result )
276
347
assert remove_matches_wheel ('zzz-7.8.9' , result )
277
348
278
349
279
- @pytest .mark .usefixtures ("populate_wheel_cache" )
280
- def test_cache_purge_too_many_args (script , wheel_cache_files ):
350
+ @pytest .mark .usefixtures ("populate_http_cache" , "populate_wheel_cache" )
351
+ def test_cache_purge_too_many_args (
352
+ script , http_cache_files , wheel_cache_files
353
+ ):
281
354
"""Running `pip cache purge aaa` should raise an error and remove no
282
- cached wheels."""
355
+ cached http files or wheels."""
283
356
result = script .pip ('cache' , 'purge' , 'aaa' , '--verbose' ,
284
357
expect_error = True )
285
358
assert result .stdout == ''
@@ -289,7 +362,7 @@ def test_cache_purge_too_many_args(script, wheel_cache_files):
289
362
assert 'ERROR: Too many arguments' in result .stderr .splitlines ()
290
363
291
364
# Make sure nothing was deleted.
292
- for filename in wheel_cache_files :
365
+ for filename in http_cache_files + wheel_cache_files :
293
366
assert os .path .exists (filename )
294
367
295
368
0 commit comments