Ejemplo n.º 1
0
    def testFollowLinks(self):
        self.Touch("foo", "0")
        self.Touch("foo", "bar", "0")
        self.Touch("foo", "baz", "0")
        self.Touch("foo", "baz", "1")
        self.Touch("quux", "0")
        self.Touch("norf", "0")
        os.symlink(self.Path("foo", "bar"), self.Path("quux", "bar"))
        os.symlink(self.Path("foo", "baz"), self.Path("quux", "baz"))
        os.symlink(self.Path("quux"), self.Path("norf", "quux"))

        opts = globbing.PathOpts(follow_links=True)
        component = globbing.RecursiveComponent(opts=opts)

        # It should resolve two links and recur to linked directories.
        results = list(component.Generate(self.Path("quux")))
        self.assertCountEqual(results, [
            self.Path("quux", "0"),
            self.Path("quux", "bar"),
            self.Path("quux", "bar", "0"),
            self.Path("quux", "baz"),
            self.Path("quux", "baz", "0"),
            self.Path("quux", "baz", "1"),
        ])

        # It should resolve symlinks recursively.
        results = list(component.Generate(self.Path("norf")))
        self.assertCountEqual(results, [
            self.Path("norf", "0"),
            self.Path("norf", "quux"),
            self.Path("norf", "quux", "0"),
            self.Path("norf", "quux", "bar"),
            self.Path("norf", "quux", "bar", "0"),
            self.Path("norf", "quux", "baz"),
            self.Path("norf", "quux", "baz", "0"),
            self.Path("norf", "quux", "baz", "1"),
        ])

        opts = globbing.PathOpts(follow_links=False)
        component = globbing.RecursiveComponent(opts=opts)

        # It should list symlinks but should not recur to linked directories.
        results = list(component.Generate(self.Path()))
        self.assertCountEqual(results, [
            self.Path("foo"),
            self.Path("foo", "0"),
            self.Path("foo", "bar"),
            self.Path("foo", "bar", "0"),
            self.Path("foo", "baz"),
            self.Path("foo", "baz", "0"),
            self.Path("foo", "baz", "1"),
            self.Path("quux"),
            self.Path("quux", "0"),
            self.Path("quux", "bar"),
            self.Path("quux", "baz"),
            self.Path("norf"),
            self.Path("norf", "0"),
            self.Path("norf", "quux"),
        ])
Ejemplo n.º 2
0
    def testMaxDepth(self):
        filepaths = [
            ("foo", "0"),
            ("foo", "1"),
            ("foo", "bar", "0"),
            ("foo", "bar", "baz", "0"),
        ]

        component = globbing.RecursiveComponent(max_depth=3)

        with DirHierarchy(filepaths) as hierarchy:
            results = list(component.Generate(hierarchy(())))

            # Files at level lesser than 3 should be included.
            self.assertIn(hierarchy(("foo", )), results)
            self.assertIn(hierarchy(("foo", "0")), results)
            self.assertIn(hierarchy(("foo", "1")), results)
            self.assertIn(hierarchy(("foo", "bar")), results)

            # Files at level equal to 3 should be included.
            self.assertIn(hierarchy(("foo", "bar", "0")), results)
            self.assertIn(hierarchy(("foo", "bar", "baz")), results)

            # Files at level bigger that 3 should not be included.
            self.assertNotIn(hierarchy(("foo", "bar", "baz", "0")), results)
Ejemplo n.º 3
0
    def testIgnore(self):
        self.Touch("foo", "0")
        self.Touch("foo", "1")
        self.Touch("foo", "bar", "0")
        self.Touch("bar", "0")
        self.Touch("bar", "quux", "0")
        self.Touch("bar", "quux", "1")
        self.Touch("baz", "0")
        self.Touch("baz", "1")
        self.Touch("baz", "quux", "0")

        opts = globbing.PathOpts(recursion_blacklist=[
            self.Path("foo"),
            self.Path("bar", "quux"),
        ])
        component = globbing.RecursiveComponent(opts=opts)

        results = list(component.Generate(self.Path()))

        # Recursion should not visit into the blacklisted folders.
        self.assertNotIn(self.Path("foo", "0"), results)
        self.assertNotIn(self.Path("foo", "1"), results)
        self.assertNotIn(self.Path("bar", "quux", "0"), results)
        self.assertNotIn(self.Path("bar", "quux", "1"), results)

        # Blacklisted folders themselves should appear in the results.
        self.assertIn(self.Path("foo"), results)
        self.assertIn(self.Path("bar", "quux"), results)

        # Recursion should visit not blacklisted folders.
        self.assertIn(self.Path("baz"), results)
        self.assertIn(self.Path("baz", "0"), results)
        self.assertIn(self.Path("baz", "1"), results)
        self.assertIn(self.Path("baz", "quux"), results)
        self.assertIn(self.Path("baz", "quux", "0"), results)
