示例#1
0
 def test_generate_matches(self):
     la = pytree.Leaf(1, "a")
     lb = pytree.Leaf(1, "b")
     lc = pytree.Leaf(1, "c")
     ld = pytree.Leaf(1, "d")
     le = pytree.Leaf(1, "e")
     lf = pytree.Leaf(1, "f")
     leaves = [la, lb, lc, ld, le, lf]
     root = pytree.Node(1000, leaves)
     pa = pytree.LeafPattern(1, "a", "pa")
     pb = pytree.LeafPattern(1, "b", "pb")
     pc = pytree.LeafPattern(1, "c", "pc")
     pd = pytree.LeafPattern(1, "d", "pd")
     pe = pytree.LeafPattern(1, "e", "pe")
     pf = pytree.LeafPattern(1, "f", "pf")
     pw = pytree.WildcardPattern(
         [[pa, pb, pc], [pd, pe], [pa, pb], [pc, pd], [pe, pf]],
         min=1,
         max=4,
         name="pw")
     self.assertEqual([x[0] for x in pw.generate_matches(leaves)],
                      [3, 5, 2, 4, 6])
     pr = pytree.NodePattern(type=1000, content=[pw], name="pr")
     matches = list(pytree.generate_matches([pr], [root]))
     self.assertEqual(len(matches), 1)
     c, r = matches[0]
     self.assertEqual(c, 1)
     self.assertEqual(str(r["pr"]), "abcdef")
     self.assertEqual(r["pw"], [la, lb, lc, ld, le, lf])
     for c in "abcdef":
         self.assertEqual(r["p" + c], pytree.Leaf(1, c))
示例#2
0
 def test_generate_matches(self):
     la = pytree.Leaf(1, 'a')
     lb = pytree.Leaf(1, 'b')
     lc = pytree.Leaf(1, 'c')
     ld = pytree.Leaf(1, 'd')
     le = pytree.Leaf(1, 'e')
     lf = pytree.Leaf(1, 'f')
     leaves = [la, lb, lc, ld, le, lf]
     root = pytree.Node(1000, leaves)
     pa = pytree.LeafPattern(1, 'a', 'pa')
     pb = pytree.LeafPattern(1, 'b', 'pb')
     pc = pytree.LeafPattern(1, 'c', 'pc')
     pd = pytree.LeafPattern(1, 'd', 'pd')
     pe = pytree.LeafPattern(1, 'e', 'pe')
     pf = pytree.LeafPattern(1, 'f', 'pf')
     pw = pytree.WildcardPattern(
         [[pa, pb, pc], [pd, pe], [pa, pb], [pc, pd], [pe, pf]],
         min=1,
         max=4,
         name='pw')
     self.assertEqual([x[0] for x in pw.generate_matches(leaves)],
                      [3, 5, 2, 4, 6])
     pr = pytree.NodePattern(type=1000, content=[pw], name='pr')
     matches = list(pytree.generate_matches([pr], [root]))
     self.assertEqual(len(matches), 1)
     c, r = matches[0]
     self.assertEqual(c, 1)
     self.assertEqual(str(r['pr']), 'abcdef')
     self.assertEqual(r['pw'], [la, lb, lc, ld, le, lf])
     for c in 'abcdef':
         self.assertEqual(r['p' + c], pytree.Leaf(1, c))
示例#3
0
 def test_generate_matches(self):
     la = pytree.Leaf(1, "a")
     lb = pytree.Leaf(1, "b")
     lc = pytree.Leaf(1, "c")
     ld = pytree.Leaf(1, "d")
     le = pytree.Leaf(1, "e")
     lf = pytree.Leaf(1, "f")
     leaves = [la, lb, lc, ld, le, lf]
     root = pytree.Node(1000, leaves)
     pa = pytree.LeafPattern(1, "a", "pa")
     pb = pytree.LeafPattern(1, "b", "pb")
     pc = pytree.LeafPattern(1, "c", "pc")
     pd = pytree.LeafPattern(1, "d", "pd")
     pe = pytree.LeafPattern(1, "e", "pe")
     pf = pytree.LeafPattern(1, "f", "pf")
     pw = pytree.WildcardPattern([[pa, pb, pc], [pd, pe],
                                  [pa, pb], [pc, pd], [pe, pf]],
                                 min=1, max=4, name="pw")
     self.assertEqual([x[0] for x in pw.generate_matches(leaves)],
                      [3, 5, 2, 4, 6])
     pr = pytree.NodePattern(type=1000, content=[pw], name="pr")
     matches = list(pytree.generate_matches([pr], [root]))
     self.assertEqual(len(matches), 1)
     c, r = matches[0]
     self.assertEqual(c, 1)
     self.assertEqual(str(r["pr"]), "abcdef")
     self.assertEqual(r["pw"], [la, lb, lc, ld, le, lf])
     for c in "abcdef":
         self.assertEqual(r["p" + c], pytree.Leaf(1, c))