Esempio n. 1
0
def test_fnmatch():
    """ Test fnmatch parameter."""
    # find all files and directories
    paths = pathfind(BASEPATH, fnmatch="*")
    assert len(paths) == 16
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
    assert join(BASEPATH, 'dir3', 'file8') in paths
    assert join(BASEPATH, 'dir3', '.file9') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths

    # find only files or directories with a .txt extension
    paths = pathfind(BASEPATH, fnmatch="*.txt")
    assert len(paths) == 4
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
Esempio n. 2
0
    def test_fnmatch(self):
        """ Test fnmatch parameter."""
        # find all files and directories
        paths = pathfind(BASEPATH, fnmatch="*")
        self.assertEqual(22, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file2.dat') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file3.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo.gif') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.gif') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.jpg') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'transparent_gs.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file5.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file6.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file7.html') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3', 'file8') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3', '.file9') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4', 'file10') in paths)

        # find only files or directories with a .txt extension
        paths = pathfind(BASEPATH, fnmatch="*.txt")
        self.assertEqual(4, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file3.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths)
Esempio n. 3
0
    def test_ignore(self):
        """ Test ignore parameter."""
        # find all directories and all files and directories 
        # with a 2 in the path and no directories that begin
        # with a dot
        filt = OrFilter(DirectoryFilter(), RegexFilter('.*2.*'))
        ignore = DotDirectoryFilter()
        paths = pathfind(BASEPATH, filter=filt, ignore=ignore)
        self.assertEqual(7, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file2.dat') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file6.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file7.html') in paths)

        filt = FnmatchFilter("*.txt")
        ignore = FnmatchFilter("*4.txt")

        all_paths = pathfind(BASEPATH, filter=filt)
        self.assertEqual(4, len(all_paths))
        self.assertTrue("4.txt" in " ".join(all_paths))

        ignore_paths = pathfind(BASEPATH, filter=filt, ignore=ignore)
        self.assertEqual(3, len(ignore_paths))
        self.assertFalse("4.txt" in " ".join(ignore_paths))