Ejemplo n.º 4
0
    def testSimple(self):
        filepaths = [
            ("foo", "0"),
            ("foo", "1"),
            ("foo", "bar", "0"),
            ("baz", "0"),
            ("baz", "1"),
        ]

        component = globbing.RecursiveComponent()

        with DirHierarchy(filepaths) as hierarchy:
            results = list(component.Generate(hierarchy(())))
            self.assertCountEqual(results, [
                hierarchy(("foo", )),
                hierarchy(("foo", "0")),
                hierarchy(("foo", "1")),
                hierarchy(("foo", "bar")),
                hierarchy(("foo", "bar", "0")),
                hierarchy(("baz", )),
                hierarchy(("baz", "0")),
                hierarchy(("baz", "1")),
            ])

            results = list(component.Generate(hierarchy(("foo", ))))
            self.assertCountEqual(results, [
                hierarchy(("foo", "0")),
                hierarchy(("foo", "1")),
                hierarchy(("foo", "bar")),
                hierarchy(("foo", "bar", "0")),
            ])

            results = list(component.Generate(hierarchy(("baz", ))))
            self.assertCountEqual(results, [
                hierarchy(("baz", "0")),
                hierarchy(("baz", "1")),
            ])

            results = list(component.Generate(hierarchy(("foo", "bar"))))
            self.assertCountEqual(results, [
                hierarchy(("foo", "bar", "0")),
            ])
Ejemplo n.º 5
0
    def testMaxDepth(self):
        self.Touch("foo", "0")
        self.Touch("foo", "1")
        self.Touch("foo", "bar", "0")
        self.Touch("foo", "bar", "baz", "0")

        component = globbing.RecursiveComponent(max_depth=3)

        results = list(component.Generate(self.Path()))

        # Files at level lesser than 3 should be included.
        self.assertIn(self.Path("foo"), results)
        self.assertIn(self.Path("foo", "0"), results)
        self.assertIn(self.Path("foo", "1"), results)
        self.assertIn(self.Path("foo", "bar"), results)

        # Files at level equal to 3 should be included.
        self.assertIn(self.Path("foo", "bar", "0"), results)
        self.assertIn(self.Path("foo", "bar", "baz"), results)

        # Files at level bigger that 3 should not be included.
        self.assertNotIn(self.Path("foo", "bar", "baz", "0"), results)
Ejemplo n.º 6
0
    def testSimple(self):
        self.Touch("foo", "0")
        self.Touch("foo", "1")
        self.Touch("foo", "bar", "0")
        self.Touch("baz", "0")
        self.Touch("baz", "1")

        component = globbing.RecursiveComponent()

        results = list(component.Generate(self.Path()))
        self.assertCountEqual(results, [
            self.Path("foo"),
            self.Path("foo", "0"),
            self.Path("foo", "1"),
            self.Path("foo", "bar"),
            self.Path("foo", "bar", "0"),
            self.Path("baz"),
            self.Path("baz", "0"),
            self.Path("baz", "1"),
        ])

        results = list(component.Generate(self.Path("foo")))
        self.assertCountEqual(results, [
            self.Path("foo", "0"),
            self.Path("foo", "1"),
            self.Path("foo", "bar"),
            self.Path("foo", "bar", "0"),
        ])

        results = list(component.Generate(self.Path("baz")))
        self.assertCountEqual(results, [
            self.Path("baz", "0"),
            self.Path("baz", "1"),
        ])

        results = list(component.Generate(self.Path("foo", "bar")))
        self.assertCountEqual(results, [
            self.Path("foo", "bar", "0"),
        ])
