def testParent(self): filepaths = [ ("foo", "0"), ("foo", "1"), ("foo", "bar", "0"), ("bar", "0"), ] with DirHierarchy(filepaths) as hierarchy: path = hierarchy(("foo", "*")) results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ hierarchy(("foo", "0")), hierarchy(("foo", "1")), hierarchy(("foo", "bar")), ]) path = hierarchy(("foo", os.path.pardir, "*")) results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ hierarchy(("foo", )), hierarchy(("bar", )), ])
def testMixed(self): filepaths = [ ("foo", "bar", "0"), ("norf", "bar", "0"), ("norf", "baz", "0"), ("norf", "baz", "1"), ("norf", "baz", "7"), ("quux", "bar", "0"), ("quux", "baz", "1"), ("quux", "baz", "2"), ] with DirHierarchy(filepaths) as hierarchy: path = hierarchy(("**", "ba?", "[0-2]")) results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ hierarchy(("foo", "bar", "0")), hierarchy(("norf", "bar", "0")), hierarchy(("norf", "baz", "0")), hierarchy(("norf", "baz", "1")), hierarchy(("quux", "bar", "0")), hierarchy(("quux", "baz", "1")), hierarchy(("quux", "baz", "2")), ])
def testGlobbingKeyDoesNotYieldDuplicates(self): opts = globbing.PathOpts(pathtype="REGISTRY") results = globbing.ExpandGlobs( r"HKEY_LOCAL_MACHINE\SOFTWARE\GRR_TEST\*\aaa", opts) self.assertCountEqual(results, [ r"HKEY_LOCAL_MACHINE\SOFTWARE\GRR_TEST\1\aaa", ])
def testCurrent(self): self.Touch("foo", "bar", "0") self.Touch("foo", "bar", "1") self.Touch("quux", "bar", "0") path = self.Path("foo", os.path.curdir, "bar", "*") results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ self.Path("foo", "bar", "0"), self.Path("foo", "bar", "1"), ]) path = self.Path(os.path.curdir, "*", "bar", "0") results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ self.Path("foo", "bar", "0"), self.Path("quux", "bar", "0"), ])
def testParent(self): self.Touch("foo", "0") self.Touch("foo", "1") self.Touch("foo", "bar", "0") self.Touch("bar", "0") path = self.Path("foo", "*") results = list(globbing.ExpandGlobs(path)) self.assertItemsEqual(results, [ self.Path("foo", "0"), self.Path("foo", "1"), self.Path("foo", "bar"), ]) path = self.Path("foo", os.path.pardir, "*") results = list(globbing.ExpandGlobs(path)) self.assertItemsEqual(results, [ self.Path("foo"), self.Path("bar"), ])
def testRecursion(self): self.Touch("foo", "bar", "baz", "0") self.Touch("foo", "bar", "0") self.Touch("foo", "quux", "0") self.Touch("foo", "quux", "1") path = self.Path("foo", "**", "0") results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ self.Path("foo", "bar", "baz", "0"), self.Path("foo", "bar", "0"), self.Path("foo", "quux", "0"), ])
def testWildcards(self): self.Touch("foo", "bar", "0") self.Touch("foo", "baz", "1") self.Touch("foo", "norf", "0") self.Touch("quux", "bar", "0") self.Touch("quux", "baz", "0") self.Touch("quux", "norf", "0") path = self.Path("*", "ba?", "0") results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ self.Path("foo", "bar", "0"), self.Path("quux", "bar", "0"), self.Path("quux", "baz", "0"), ])
def testRecursion(self): filepaths = [ ("foo", "bar", "baz", "0"), ("foo", "bar", "0"), ("foo", "quux", "0"), ("foo", "quux", "1"), ] with DirHierarchy(filepaths) as hierarchy: path = hierarchy(("foo", "**", "0")) results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ hierarchy(("foo", "bar", "baz", "0")), hierarchy(("foo", "bar", "0")), hierarchy(("foo", "quux", "0")), ])
def testMixed(self): self.Touch("foo", "bar", "0") self.Touch("norf", "bar", "0") self.Touch("norf", "baz", "0") self.Touch("norf", "baz", "1") self.Touch("norf", "baz", "7") self.Touch("quux", "bar", "0") self.Touch("quux", "baz", "1") self.Touch("quux", "baz", "2") path = self.Path("**", "ba?", "[0-2]") results = list(globbing.ExpandGlobs(path)) self.assertCountEqual(results, [ self.Path("foo", "bar", "0"), self.Path("norf", "bar", "0"), self.Path("norf", "baz", "0"), self.Path("norf", "baz", "1"), self.Path("quux", "bar", "0"), self.Path("quux", "baz", "1"), self.Path("quux", "baz", "2"), ])
def testRelative(self): with self.assertRaises(ValueError): list(globbing.ExpandGlobs(os.path.join("foo", "bar")))
def testEmpty(self): with self.assertRaises(ValueError): list(globbing.ExpandGlobs(""))