2019-04-08 19:00:09 +02:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
|
|
|
|
def _cache_dir(script):
|
2019-10-10 01:58:23 +02:00
|
|
|
result = script.run(
|
2019-04-08 19:00:09 +02:00
|
|
|
'python', '-c',
|
|
|
|
'from pip._internal.locations import USER_CACHE_DIR;'
|
|
|
|
'print(USER_CACHE_DIR)'
|
|
|
|
)
|
2019-10-10 01:58:23 +02:00
|
|
|
return result.stdout.strip()
|
2019-04-08 19:00:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_info(script, monkeypatch):
|
|
|
|
result = script.pip('cache', 'info')
|
|
|
|
cache_dir = _cache_dir(script)
|
|
|
|
|
|
|
|
assert 'Location: %s' % cache_dir in result.stdout
|
2019-10-08 05:31:01 +02:00
|
|
|
# TODO(@duckinator): This should probably test that the number of
|
|
|
|
# packages is actually correct, but I'm not sure how to do that
|
|
|
|
# without pretty much re-implementing the entire cache info command.
|
2019-04-08 19:00:09 +02:00
|
|
|
assert 'Packages: ' in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_cache_list(script, monkeypatch):
|
|
|
|
cache_dir = _cache_dir(script)
|
|
|
|
wheel_cache_dir = os.path.join(cache_dir, 'wheels')
|
|
|
|
destination = os.path.join(wheel_cache_dir, 'arbitrary', 'pathname')
|
|
|
|
os.makedirs(destination)
|
|
|
|
with open(os.path.join(destination, 'yyy-1.2.3.whl'), 'w'):
|
|
|
|
pass
|
|
|
|
with open(os.path.join(destination, 'zzz-4.5.6.whl'), 'w'):
|
|
|
|
pass
|
|
|
|
result = script.pip('cache', 'list')
|
|
|
|
assert 'yyy-1.2.3' in result.stdout
|
|
|
|
assert 'zzz-4.5.6' in result.stdout
|
|
|
|
shutil.rmtree(os.path.join(wheel_cache_dir, 'arbitrary'))
|
|
|
|
|
|
|
|
|
2019-10-10 01:58:23 +02:00
|
|
|
def test_cache_list_too_many_args(script, monkeypatch):
|
|
|
|
script.pip('cache', 'list', 'aaa', 'bbb',
|
|
|
|
expect_error=True)
|
|
|
|
|
|
|
|
|
2019-04-08 19:00:09 +02:00
|
|
|
def test_cache_list_with_pattern(script, monkeypatch):
|
|
|
|
cache_dir = _cache_dir(script)
|
|
|
|
wheel_cache_dir = os.path.join(cache_dir, 'wheels')
|
|
|
|
destination = os.path.join(wheel_cache_dir, 'arbitrary', 'pathname')
|
|
|
|
os.makedirs(destination)
|
|
|
|
with open(os.path.join(destination, 'yyy-1.2.3.whl'), 'w'):
|
|
|
|
pass
|
|
|
|
with open(os.path.join(destination, 'zzz-4.5.6.whl'), 'w'):
|
|
|
|
pass
|
|
|
|
result = script.pip('cache', 'list', 'zzz')
|
|
|
|
assert 'yyy-1.2.3' not in result.stdout
|
|
|
|
assert 'zzz-4.5.6' in result.stdout
|
|
|
|
shutil.rmtree(os.path.join(wheel_cache_dir, 'arbitrary'))
|
|
|
|
|
|
|
|
|
|
|
|
def test_cache_remove(script, monkeypatch):
|
|
|
|
cache_dir = _cache_dir(script)
|
|
|
|
wheel_cache_dir = os.path.join(cache_dir, 'wheels')
|
|
|
|
destination = os.path.join(wheel_cache_dir, 'arbitrary', 'pathname')
|
|
|
|
os.makedirs(destination)
|
|
|
|
with open(os.path.join(wheel_cache_dir, 'yyy-1.2.3.whl'), 'w'):
|
|
|
|
pass
|
|
|
|
with open(os.path.join(wheel_cache_dir, 'zzz-4.5.6.whl'), 'w'):
|
|
|
|
pass
|
|
|
|
|
|
|
|
script.pip('cache', 'remove', expect_error=True)
|
|
|
|
result = script.pip('cache', 'remove', 'zzz', '--verbose')
|
|
|
|
assert 'yyy-1.2.3' not in result.stdout
|
|
|
|
assert 'zzz-4.5.6' in result.stdout
|
|
|
|
shutil.rmtree(os.path.join(wheel_cache_dir, 'arbitrary'))
|
2019-10-10 01:58:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_remove_too_many_args(script, monkeypatch):
|
|
|
|
result = script.pip('cache', 'remove', 'aaa', 'bbb',
|
|
|
|
expect_error=True)
|
|
|
|
|
|
|
|
|
|
|
|
def test_cache_purge(script, monkeypatch):
|
|
|
|
cache_dir = _cache_dir(script)
|
|
|
|
wheel_cache_dir = os.path.join(cache_dir, 'wheels')
|
|
|
|
destination = os.path.join(wheel_cache_dir, 'arbitrary', 'pathname')
|
|
|
|
os.makedirs(destination)
|
|
|
|
with open(os.path.join(wheel_cache_dir, 'yyy-1.2.3.whl'), 'w'):
|
|
|
|
pass
|
|
|
|
with open(os.path.join(wheel_cache_dir, 'zzz-4.5.6.whl'), 'w'):
|
|
|
|
pass
|
|
|
|
|
|
|
|
result = script.pip('cache', 'purge', 'aaa', '--verbose',
|
|
|
|
expect_error=True)
|
|
|
|
assert 'yyy-1.2.3' not in result.stdout
|
|
|
|
assert 'zzz-4.5.6' not in result.stdout
|
|
|
|
|
|
|
|
result = script.pip('cache', 'purge', '--verbose')
|
|
|
|
assert 'yyy-1.2.3' in result.stdout
|
|
|
|
assert 'zzz-4.5.6' in result.stdout
|
|
|
|
|
|
|
|
shutil.rmtree(os.path.join(wheel_cache_dir, 'arbitrary'))
|