Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'pip cache' command #6391

Merged
merged 40 commits into from
Apr 13, 2020
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
04c0b0e
Add 'pip cache' command.
duckinator Apr 8, 2019
b0e7b66
[commands/cache] Refactor + fix linting failures.
duckinator Oct 8, 2019
b9b29b8
[commands/cache] fix 'pip cache info'; don't hide python/abi/platform…
duckinator Oct 8, 2019
c59ced6
[commands/cache] More refactoring of cache command
duckinator Oct 8, 2019
8ae71ad
[commands/cache] Add docs for 'pip cache' command.
duckinator Oct 8, 2019
d57dcd9
[commands/cache] Add news file for cache command.
duckinator Oct 8, 2019
50604be
[commands/cache] Raise errors if wrong number of args.
duckinator Oct 9, 2019
9563dfb
[commands/cache] Refactor get_cache_info().
duckinator Oct 10, 2019
6fb1ee7
[commands/cache] fix linting error.
duckinator Oct 10, 2019
c838a67
[commands/cache] Change pattern suffix from -*.whl to *.whl.
duckinator Oct 10, 2019
61dd0bc
[commands/cache] Use location of wheel cache dir specifically.
duckinator Oct 10, 2019
94a6593
[commands/cache] Add HTML docs for `pip cache`.
duckinator Oct 10, 2019
61a0adc
[commands/cache] Add missing type annotation.
duckinator Oct 10, 2019
554133a
[commands/cache] Add file size information.
duckinator Jan 6, 2020
2d97830
[commands/cache] Minor clean-up.
duckinator Jan 13, 2020
6fa8498
[commands/cache] Avoid use of "(s)" suffix.
duckinator Jan 14, 2020
d74895a
[commands/cache] Normalize path in test.
duckinator Feb 23, 2020
10d1376
[commands/cache] Be explicit about `pip cache` only working on the wh…
duckinator Feb 23, 2020
d9dc76e
[commands/cache] Correct argument name in documentation for `pip cach…
duckinator Mar 4, 2020
f22f69e
[utils/filesystem] Convert `size` to float, for consistent behavior b…
duckinator Mar 4, 2020
03d5ec1
[utils/filesystem] Reformat comment to keep lines <79 characters long.
duckinator Mar 4, 2020
735375f
[commands/cache] Reformat documentation.
duckinator Mar 5, 2020
8cd8c91
[commands/cache] Reformat (more) documentation.
duckinator Mar 5, 2020
63ba6cc
[command/cache, utils/filesystem] Use existing format_size; remove _f…
duckinator Mar 5, 2020
ed9f885
[commands/cache] Reformat output of `pip cache info`
duckinator Mar 5, 2020
f8b67c8
[commands/cache] Fix test_cache_info test.
duckinator Mar 5, 2020
8b518b2
[commands/cache] Make filenames more realistic in tests.
duckinator Mar 5, 2020
d57407a
[commands/cache] Make _find_wheels(), and this `pip cache {list,remov…
duckinator Mar 5, 2020
e1fde1f
[commands/cache] Remove unnecessary re-definition of __init__.
duckinator Mar 5, 2020
e804aa5
[commands/cache] Have `pip cache info` raise an exception if it gets …
duckinator Mar 5, 2020
6e425d8
[tests/functional/cache] Refactor to be less redundant.
duckinator Mar 6, 2020
274b295
[tests/functional/cache] Make fixtures feel less magical.
duckinator Mar 6, 2020
c6b5a52
[tests/functional/test_cache] Always call normcase on cache dir; fix …
duckinator Mar 7, 2020
32ce3ba
[tests/functional/cache] Rewrite all of the pip cache {list,remove} t…
duckinator Mar 10, 2020
ba7c3ac
[tests/functional/test_cache] Add test `pip cache list` with an empty…
duckinator Mar 10, 2020
a20b28d
[tests/functional/test_cache] Split apart tests for `pip cache purge`.
duckinator Mar 10, 2020
8858237
[tests/functional/test_cache] Refactor list_matches_wheel() and remov…
duckinator Mar 10, 2020
b7239f5
[tests/functional/test_cache] Remove unused import.
duckinator Mar 10, 2020
0c4eafa
[tests/functional/test_cache] Fix test on Python 2.7.
duckinator Mar 10, 2020
b988417
[tests/functional/test_cache] Use os.path.join() instead of hard-codi…
duckinator Mar 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[tests/functional/cache] Rewrite all of the pip cache {list,remove} t…
…ests.
  • Loading branch information
duckinator committed Apr 1, 2020
commit 32ce3bacbe0893bc0ceb326b8df98ac9300a6915
106 changes: 95 additions & 11 deletions tests/functional/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
from glob import glob

import pytest
Expand Down Expand Up @@ -37,6 +38,8 @@ def populate_wheel_cache(wheel_cache_dir):
files = [
('yyy-1.2.3', os.path.join(destination, 'yyy-1.2.3-py3-none-any.whl')),
('zzz-4.5.6', os.path.join(destination, 'zzz-4.5.6-py3-none-any.whl')),
('zzz-4.5.7', os.path.join(destination, 'zzz-4.5.7-py3-none-any.whl')),
('zzz-7.8.9', os.path.join(destination, 'zzz-7.8.9-py3-none-any.whl')),
]

for _name, filename in files:
Expand All @@ -46,6 +49,38 @@ def populate_wheel_cache(wheel_cache_dir):
return files


def list_matches_wheel(wheel_name, lines):
"""Returns True if any line in `lines`, which should be the output of
a `pip cache list` call, matches `wheel_name`.

E.g., If wheel_name is `foo-1.2.3` it searches for a line starting with
`- foo-1.2.3-py3-none-any.whl `."""
expected = ' - {}-py3-none-any.whl '.format(wheel_name)
return any(map(lambda l: l.startswith(expected), lines))


@pytest.fixture
def remove_matches_wheel(wheel_cache_dir):
"""Returns True if any line in `lines`, which should be the output of
a `pip cache remove`/`pip cache purge` call, matches `wheel_name`.

E.g., If wheel_name is `foo-1.2.3`, it searches for a line equal to
`Removed <wheel cache dir>/arbitrary/pathname/foo-1.2.3-py3-none-any.whl`.
"""

def _remove_matches_wheel(wheel_name, lines):
wheel_filename = '{}-py3-none-any.whl'.format(wheel_name)

# The "/arbitrary/pathname/" bit is an implementation detail of how
# the `populate_wheel_cache` fixture is implemented.
expected = 'Removed {}/arbitrary/pathname/{}'.format(
duckinator marked this conversation as resolved.
Show resolved Hide resolved
wheel_cache_dir, wheel_filename,
)
return expected in lines

return _remove_matches_wheel


@pytest.mark.usefixtures("populate_wheel_cache")
def test_cache_info(script, wheel_cache_dir, wheel_cache_files):
result = script.pip('cache', 'info')
Expand All @@ -57,37 +92,86 @@ def test_cache_info(script, wheel_cache_dir, wheel_cache_files):

@pytest.mark.usefixtures("populate_wheel_cache")
def test_cache_list(script):
"""Running `pip cache list` should return exactly what the
populate_wheel_cache fixture adds."""
result = script.pip('cache', 'list')

assert 'yyy-1.2.3' in result.stdout
assert 'zzz-4.5.6' in result.stdout
lines = result.stdout.splitlines()
assert list_matches_wheel('yyy-1.2.3', lines)
assert list_matches_wheel('zzz-4.5.6', lines)
assert list_matches_wheel('zzz-4.5.7', lines)
assert list_matches_wheel('zzz-7.8.9', lines)


def test_cache_list_too_many_args(script):
"""Passing `pip cache list` too many arguments should cause an error."""
script.pip('cache', 'list', 'aaa', 'bbb',
expect_error=True)


@pytest.mark.usefixtures("populate_wheel_cache")
def test_cache_list_with_pattern(script):
result = script.pip('cache', 'list', 'zzz')
assert 'yyy-1.2.3' not in result.stdout
assert 'zzz-4.5.6' in result.stdout
def test_cache_list_name_match(script):
"""Running `pip cache list zzz` should list zzz-4.5.6, zzz-4.5.7,
zzz-7.8.9, but nothing else."""
result = script.pip('cache', 'list', 'zzz', '--verbose')
lines = result.stdout.splitlines()

assert not list_matches_wheel('yyy-1.2.3', lines)
assert list_matches_wheel('zzz-4.5.6', lines)
assert list_matches_wheel('zzz-4.5.7', lines)
assert list_matches_wheel('zzz-7.8.9', lines)


@pytest.mark.usefixtures("populate_wheel_cache")
def test_cache_remove(script):
def test_cache_list_name_and_version_match(script):
"""Running `pip cache list zzz-4.5.6` should list zzz-4.5.6, but
nothing else."""
result = script.pip('cache', 'list', 'zzz-4.5.6', '--verbose')
lines = result.stdout.splitlines()

assert not list_matches_wheel('yyy-1.2.3', lines)
assert list_matches_wheel('zzz-4.5.6', lines)
assert not list_matches_wheel('zzz-4.5.7', lines)
assert not list_matches_wheel('zzz-7.8.9', lines)


@pytest.mark.usefixture("populate_wheel_cache")
def test_cache_remove_no_arguments(script):
"""Running `pip cache remove` with no arguments should cause an error."""
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


def test_cache_remove_too_many_args(script):
"""Passing `pip cache remove` too many arguments should cause an error."""
script.pip('cache', 'remove', 'aaa', 'bbb',
expect_error=True)


@pytest.mark.usefixtures("populate_wheel_cache")
def test_cache_remove_name_match(script, remove_matches_wheel):
"""Running `pip cache remove zzz` should remove zzz-4.5.6 and zzz-7.8.9,
but nothing else."""
result = script.pip('cache', 'remove', 'zzz', '--verbose')
lines = result.stdout.splitlines()

assert not remove_matches_wheel('yyy-1.2.3', lines)
assert remove_matches_wheel('zzz-4.5.6', lines)
assert remove_matches_wheel('zzz-4.5.7', lines)
assert remove_matches_wheel('zzz-7.8.9', lines)


@pytest.mark.usefixtures("populate_wheel_cache")
def test_cache_remove_name_and_version_match(script, remove_matches_wheel):
"""Running `pip cache remove zzz-4.5.6` should remove zzz-4.5.6, but
nothing else."""
result = script.pip('cache', 'remove', 'zzz-4.5.6', '--verbose')
lines = result.stdout.splitlines()

assert not remove_matches_wheel('yyy-1.2.3', lines)
assert remove_matches_wheel('zzz-4.5.6', lines)
assert not remove_matches_wheel('zzz-4.5.7', lines)
assert not remove_matches_wheel('zzz-7.8.9', lines)


@pytest.mark.usefixtures("populate_wheel_cache")
def test_cache_purge(script):
result = script.pip('cache', 'purge', 'aaa', '--verbose',
Expand Down