コード例 #1
0
    def test_prune_regex(self):
        ff = fsfind.FsFinder(prune_rules=['level0-dir'])
        matches = list(ff.matches('level0-dir'))
        assert (len(matches) == 1)
        assert (matches[0].path == 'level0-dir')

        prune_rule = 'level2-dir1'
        ff = fsfind.FsFinder(prune_rules=[prune_rule])
        for match_result in ff.matches('level0-dir'):
            idx = match_result.path.find(prune_rule)
            if idx != -1:
                assert (all(x != os.sep for x in match_result.path[idx:]))
コード例 #2
0
    def test_ignore_regex(self):
        ff = fsfind.FsFinder(ignore_rules=['level0'])
        matches = list(ff.matches('level0-dir'))
        assert (len(matches) == 0)

        for i in range(1, len(self.paths_at_level)):
            ff = fsfind.FsFinder(ignore_rules=['level' + str(i)])
            matches = list(ff.matches('level0-dir'))

            for j in range(0, i):
                for path in self.paths_at_level[j]:
                    path = os.path.normpath(path)
                    assert (any(path == m.path for m in matches))
コード例 #3
0
 def test_prune_regexes(self):
     prune_rules = ['level1-dir2', 'level3-dir1']
     ff = fsfind.FsFinder(prune_rules=prune_rules)
     for match_result in ff.matches('level0-dir'):
         for rule in prune_rules:
             idx = match_result.path.find(rule)
             if idx != -1:
                 assert (all(x != os.sep for x in match_result.path[idx:]))
コード例 #4
0
    def test_match_regex(self):
        for i in range(len(self.paths_at_level)):
            ff = fsfind.FsFinder('level' + str(i))
            matches = list(ff.matches('level0-dir'))

            for j in range(i, len(self.paths_at_level)):
                for path in self.paths_at_level[j]:
                    path = os.path.normpath(path)
                    assert (any(['level' + str(i)] == m.match_info
                                for m in matches))
コード例 #5
0
    def test_max_depth(self):
        for i in range(len(self.paths_at_level)):
            ff = fsfind.FsFinder(depth=(0, i))
            matches = list(ff.matches('level0-dir'))

            total_paths = 0
            for j in range(0, i + 1):
                total_paths += len(self.paths_at_level[j])
                for path in self.paths_at_level[j]:
                    assert (any(path == m.path for m in matches))

            assert (len(matches) == total_paths)
コード例 #6
0
    def test_min_depth(self):
        for i in range(len(self.paths_at_level)):
            ff = fsfind.FsFinder(depth=(i, None))
            matches = list(ff.matches('level0-dir'))

            total_paths = 0
            for j in range(i, len(self.paths_at_level)):
                total_paths += len(self.paths_at_level[j])
                for path in self.paths_at_level[j]:
                    assert (any(path == m.path for m in matches))

            if len(matches) != total_paths:
                print(i)
                print([m.path for m in matches])
            assert (len(matches) == total_paths)
コード例 #7
0
 def test_sorting(self):
     ff = fsfind.FsFinder(sort=True)
     matched_paths = [m.path for m in ff.matches('.')]
     assert matched_paths == self.dfs_sorted
コード例 #8
0
 def test_ignore_regexes(self):
     ignore_rules = ['level2-file1', '.+' + os.sep + 'level3-dir1$']
     ff = fsfind.FsFinder(ignore_rules=ignore_rules)
     for match_result in ff.matches('level0-dir'):
         assert (not os.path.basename(match_result.path)
                 in ['level2-file1', 'level3-dir1'])