def test_multiple_cased_path_candidates(tmp_path): # test that we can get multiple cased path # candidates on case-sensitive file systems # create two folders that differ only in casing dir0 = tmp_path / "test folder/subfolder" dir1 = tmp_path / "Test Folder/subfolder" dir0.mkdir(parents=True, exist_ok=True) dir1.mkdir(parents=True, exist_ok=True) dir0 = str(dir0) dir1 = str(dir1) # scramble the casing and check if we can find matches path = osp.join(dir0.lower(), "File.txt") # find matches for original path itself candidates = cased_path_candidates(path) assert len(candidates) == 2 assert osp.join(dir0, "File.txt") in candidates assert osp.join(dir1, "File.txt") in candidates # find matches for children candidates = cased_path_candidates("/test folder/subfolder/File.txt", root=str(tmp_path)) assert len(candidates) == 2 assert osp.join(dir0, "File.txt") in candidates assert osp.join(dir1, "File.txt") in candidates
def test_cased_path_candidates(): # test that we can find a unique correctly cased path # starting from a candidate with scrambled casing path = "/usr/local/share".upper() candidates = cased_path_candidates(path) assert len(candidates) == 1 assert "/usr/local/share" in candidates candidates = cased_path_candidates("/test", root="/usr/local/share") assert len(candidates) == 1 assert "/usr/local/share/test" in candidates home = get_home_dir() # test that we can get multiple cased path # candidates on case-sensitive file systems if is_fs_case_sensitive(home): parent0 = osp.join(home, "test folder/subfolder") parent1 = osp.join(home, "Test Folder/subfolder") os.makedirs(parent0) os.makedirs(parent1) path = osp.join(parent0.lower(), "File.txt") try: candidates = cased_path_candidates(path) assert len(candidates) == 2 assert osp.join(parent0, "File.txt") in candidates assert osp.join(parent1, "File.txt") in candidates candidates = cased_path_candidates( "/test folder/subfolder/File.txt", root=home ) assert len(candidates) == 2 assert osp.join(parent0, "File.txt") in candidates assert osp.join(parent1, "File.txt") in candidates finally: delete(parent0) delete(parent1)
def test_cased_path_candidates(): # test that we can find a unique correctly cased path # starting from a candidate with scrambled casing path = "/usr/local/share".upper() candidates = cased_path_candidates(path) assert len(candidates) == 1 assert "/usr/local/share" in candidates candidates = cased_path_candidates("/test", root="/usr/local/share") assert len(candidates) == 1 assert "/usr/local/share/test" in candidates