Exemple #1
0
    def testExplain(self):
        m = matchmod.treematcher("/",
                                 "",
                                 rules=["foo/bar", "!baz", "qux", "!qux"])
        self.assertEqual(m.explain("blah"), None)
        self.assertEqual(m.explain("baz"), "!baz")
        self.assertEqual(m.explain("qux"), "!qux")
        self.assertEqual(m.explain("foo/bar"), "foo/bar")

        m = matchmod.treematcher("/",
                                 "",
                                 rules=["foo/bar", "!baz"],
                                 ruledetails=["a", "b"])
        self.assertEqual(m.explain("blah"), None)
        self.assertEqual(m.explain("baz"), "!baz (b)")
        self.assertEqual(m.explain("foo/bar"), "foo/bar (a)")
Exemple #2
0
 def testManyPrefixes(self):
     n = 10000
     rules = ["a/b/c/d/e/f/g/%s/**" % i for i in range(n)]
     m = matchmod.treematcher("", "", rules=rules)
     self.assertTrue(m.visitdir("a"))
     self.assertTrue(m.visitdir("a/b"))
     self.assertEqual(m.visitdir("a/b/c/d/e/f/g/1"), "all")
     self.assertFalse(m.visitdir("b"))
     self.assertTrue(m("a/b/c/d/e/f/g/99/x"))
Exemple #3
0
 def testExplainUnion(self):
     m = matchmod.unionmatcher([
         matchmod.treematcher("/", "", rules=["f*"]),
         matchmod.treematcher("/", "", rules=["bar"]),
     ])
     self.assertEqual(m.explain("foo"), "f*")
Exemple #4
0
 def testManyGlobRaises(self):
     n = 10000
     rules = ["a/b/*/c/d/e/f/g/%s/**" % i for i in range(n)]
     with self.assertRaises(Exception):
         # "Compiled regex exceeds size limit of 10485760 bytes."
         matchmod.treematcher("", "", rules=rules)