1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Add a test for compressed_listing

This commit is contained in:
Pradyun S. Gedam 2017-06-05 17:18:41 +05:30
parent 32c8f42729
commit 26c5f12a92

View file

@ -4,7 +4,11 @@ import pytest
from mock import Mock
import pip.req.req_uninstall
from pip.req.req_uninstall import UninstallPathSet, uninstallation_paths
from pip.req.req_uninstall import (
UninstallPathSet, compact, compress_for_output_listing,
uninstallation_paths
)
from tests.lib import create_file
# Pretend all files are local, so UninstallPathSet accepts files in the tmpdir,
@ -40,6 +44,55 @@ def test_uninstallation_paths():
assert paths2 == paths
def test_compressed_listing(tmpdir):
def in_tmpdir(paths):
li = []
for path in paths:
li.append(str(os.path.join(tmpdir, path.replace("/", os.path.sep))))
return li
sample = in_tmpdir([
"lib/mypkg.dist-info/METADATA",
"lib/mypkg.dist-info/PKG-INFO",
"lib/mypkg/would_be_removed.txt",
"lib/mypkg/would_be_skipped.skip.txt",
"lib/mypkg/__init__.py",
"lib/mypkg/my_awesome_code.py",
"lib/mypkg/__pycache__/my_awesome_code-magic.pyc",
"lib/mypkg/support/support_file.py",
"lib/mypkg/support/more_support.py",
"lib/mypkg/support/would_be_skipped.skip.py",
"lib/mypkg/support/__pycache__/support_file-magic.pyc",
"lib/random_other_place/file_without_a_dot_pyc",
"bin/mybin",
])
# Create the required files
for fname in sample:
create_file(fname, "random blub")
# Remove the files to be skipped from the paths
for path in sample[:]:
if ".skip." in path:
sample.remove(path)
expected_remove = in_tmpdir([
"bin/mybin",
"lib/mypkg.dist-info/*",
"lib/mypkg/*",
"lib/random_other_place/file_without_a_dot_pyc",
])
expected_skip = in_tmpdir([
"lib/mypkg/would_be_skipped.skip.txt",
"lib/mypkg/support/would_be_skipped.skip.py",
])
will_remove, will_skip = compress_for_output_listing(sample)
assert sorted(expected_skip) == sorted(compact(will_skip))
assert sorted(expected_remove) == sorted(compact(will_remove))
class TestUninstallPathSet(object):
def test_add(self, tmpdir, monkeypatch):
monkeypatch.setattr(pip.req.req_uninstall, 'is_local', mock_is_local)
@ -80,7 +133,7 @@ class TestUninstallPathSet(object):
ups = UninstallPathSet(dist=Mock())
ups.add(short_path)
ups.add(os.path.join(short_path, 'longer'))
assert ups.compact(ups.paths) == set([short_path])
assert compact(ups.paths) == set([short_path])
@pytest.mark.skipif("sys.platform == 'win32'")
def test_detect_symlink_dirs(self, monkeypatch, tmpdir):