def test_glob_when_files_match_with_question_mark(self): glob.populate(self.some_files_on_disk) d = PathList() file = "/some/file.00?0.exr" d.add(file) d.glob() self.assertEqual(len(d), 2)
def test_glob_when_files_match_with_range(self): glob.populate(self.some_files_on_disk) d = PathList() file = "/some/file.000[0-9].exr" d.add(file) d.glob() self.assertEqual(len(d), 9)
def test_common_path_when_duplicate_entries_of_single_path(self): d = PathList() files = [ "/users/joebloggs/tmp/foo.txt", "/users/joebloggs/tmp/foo.txt" ] d.add(*files) self.assertEqual(d.common_path(), Path("/users/joebloggs/tmp/foo.txt"))
def test_remove_one_missing_file(self): d = PathList() files = ["/tmp/missing.txt", "/tmp/foo.txt", "/tmp/bar.txt"] d.add(*files) self.assertEqual(len(d), 3) d.remove_missing() self.assertEqual(len(d), 2)
def test_glob_when_files_dont_match(self): glob.populate(self.other_files_on_disk) d = PathList() file = "/some/file.*.exr" d.add(file) d.glob() self.assertEqual(len(d), 0)
def test_next_reset_after_add(self): d = PathList() d.add("/file1", "/file2", "/file3") next(d) next(d) d.add("/file4") self.assertEqual(next(d), Path("/file1"))
def test_ignore_invalid_glob(self): bad_glob = "/path/to/Model[b-a]" glob.populate(bad_glob) d = PathList() d.add(bad_glob) d.glob() self.assertEqual(list(d)[0].fslash(), bad_glob)
def test_remove_when_all_files_missing(self): d = PathList() files = ["/tmp/missing.txt", "/tmp/missing2.txt", "/tmp/missing3.txt"] d.add(*files) self.assertEqual(len(d), 3) d.remove_missing() self.assertFalse(d)
def test_glob_dedups_when_many_files_match(self): glob.populate(self.some_files_on_disk) d = PathList() files = ["/some/file.*.exr", "/some/*.exr"] d.add(*files) d.glob() self.assertEqual(len(d), 20)
def test_next_fails_after_last(self): d = PathList() d.add("/file1", "/file2", "/file3") next(d) next(d) next(d) with self.assertRaises(StopIteration): next(d)
def test_common_path_when_one_path_is_the_common_path(self): d = PathList() files = [ "/users/joebloggs/tmp", "/users/joebloggs/tmp/bolly/operation", "/users/joebloggs/tmp/stay/go", ] d.add(*files) self.assertEqual(d.common_path(), Path("/users/joebloggs/tmp"))
def test_common_path(self): d = PathList() files = [ "/users/joebloggs/tmp/foobar/test", "/users/joebloggs/tmp/baz/fripp", "/users/joebloggs/tmp/elephant/corner", ] d.add(*files) self.assertEqual(d.common_path(), Path("/users/joebloggs/tmp"))
def test_common_path_when_common_prefix_in_filename(self): d = PathList() files = [ "/users/joebloggs/tmp/dissention/perfect", "/users/joebloggs/tmp/disagreement/crimson", "/users/joebloggs/tmp/diatribe/belew", ] d.add(*files) self.assertEqual(d.common_path(), Path("/users/joebloggs/tmp"))
def test_common_different_drive_letter(self): d = PathList() files = [ "D:/users/joebloggs/tmp/foo.txt", "D:/users/joebloggs/tmp/modelman.jpg", "C:/users/joebloggs/tmp/ration.cpp", "C:/users/joebloggs/tmp/bill.project", ] d.add(*files) self.assertEqual(d.common_path(), Path("/"))
def test_common_path_when_lowest_path_is_the_common_path(self): d = PathList() files = [ "/users/joebloggs/tmp/foo.txt", "/users/joebloggs/tmp/modelman.jpg", "/users/joebloggs/tmp/ration.cpp", "/users/joebloggs/tmp/bill.project", ] d.add(*files) self.assertEqual(d.common_path(), Path("/users/joebloggs/tmp"))
def test_dont_remove_globbable_files(self): d = PathList() files = [ "/tmp/foo", "/tmp/missing*", "/tmp/missing.[0-9]", "/tmp/missing.????.exr" ] d.add(*files) self.assertEqual(len(d), 4) d.remove_missing() self.assertEqual(len(d), 4)
def test_remove_missing_when_dups_given(self): d = PathList() files = [ "/tmp/missing", "/tmp/foo", "/tmp/bar", "/tmp/foo", "/tmp/missing2", "/tmp/missing" ] d.add(*files) self.assertEqual(len(d), 4) d.remove_missing() self.assertEqual(len(d), 2)
def test_next(self): d = PathList() d.add("/file1", "/file2", "/file3") self.assertEqual(next(d), Path("/file1")) self.assertEqual(next(d), Path("/file2"))
def test_adds_strings(self): d = PathList() d.add("/a/file1", "/a/file2") self.assertEqual(len(d), 2)
def test_unpacking(self): d = PathList() d.add(Path("/a/file1"), Path("/a/file2")) a, b = d self.assertEqual(type(a), Path)
def test_glob_leaves_non_existent_unglobbable_entries_untouched(self): glob.populate(self.some_files_on_disk[:3]) d = PathList() d.add("/some/file.*.exr", "/other/file1.exr", "/other/file2.exr") d.glob() self.assertEqual(len(d), 5)
def test_dedup_cleaned_on_access_next(self): d = PathList() d.add("/file1", "/file2", "/file3") n = next(d) self.assertTrue(d._clean)
def test_common_path_is_slash_when_root(self): d = PathList() files = ["/users/joebloggs/tmp/foo.txt", "/dev/joebloggs/tmp/foo.txt"] d.add(*files) self.assertEqual(d.common_path(), Path("/"))
def test_removes_string(self): d = PathList() d.add("/a/file1", "/a/file2", "/a/file3") d.remove("/a/file2") self.assertEqual(len(d), 2)
def test_adds_paths(self): d = PathList() d.add(Path("/a/file1"), Path("/a/file2")) self.assertEqual(len(d), 2)
def test_dedup_dirtied_on_add(self): d = PathList() d.add("/file1") self.assertFalse(d._clean)
def test_adds_mix(self): d = PathList() d.add("/a/file1", "/a/file2", Path("/a/file3")) self.assertEqual(len(d), 3)
def test_dedup_cleaned_on_access_len(self): d = PathList() d.add("/file1") ls = len(d) self.assertTrue(d._clean)
def test_removes_path(self): d = PathList() d.add("/a/file1", "/a/file2", "/a/file3") d.remove(Path("/a/file2")) self.assertEqual(len(d), 2) self.assertEqual(list(d)[1], Path("/a/file3"))
def test_dedup_contained_file(self): d = PathList() d.add("/dir1/", "/dir1/file1", "/dir2/file1", "/dir3/file2") self.assertEqual(len(d), 3)