def test_files_gen(): filepath_parts = [ ("dir", "file1.txt"), ("dir", "file2.txt"), ("dir", "file3.txt"), ("dir", "dir2", "file1.txt"), ("dir", "dir2", "file2.txt"), ("dir", "dir2", "file3.txt"), ("dir", "dir2a", "file1.txt"), ("dir", "dir2a", "file2.txt"), ("dir", "dir2a", "file3.txt"), ] for f in filepath_parts: filepath = path.join(*f) touch(filepath) expected_files = sorted(path.join(*f) for f in filepath_parts) files = list(sorted(files_gen("dir"))) assert expected_files == files expected_dirs = sorted( set( path.join(*(part for part in f if ".txt" not in part)) for f in filepath_parts)) dirs = list(sorted(dirs_gen("dir"))) assert expected_dirs == dirs files_and_dirs = list(sorted(walk_gen("dir"))) expected = set(expected_dirs + expected_files) got = set(files_and_dirs) print(expected, got) assert set(expected_dirs + expected_files) == set(files_and_dirs) rmtree("dir")
def test_mv_multi(tmpdir): filepath_parts = [ ("dir", "file1.txt"), ("dir", "file2.txt"), ("dir", "file3.txt"), ("dir", "dir2", "file1.txt"), ("dir", "dir2", "file2.txt"), ("dir", "dir2", "file3.txt"), ("dir", "dir2a", "file1.txt"), ("dir", "dir2a", "file2.txt"), ("dir", "dir2a", "file3.txt"), ] for f in filepath_parts: filepath = path.join(tmpdir, *f) touch(filepath) files = list(sorted(files_gen(tmpdir))) # print(files) cd(tmpdir) mkdir("out") mv("dir/*", "out") files = list( sorted((e.replace(str(tmpdir), "").strip(sep) for e in files_gen(tmpdir)))) # print(files) expected = set( path.join("out", *f).replace(sep + "dir" + sep, sep) for f in filepath_parts) got = set(files) # print(expected) # print(got) assert expected == got
def test_touch(fdpath): assert not path.exists(fdpath) touch(fdpath) assert path.exists(fdpath) root = fdpath.split(sep)[0] if path.isdir(root): rmtree(root) elif path.isfile(root): remove(root)
def test_files_n_dirs_gen(): filepath_parts = [ ("dir", "file1.txt"), ("dir", "file2.txt"), ("dir", "file3.txt"), ("dir", "dir2", "file1.txt"), ("dir", "dir2", "file2.txt"), ("dir", "dir2", "file3.txt"), ("dir", "dir2a", "file1.txt"), ("dir", "dir2a", "file2.txt"), ("dir", "dir2a", "file3.txt"), ] for f in filepath_parts: filepath = path.join(*f) touch(filepath) expected_files = sorted(path.join(*f) for f in filepath_parts) files, dirs = files_dirs_gen("dir") files_n_dirs = set(list(files) + list(dirs)) walk_files_n_dirs = set(walk_gen("dir")) assert files_n_dirs == walk_files_n_dirs
def test_touch(dummy_filepath, tmpdir): fdpath = path.join(tmpdir, dummy_filepath) assert not path.exists(fdpath) touch(fdpath) assert path.exists(fdpath)