def test_walkdir_with_ambiguous_terms(): """Walkdir should return the path for the first dir that matches the term""" mkdir('dir1/filedir', 'dir1/filedir2') touch('dir1/file1') # caution a file! expected_result = os.path.join(TEST_DIR, 'dir1', 'filedir') eq_(expected_result, walkdir(TEST_DIR, terms=['file', 'dir1']))
def test_walkdir_without_two_existing_dirs_and_one_fake_subdir(): """Walkdir should return the path until the last dir that exists""" mkdir('dir1/dir2') assert not os.path.isdir(os.path.join(TEST_DIR, 'dir1', 'dir2', 'fake_dir')) expected_result = os.path.join(TEST_DIR, 'dir1', 'dir2', '') eq_(expected_result, walkdir(TEST_DIR, terms=['fake_dir', 'dir2', 'dir1']))
def test_walkdir_with_a_filename_unicode_support(): """Walkdir should return the path until the last dir that exists""" mkdir('dir1éñö') touch('dir1éñö/file1') expected_result = os.path.join(TEST_DIR, 'dir1éñö', '') eq_(expected_result, walkdir(TEST_DIR, terms=['file1', 'dir1éñö']))
def test_walkdir_with_one_existing_dir(): """Calling walkdir with one existing dir as terms should return that dir""" mkdir('dir1') expected_result = os.path.join(TEST_DIR, 'dir1') eq_(expected_result, walkdir(TEST_DIR, terms=['dir1']))
def test_walkdir_with_fuzzy_names_in_different_parts_of_the_dirname(): """Walkdir should prioratize matching at the begining of the dirname when fuzzy finding for child dirs""" mkdir('dir1/filedir', 'dir1/dir', 'dir1/dir1') expected_result = os.path.join(TEST_DIR, 'dir1', 'dir') eq_(expected_result, walkdir(TEST_DIR, terms=['dir', 'dir']))
def test_walkdir_with_fuzzy_names(): """Walkdir should support fuzzy finding for child dirs""" mkdir('dir1/filedir', 'dir1/filedir2') expected_result = os.path.join(TEST_DIR, 'dir1', 'filedir') eq_(expected_result, walkdir(TEST_DIR, terms=['dir', 'dir']))
def test_walkdir_without_existings_dirs_returns_rootdir(): """Calling walkdir without one existing dir as terms should returns rootdir""" mkdir('') # just rootdir assert not os.path.isdir(os.path.join(TEST_DIR, 'fake_dir1', 'fake_dir2')) expected_result = os.path.join(TEST_DIR, '') eq_(expected_result, walkdir(TEST_DIR, terms=['fake_dir2', 'fake_dir1']))
def test_walkdir_without_terms(): """Calling walkdir without terms should return the rootdir""" mkdir('') # just rootdir eq_(TEST_DIR, walkdir(TEST_DIR, terms=[]))