Ejemplo n.º 1
0
    def should_include(self, cpath: CPath):
        assert cpath.is_rel
        assert cpath.has_parent()
        # does the parent dir matcher group exist
        parent_cdir = CDir(cpath.get_cpath_info().get_parent())
        parent_matcher_group: Union[FsMatcherRootGroup, None] = self.__matcher_groups.get(parent_cdir.names, None)
        if parent_matcher_group is not None:
            # if parent says to exclude then look nothing beyond
            if parent_matcher_group.should_exclude(cpath):
                return False
        else:
            # look if any ancestor say that you should not match
            ancestor_cdir: CDir = parent_cdir
            while True:
                ancestor_cdir = ancestor_cdir.get_parent()
                ancestor_matcher_group: Union[FsMatcherGroup, None] = self.__matcher_groups.get(ancestor_cdir.names, None)
                if ancestor_matcher_group is not None:
                    if ancestor_matcher_group.should_exclude(cpath):
                        return False

                if ancestor_cdir.is_root():
                    break

        # No group asked to exclude, then include it
        return True
Ejemplo n.º 2
0
 def test_is_ancestor(self):
     # root dir root cannot play ancestor
     self.assertFalse(CPathUtils.is_ancestor(CDir(""), CDir("")))
     # ancestor must be dir
     self.assertRaises(CFSException, lambda: CPathUtils.is_ancestor(
         CPath("a"), CPath("a/b/c/d")))  # TODO: create proper exception
     self.assertRaises(
         CFSException,
         lambda: CPathUtils.is_ancestor(CFile("a", 1, 2), CPath("a/b/c/d")))
     # a dir is ancestor
     self.assertTrue(CPathUtils.is_ancestor(CPath("a/"), CPath("a/b/c/d")))
     # parent is also an ancestor
     self.assertTrue(
         CPathUtils.is_ancestor(CPath("a/b/c/"), CPath("a/b/c/d")))
     # not ancestor
     self.assertFalse(
         CPathUtils.is_ancestor(CDir("a/b"), CFile("x/y", 1, 1)))
Ejemplo n.º 3
0
 def test_is_parent(self):
     # root dir root cannot play parent child
     self.assertFalse(CPathUtils.is_parent(CDir(""), CDir("")))
     # parent must be dir
     self.assertRaises(
         CFSException,
         lambda: CPathUtils.is_parent(CPath("a"), CPath("a/b")))
     self.assertRaises(
         CFSException,
         lambda: CPathUtils.is_parent(CFile("a", 1, 2), CPath("a/b/")))
     # a dir is parent
     self.assertTrue(CPathUtils.is_parent(CPath("a/"), CPath("a/b")))
     self.assertTrue(CPathUtils.is_parent(CPath("a/b/"),
                                          CPath("a/b/c.txt")))
     # not parent
     self.assertFalse(
         CPathUtils.is_ancestor(CDir("a/b"), CFile("x/y", 1, 1)))
Ejemplo n.º 4
0
 def test_without_dev_matcher(self):
     matcher_group = FsMatcherGroup(CDir(""))
     self.assertFalse(matcher_group.should_exclude(CPath(".git/")))
     self.assertTrue(matcher_group.should_include(CPath(".git/")))
Ejemplo n.º 5
0
 def test_is_dir(self):
     cpath = CPath('/a/')
     cfile = CFile('/a', 1, 1)
     self.assertNotEqual(cpath.is_dir(), cfile.is_dir())
Ejemplo n.º 6
0
 def test_is_file(self):
     cpath = CPath('/a')
     cfile = CFile('/a', 1, 1)
     self.assertEqual(cpath.is_file(), cfile.is_file())
Ejemplo n.º 7
0
 def test_get_type(self):
     cpath = CPath("a/v")
     self.assertEqual(cpath.get_type(), CPathType.FILE)
     cfile = CFile("a/v", 1, 1)
     self.assertEqual(cfile.get_type(), CPathType.FILE)
Ejemplo n.º 8
0
 def test_get_type(self):
     cpath = CPath("a/")
     cdir = CDir("a")
     self.assertEqual(cpath.get_type(), cdir.get_type())
Ejemplo n.º 9
0
 def test_new(self):
     self.assertEqual(1, len(self.diff.new.get_leaves()))
     self.assertIsNotNone(self.diff.new.get(CPath("d3/p/y.txt")))
Ejemplo n.º 10
0
 def test_deleted(self):
     self.assertIsNotNone(self.diff.deleted.get(CPath("d2")))