Esempio n. 1
0
def test_compressed_listing(tmpdir):
    def in_tmpdir(paths):
        li = []
        for path in paths:
            li.append(
                str(
                    os.path.normcase(
                        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
    sample = [path for path in sample if ".skip." not in 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))
Esempio n. 2
0
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
    sample = [path for path in sample if ".skip." not in 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))
Esempio n. 3
0
 def test_compact_shorter_path(self, monkeypatch):
     monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                         lambda p: True)
     monkeypatch.setattr('os.path.exists', lambda p: True)
     # This deals with nt/posix path differences
     short_path = os.path.normcase(os.path.abspath(
         os.path.join(os.path.sep, 'path')))
     ups = UninstallPathSet(dist=Mock())
     ups.add(short_path)
     ups.add(os.path.join(short_path, 'longer'))
     assert compact(ups.paths) == {short_path}
Esempio n. 4
0
 def test_compact_shorter_path(self, monkeypatch):
     monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                         lambda p: True)
     monkeypatch.setattr('os.path.exists', lambda p: True)
     # This deals with nt/posix path differences
     short_path = os.path.normcase(
         os.path.abspath(os.path.join(os.path.sep, 'path')))
     ups = UninstallPathSet(dist=Mock())
     ups.add(short_path)
     ups.add(os.path.join(short_path, 'longer'))
     assert compact(ups.paths) == set([short_path])
Esempio n. 5
0
 def test_compact_shorter_path(self,
                               monkeypatch: pytest.MonkeyPatch) -> None:
     monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local",
                         mock_is_local)
     monkeypatch.setattr("os.path.exists", lambda p: True)
     # This deals with nt/posix path differences
     short_path = os.path.normcase(
         os.path.abspath(os.path.join(os.path.sep, "path")))
     ups = UninstallPathSet(dist=Mock())
     ups.add(short_path)
     ups.add(os.path.join(short_path, "longer"))
     assert compact(ups._paths) == {short_path}