Ejemplo n.º 7
0
    def testIgnore(self):
        filepaths = [
            ("foo", "0"),
            ("foo", "1"),
            ("foo", "bar", "0"),
            ("bar", "0"),
            ("bar", "quux", "0"),
            ("bar", "quux", "1"),
            ("baz", "0"),
            ("baz", "1"),
            ("baz", "quux", "0"),
        ]

        with DirHierarchy(filepaths) as hierarchy:
            opts = globbing.PathOpts(recursion_blacklist=[
                hierarchy(("foo", )),
                hierarchy(("bar", "quux")),
            ])
            component = globbing.RecursiveComponent(opts=opts)

            results = list(component.Generate(hierarchy(())))

            # Recursion should not visit into the blacklisted folders.
            self.assertNotIn(hierarchy(("foo", "0")), results)
            self.assertNotIn(hierarchy(("foo", "1")), results)
            self.assertNotIn(hierarchy(("bar", "quux", "0")), results)
            self.assertNotIn(hierarchy(("bar", "quux", "1")), results)

            # Blacklisted folders themselves should appear in the results.
            self.assertIn(hierarchy(("foo", )), results)
            self.assertIn(hierarchy(("bar", "quux")), results)

            # Recursion should visit not blacklisted folders.
            self.assertIn(hierarchy(("baz", )), results)
            self.assertIn(hierarchy(("baz", "0")), results)
            self.assertIn(hierarchy(("baz", "1")), results)
            self.assertIn(hierarchy(("baz", "quux")), results)
            self.assertIn(hierarchy(("baz", "quux", "0")), results)
Ejemplo n.º 8
0
    def testFollowLinks(self):
        filepaths = [
            ("foo", "0"),
            ("foo", "bar", "0"),
            ("foo", "baz", "0"),
            ("foo", "baz", "1"),
            ("quux", "0"),
            ("norf", "0"),
        ]

        with DirHierarchy(filepaths) as hierarchy:
            os.symlink(hierarchy(("foo", "bar")), hierarchy(("quux", "bar")))
            os.symlink(hierarchy(("foo", "baz")), hierarchy(("quux", "baz")))
            os.symlink(hierarchy(("quux", )), hierarchy(("norf", "quux")))

            opts = globbing.PathOpts(follow_links=True)
            component = globbing.RecursiveComponent(opts=opts)

            # It should resolve two links and recur to linked directories.
            results = list(component.Generate(hierarchy(("quux", ))))
            self.assertCountEqual(results, [
                hierarchy(("quux", "0")),
                hierarchy(("quux", "bar")),
                hierarchy(("quux", "bar", "0")),
                hierarchy(("quux", "baz")),
                hierarchy(("quux", "baz", "0")),
                hierarchy(("quux", "baz", "1")),
            ])

            # It should resolve symlinks recursively.
            results = list(component.Generate(hierarchy(("norf", ))))
            self.assertCountEqual(results, [
                hierarchy(("norf", "0")),
                hierarchy(("norf", "quux")),
                hierarchy(("norf", "quux", "0")),
                hierarchy(("norf", "quux", "bar")),
                hierarchy(("norf", "quux", "bar", "0")),
                hierarchy(("norf", "quux", "baz")),
                hierarchy(("norf", "quux", "baz", "0")),
                hierarchy(("norf", "quux", "baz", "1")),
            ])

            opts = globbing.PathOpts(follow_links=False)
            component = globbing.RecursiveComponent(opts=opts)

            # It should list symlinks but should not recur to linked directories.
            results = list(component.Generate(hierarchy(())))
            self.assertCountEqual(results, [
                hierarchy(("foo", )),
                hierarchy(("foo", "0")),
                hierarchy(("foo", "bar")),
                hierarchy(("foo", "bar", "0")),
                hierarchy(("foo", "baz")),
                hierarchy(("foo", "baz", "0")),
                hierarchy(("foo", "baz", "1")),
                hierarchy(("quux", )),
                hierarchy(("quux", "0")),
                hierarchy(("quux", "bar")),
                hierarchy(("quux", "baz")),
                hierarchy(("norf", )),
                hierarchy(("norf", "0")),
                hierarchy(("norf", "quux")),
            ])
Ejemplo n.º 9
0
    def testInvalidDirpath(self):
        component = globbing.RecursiveComponent()

        results = list(component.Generate("/foo/bar/baz"))
        self.assertCountEqual(results, [])