Esempio n. 4
0
def test_fnmatch():
    """ Test fnmatch parameter."""
    # find all files and directories
    paths = pathfind(BASEPATH, fnmatch="*")
    assert len(paths) == 16
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
    assert join(BASEPATH, 'dir3', 'file8') in paths
    assert join(BASEPATH, 'dir3', '.file9') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths

    # find only files or directories with a .txt extension
    paths = pathfind(BASEPATH, fnmatch="*.txt")
    assert len(paths) == 4
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
Esempio n. 5
0
    def test_depth(self):
        """ Only descend a certain depth into a tree."""
        paths = pathfind(BASEPATH, filter=DirectoryFilter(), depth=1)
        self.assertEqual(4, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4') in paths)

        paths = pathfind(BASEPATH, filter=DirectoryFilter(), depth=2)
        self.assertEqual(5, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)
Esempio n. 6
0
    def test_regex(self):
        """ Test regex parameter."""
        # find all files and directories
        paths = pathfind(BASEPATH, regex=".*")
        self.assertEqual(22, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file2.dat') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file3.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo.gif') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.gif') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.jpg') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'transparent_gs.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file5.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file6.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file7.html') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3', 'file8') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3', '.file9') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4', 'file10') in paths)

        # use Filter.find
        paths_2 = RegexFilter('.*').find(BASEPATH)
        self.assertEqual(paths, paths_2)

        # find only files and directories with a t in the extension
        paths = pathfind(BASEPATH, regex=".*\..*t.*$")
        self.assertEqual(6, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file2.dat') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file3.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file7.html') in paths)

        # find only files and directories with 1 anywhere in the path
        paths = pathfind(BASEPATH, regex=".*1.*")
        self.assertTrue(7, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file5.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4', 'file10') in paths)
Esempio n. 7
0
def test_depth():
    """ Test depth parameter."""
    # only descend the tree to one level of subdirectories
    paths = pathfind(BASEPATH, filter=DirectoryFilter(), depth=1)
    assert len(paths) == 4
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths

    paths = pathfind(BASEPATH, filter=DirectoryFilter(), depth=2)
    assert len(paths) == 5
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
Esempio n. 8
0
def test_depth():
    """ Test depth parameter."""
    # only descend the tree to one level of subdirectories
    paths = pathfind(BASEPATH, filter=DirectoryFilter(), depth=1)
    assert len(paths) == 4
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths

    paths = pathfind(BASEPATH, filter=DirectoryFilter(), depth=2)
    assert len(paths) == 5
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
Esempio n. 9
0
    def test_abspath(self):
        """ Make sure all paths are absolute paths."""
        cwd = os.getcwd()
        paths = pathfind(BASEPATH, filter=DirectoryFilter(), abspath=True)
        self.assertEqual(5, len(paths))
        self.assertTrue(os.path.join(cwd, BASEPATH, 'dir1') in paths)
        self.assertTrue(os.path.join(cwd, BASEPATH, 'dir1', 'subdirectory') in paths)
        self.assertTrue(os.path.join(cwd, BASEPATH, 'dir2') in paths)
        self.assertTrue(os.path.join(cwd, BASEPATH, 'dir3') in paths)
        self.assertTrue(os.path.join(cwd, BASEPATH, '.dir4') in paths)

        paths = pathfind(BASEPATH, just_files=True, abspath=True)
        self.assertEqual(17, len(paths))
        self.assertTrue(os.path.join(cwd, BASEPATH, 'python_logo.png') in paths)
Esempio n. 10
0
    def test_and(self):
        """ Test AndFilter."""
        # find directories with a 2 anywhere in the path
        filt = AndFilter(DirectoryFilter(), RegexFilter('.*2.*'))
        paths = pathfind(BASEPATH, filter=filt)
        self.assertEqual(1, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths)

        # test overridden __and__
        filt = DirectoryFilter() & RegexFilter('.*2.*')
        paths_2 = pathfind(BASEPATH, filter=filt)
        self.assertEqual(paths, paths_2)

        # use Filter.find
        paths_3 = AndFilter(DirectoryFilter(), RegexFilter('.*2.*')).find(BASEPATH)
        self.assertEqual(paths, paths_3)
Esempio n. 11
0
 def test_all(self):
     """ Test with no parameters. """
     # find all paths
     paths = pathfind(BASEPATH)
     self.assertEqual(22, len(paths))
     self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir3') in paths)
     self.assertTrue(os.path.join(BASEPATH, '.dir4') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'file2.dat') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'file3.txt') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'python_logo.gif') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'python_logo.png') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.gif') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.jpg') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.png') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'transparent_gs.png') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file5.log') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file6.log') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file7.html') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir3', 'file8') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir3', '.file9') in paths)
Esempio n. 12
0
def test_and():
    """ Test AndFilter."""
    # find directories with a 2 anywhere in the path
    filt = AndFilter(DirectoryFilter(), RegexFilter('.*2.*'))
    paths = pathfind(BASEPATH, filter=filt)
    assert len(paths) == 1
    assert join(BASEPATH, 'dir2') in paths
Esempio n. 13
0
def test_and():
    """ Test AndFilter."""
    # find directories with a 2 anywhere in the path
    filt = AndFilter(DirectoryFilter(), RegexFilter('.*2.*'))
    paths = pathfind(BASEPATH, filter=filt)
    assert len(paths) == 1
    assert join(BASEPATH, 'dir2') in paths
Esempio n. 14
0
    def test_just_files(self):
        """ Test just_files parameter."""
        # only find files
        paths = pathfind(BASEPATH, just_files=True)
        self.assertEqual(17, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file2.dat') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file3.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo.gif') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.gif') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.jpg') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'transparent_gs.png') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file5.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file6.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file7.html') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3', 'file8') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3', '.file9') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4', 'file10') in paths)

        # use Filter.find
        paths_2 = FileFilter().find(BASEPATH)
        self.assertEqual(paths, paths_2)
Esempio n. 15
0
def test_just_dirs():
    """ Test just_dirs parameter."""
    # only find directories
    paths = pathfind(BASEPATH, just_dirs=True)
    assert len(paths) == 5
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
Esempio n. 16
0
def test_not():
    """ Test NotFilter."""
    # find all files and directories with a .txt extension
    # except ones that end in 3.txt
    filt = AndFilter(NotFilter(FnmatchFilter('*3.txt')), FnmatchFilter('*.txt'))
    paths = pathfind(BASEPATH, filter=filt)
    assert len(paths) == 3
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
Esempio n. 17
0
def test_just_dirs():
    """ Test just_dirs parameter."""
    # only find directories
    paths = pathfind(BASEPATH, just_dirs=True)
    assert len(paths) == 5
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
Esempio n. 18
0
 def test_not(self):
     """ Test NotFilter."""
     # find all files and directories with a .txt extension
     # except ones that end in 3.txt
     filt = AndFilter(NotFilter(FnmatchFilter('*3.txt')), FnmatchFilter('*.txt'))
     paths = pathfind(BASEPATH, filter=filt)
     self.assertEqual(3, len(paths))
     self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths)
     self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths)
