def test_compress_for_rename(self, monkeypatch: pytest.MonkeyPatch) -> None: paths = [ os.path.sep.join(p.split("/")) for p in [ "A/B/b.py", "A/B/D/c.py", "A/C/d.py", "A/E/f.py", "A/G/g.py", ] ] expected_paths = [ os.path.sep.join(p.split("/")) for p in [ "A/B/", # selected everything below A/B "A/C/d.py", # did not select everything below A/C "A/E/", # only empty folders remain under A/E "A/G/g.py", # non-empty folder remains under A/G ] ] monkeypatch.setattr("os.walk", self.mock_walk) actual_paths = compress_for_rename(paths) assert set(expected_paths) == set(actual_paths)
def test_compress_for_rename(self, monkeypatch): paths = [os.path.sep.join(p.split("/")) for p in [ "A/B/b.py", "A/B/D/c.py", "A/C/d.py", "A/E/f.py", "A/G/g.py", ]] expected_paths = [os.path.sep.join(p.split("/")) for p in [ "A/B/", # selected everything below A/B "A/C/d.py", # did not select everything below A/C "A/E/", # only empty folders remain under A/E "A/G/g.py", # non-empty folder remains under A/G ]] monkeypatch.setattr('os.walk', self.mock_walk) actual_paths = compress_for_rename(paths) assert set(expected_paths) == set(actual_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 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", ]) expected_rename = in_tmpdir([ "bin/", "lib/mypkg.dist-info/", "lib/mypkg/would_be_removed.txt", "lib/mypkg/__init__.py", "lib/mypkg/my_awesome_code.py", "lib/mypkg/__pycache__/", "lib/mypkg/support/support_file.py", "lib/mypkg/support/more_support.py", "lib/mypkg/support/__pycache__/", "lib/random_other_place/", ]) will_remove, will_skip = compress_for_output_listing(sample) will_rename = compress_for_rename(sample) assert sorted(expected_skip) == sorted(compact(will_skip)) assert sorted(expected_remove) == sorted(compact(will_remove)) assert sorted(expected_rename) == sorted(compact(will_rename))
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", ]) expected_rename = in_tmpdir([ "bin/", "lib/mypkg.dist-info/", "lib/mypkg/would_be_removed.txt", "lib/mypkg/__init__.py", "lib/mypkg/my_awesome_code.py", "lib/mypkg/__pycache__/", "lib/mypkg/support/support_file.py", "lib/mypkg/support/more_support.py", "lib/mypkg/support/__pycache__/", "lib/random_other_place/", ]) will_remove, will_skip = compress_for_output_listing(sample) will_rename = compress_for_rename(sample) assert sorted(expected_skip) == sorted(compact(will_skip)) assert sorted(expected_remove) == sorted(compact(will_remove)) assert sorted(expected_rename) == sorted(compact(will_rename))