Esempio n. 19
0
def test_regex():
    """ Test regex parameter."""
    # find all files and directories
    paths = pathfind(BASEPATH, regex=".*")
    assert len(paths) == 16
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
    assert join(BASEPATH, 'dir3', 'file8') in paths
    assert join(BASEPATH, 'dir3', '.file9') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths

    # find only files and directories with a t in the extension
    paths = pathfind(BASEPATH, regex=".*\..*t.*$")
    assert len(paths) == 6
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths

    # find only files and directories with 1 anywhere in the path
    paths = pathfind(BASEPATH, regex=".*1.*")
    assert len(paths) == 7
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths
Esempio n. 20
0
def test_regex():
    """ Test regex parameter."""
    # find all files and directories
    paths = pathfind(BASEPATH, regex=".*")
    assert len(paths) == 16
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
    assert join(BASEPATH, 'dir3', 'file8') in paths
    assert join(BASEPATH, 'dir3', '.file9') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths

    # find only files and directories with a t in the extension
    paths = pathfind(BASEPATH, regex=".*\..*t.*$")
    assert len(paths) == 6
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths

    # find only files and directories with 1 anywhere in the path
    paths = pathfind(BASEPATH, regex=".*1.*")
    assert len(paths) == 7
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths
Esempio n. 21
0
def test_abspath():
    """ Test abspath parameter."""
    # test that absolute paths are returned
    cwd = os.getcwd()
    paths = pathfind(BASEPATH, filter=DirectoryFilter(), abspath=True)
    assert len(paths) == 5
    assert join(cwd, BASEPATH, 'dir1') in paths
    assert join(cwd, BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(cwd, BASEPATH, 'dir2') in paths
    assert join(cwd, BASEPATH, 'dir3') in paths
    assert join(cwd, BASEPATH, '.dir4') in paths
Esempio n. 22
0
def test_abspath():
    """ Test abspath parameter."""
    # test that absolute paths are returned
    cwd = os.getcwd()
    paths = pathfind(BASEPATH, filter=DirectoryFilter(), abspath=True)
    assert len(paths) == 5
    assert join(cwd, BASEPATH, 'dir1') in paths
    assert join(cwd, BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(cwd, BASEPATH, 'dir2') in paths
    assert join(cwd, BASEPATH, 'dir3') in paths
    assert join(cwd, BASEPATH, '.dir4') in paths
Esempio n. 23
0
    def __init__(self, watch_dir, *args, **kwargs):
        """
        Store the directory we are watching and set up the
        dependency store.
        """
        self.dependencies = {}
        self._dependencies(pathfind(watch_dir, abspath=True, fnmatch="*.less"))

        kwargs['patterns'] = ["*.less"]
        kwargs['ignore_directories'] = True
        super(LessEventHandler, self).__init__(*args, **kwargs)
Esempio n. 24
0
def test_not():
    """ Test NotFilter."""
    # find all files and directories with a .txt extension
    # except ones that end in 3.txt
    filt = AndFilter(NotFilter(FnmatchFilter('*3.txt')),
                     FnmatchFilter('*.txt'))
    paths = pathfind(BASEPATH, filter=filt)
    assert len(paths) == 3
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
Esempio n. 25
0
    def test_just_dirs(self):
        """ Test just_dirs parameter."""
        # only find directories
        paths = pathfind(BASEPATH, just_dirs=True)
        self.assertEqual(5, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4') in paths)

        # use Filter.find
        paths_2 = DirectoryFilter().find(BASEPATH)
        self.assertEqual(paths, paths_2)
Esempio n. 26
0
    def test_or(self):
        """ Test OrFilter."""
        # find all directories and any files (or directories)
        # with 2 in the path
        filt = OrFilter(DirectoryFilter(), RegexFilter('.*2.*'))
        paths = pathfind(BASEPATH, filter=filt)
        self.assertEqual(8, len(paths))
        self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir3') in paths)
        self.assertTrue(os.path.join(BASEPATH, '.dir4') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'file2.dat') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file6.log') in paths)
        self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file7.html') in paths)

        # test overridden __or__
        filt = DirectoryFilter() | RegexFilter('.*2.*')
        paths_2 = pathfind(BASEPATH, filter=filt)
        self.assertEqual(paths, paths_2)

        # use Filter.find
        paths_3 = OrFilter(DirectoryFilter(), RegexFilter('.*2.*')).find(BASEPATH)
        self.assertEqual(paths, paths_3)
Esempio n. 27
0
def test_or():
    """ Test OrFilter."""
    # find all directories and any files (or directories)
    # with 2 in the path
    filt = OrFilter(DirectoryFilter(), RegexFilter('.*2.*'))
    paths = pathfind(BASEPATH, filter=filt)
    assert len(paths) == 8
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
Esempio n. 28
0
def test_or():
    """ Test OrFilter."""
    # find all directories and any files (or directories)
    # with 2 in the path
    filt = OrFilter(DirectoryFilter(), RegexFilter('.*2.*'))
    paths = pathfind(BASEPATH, filter=filt)
    assert len(paths) == 8
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
Esempio n. 29
0
def test_ignore():
    """ Test ignore parameter."""
    # find all directories and all files and directories 
    # with a 2 in the path and no directories that begin
    # with a dot
    filt = OrFilter(DirectoryFilter(), RegexFilter('.*2.*'))
    ignore = DotDirectoryFilter()
    paths = pathfind(BASEPATH, filter=filt, ignore=ignore)
    assert len(paths) == 7
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
Esempio n. 30
0
def test_just_files():
    """ Test just_files parameter."""
    # only find files
    paths = pathfind(BASEPATH, just_files=True)
    assert len(paths) == 11
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
    assert join(BASEPATH, 'dir3', 'file8') in paths
    assert join(BASEPATH, 'dir3', '.file9') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths
Esempio n. 31
0
def test_ignore():
    """ Test ignore parameter."""
    # find all directories and all files and directories
    # with a 2 in the path and no directories that begin
    # with a dot
    filt = OrFilter(DirectoryFilter(), RegexFilter('.*2.*'))
    ignore = DotDirectoryFilter()
    paths = pathfind(BASEPATH, filter=filt, ignore=ignore)
    assert len(paths) == 7
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
Esempio n. 32
0
def test_just_files():
    """ Test just_files parameter."""
    # only find files
    paths = pathfind(BASEPATH, just_files=True)
    assert len(paths) == 11
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
    assert join(BASEPATH, 'dir3', 'file8') in paths
    assert join(BASEPATH, 'dir3', '.file9') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths
Esempio n. 33
0
def test_all():
    """ Test with no parameters. """
    # find all paths
    paths = pathfind(BASEPATH)
    assert len(paths) == 16
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
    assert join(BASEPATH, 'dir3', 'file8') in paths
    assert join(BASEPATH, 'dir3', '.file9') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths
Esempio n. 34
0
def test_all():
    """ Test with no parameters. """
    # find all paths
    paths = pathfind(BASEPATH)
    assert len(paths) == 16
    assert join(BASEPATH, 'dir1') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory') in paths
    assert join(BASEPATH, 'dir2') in paths
    assert join(BASEPATH, 'dir3') in paths
    assert join(BASEPATH, '.dir4') in paths
    assert join(BASEPATH, 'file1.txt') in paths
    assert join(BASEPATH, 'file2.dat') in paths
    assert join(BASEPATH, 'file3.txt') in paths
    assert join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths
    assert join(BASEPATH, 'dir1', 'file4.txt') in paths
    assert join(BASEPATH, 'dir1', 'file5.log') in paths
    assert join(BASEPATH, 'dir2', 'file6.log') in paths
    assert join(BASEPATH, 'dir2', 'file7.html') in paths
    assert join(BASEPATH, 'dir3', 'file8') in paths
    assert join(BASEPATH, 'dir3', '.file9') in paths
    assert join(BASEPATH, '.dir4', 'file10') in paths
Esempio n. 35
0
 def test_find_filepath(self):
     """ Test when the root path to a find is a file and not a directory. """
     a_paths = pathfind(os.path.join(BASEPATH, 'python_logo.png'), just_files=True)
     b_paths = pathfind(BASEPATH, just_files=True)
     self.assertEqual(a_paths, b_paths)