def test_07(self): """wildcard tree matching""" global in_test # Test(.b = *) -> #checkMatch; def checkMatch(tree: Node, user_data, nodes): global in_test in_test = True tree.is_rewrited = True m = MatchBlock([ MatchHook(checkMatch, MatchType(Test, [MatchAttr('b')])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t[0], "is_rewrited"), "Failed to rewrite a node") self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # L([2: *]) -> #checkMatch; def checkMatch(tree: Node, user_data, nodes): global in_test in_test = True # nodes[0] == nodes[-1] on root node if nodes[0] != nodes[-1]: index = nodes[-1].index(nodes[0]) nodes[-1][index] = Test() nodes[-1][index].is_rewrited = True else: nodes[0].is_rewrited = True m = MatchBlock([ MatchHook(checkMatch, MatchType(L, [MatchIndice(2)])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_2.png') t = L() t.append(Test()) t.append(A()) t.append(L()) t[0].a = 42 t[1].b = 42 t[2].c = 42 t[2].subls = [0, 1, L([2, 3, Test(), 4]), 5] in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t, "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t[2].subls[2], "is_rewrited"), "Failed to rewrite a node") self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # H({'toto': *}) -> #checkMatch; def checkMatch(tree: Node, user_data, nodes): global in_test in_test = True # nodes[0] == nodes[-1] on root node if nodes[0] != nodes[-1]: k = 'toto' nodes[-1][k] = Test() nodes[-1][k].is_rewrited = True else: nodes[0].is_rewrited = True m = MatchBlock([ MatchHook(checkMatch, MatchType(H, [MatchKey("toto")])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_3.png') t = H() t['bla'] = Test() t['bla'].a = 42 t['toto'] = Test() t['toto'].b = 42 t['blu'] = Test() t['blu'].c = 42 t['blu'].subh = {'t': 0, 'x': 1, 'toto': H({'2': 2, '3': 3, 'toto': Test(), '4': 4}), 'z': 5} in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t, "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t['blu'].subh['toto'], "is_rewrited"), "Failed to rewrite a node") self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # Test([*: 12]) -> #checkMatch; print('-------------------------------------------------------------------------------') def checkMatch(tree: Node, user_data, nodes): global in_test in_test = True print("HHHHHEEEERRRREEEE %r" % nodes) # nodes[0] == nodes[-1] on root node if nodes[0] != nodes[-1]: index = nodes[-1].index(nodes[0]) nodes[-1][index] = Test() nodes[-1][index].is_rewrited = True else: nodes[0].is_rewrited = True m = MatchBlock([ MatchHook(checkMatch, MatchType(L, [MatchIndice(None, MatchValue(12))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_4.png') t = L([1, 12, 2, 12, 3, 12]) in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called")
def test_05(self): """basic tree matching""" def checkMatch(tree: Node, user_data, nodes) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree), "Failed to match the node of tree") return tree def checkNoMatch(tree: Node, user_data, nodes) -> Node: global in_test in_test = True return tree global in_test # Test(.b = 42) -> #checkMatch; m = MatchBlock([ MatchHook(checkMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.b = 42) -> #checkNoMatch; m = MatchBlock([ MatchHook(checkNoMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_2.png') t = Test() t.a = 42 t.b = 12 in_test = False walk(t, lc, (id(t), self)) self.assertFalse(in_test, "Expect that the Hook checkNoMatch isn't called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.a=42, .c=1.2) -> #checkMatch; m = MatchBlock([ MatchHook(checkMatch, MatchType(Test, [MatchAttr('a', MatchValue(42)), MatchAttr('c', MatchValue(1.2))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_3.png') t = Test() t.a = 42 t.c = 1.2 in_test = False walk(t, lc, (id(t), self)) self.assertTrue(in_test, "Expect that the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") t = Test() t.a = 42 t.b = Test() t.b.c = 1.2 in_test = False walk(t, lc, (id(t), self)) self.assertFalse(in_test, "Expect that the Hook checkMatch isn't called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # L([2: 42]) -> #checkMatch; m = MatchBlock([ MatchHook(checkMatch, MatchType(L, [MatchIndice(2, MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_4.png') t = [L(), L(), L()] t[0].append(10) t[0].append(42) t[1].append(10) t[1].append(10) t[1].append(10) t[2].append(10) t[2].append(10) t[2].append(42) in_test = False walk(t, lc, (id(t[2]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # H({'toto': 42}) -> #checkMatch; m = MatchBlock([ MatchHook(checkMatch, MatchType(H, [MatchKey('toto', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_5.png') t = [H(), H(), H()] t[0]['chausette'] = 12 t[0]['toto'] = 12 t[1]['toto'] = 42 t[2]['zozo'] = 42 in_test = False walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.a = 12, .c = 42, ...) -> #checkMatch; m = MatchBlock([ MatchHook(checkMatch, MatchType(Test, [MatchAttr('a', MatchValue(12)), MatchAttr('c', MatchValue(42))], strict=False)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_6.png') t = [Test(), Test()] t[0].a = 12 t[0].b = 42 t[1].a = 12 t[1].b = 22 t[1].c = 42 in_test = False walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test^(.b = 42) -> #checkMatch; class ChildTest(Test): pass m = MatchBlock([ MatchHook(checkMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))], iskindof=True)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_7.png') t = [ChildTest()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state")
def test_06(self): """tree rewriting""" def checkMatch1(tree: Node, user_data, nodes): global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree), "Failed to match the node of tree") index = nodes[-1].index(nodes[0]) nodes[-1][index] = "rewrited" def checkMatch2(tree: Node, user_data, nodes): global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree), "Failed to match the node of tree") nodes[-1][nodes.last_index] = "rewrited" def checkMatch3(tree: Node, user_data, nodes): global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree), "Failed to match the node of tree") index = nodes[-1].index(nodes[0]) nodes[-1][index] = "rewrited" def checkMatch4(tree: Node, user_data, nodes): global in_test in_test = True index = nodes[-1].index(nodes[0]) nodes[-1][index] = "rewrited" global in_test # Test(.b = 42) -> #checkMatch1; m = MatchBlock([ MatchHook(checkMatch1, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't6_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") self.assertEqual(t[0], "rewrited", "Failed to rewrite a node") # L([2: 42]) -> #checkMatch2; m = MatchBlock([ MatchHook(checkMatch2, MatchType(L, [MatchIndice(2, MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't6_2.png') t = [L(), L(), L()] t[0].append(10) t[0].append(42) t[1].append(10) t[1].append(10) t[1].append(10) t[2].append(10) t[2].append(10) t[2].append(42) in_test = False walk(t, lc, (id(t[2]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") self.assertEqual(t[2], "rewrited", "Failed to rewrite a node") # H({'toto': 42}) -> #checkMatch3; m = MatchBlock([ MatchHook(checkMatch3, MatchType(H, [MatchKey('toto', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't6_3.png') t = [H(), H(), H()] t[0]['chausette'] = 12 t[0]['toto'] = 12 t[1]['toto'] = 42 t[2]['zozo'] = 42 in_test = False walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") self.assertEqual(t[1], "rewrited", "Failed to rewrite a node") # Test(.a = 12, .c = 42, ...) -> #checkMatch4; m = MatchBlock([ MatchHook(checkMatch4, MatchType(Test, [MatchAttr('a', MatchValue(12)), MatchAttr('c', MatchValue(42))], strict=False)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't6_4.png') t = [Test(), Test(), Test(), Test(), Test()] t[0].a = 12 t[0].b = 42 t[1].a = 12 t[1].b = 22 t[1].c = 42 t[2] = "glubu" t[3].c = 42 t[3].a = 12 t[3].g = "plop" in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") self.assertEqual(t[1], "rewrited", "Failed to rewrite a node") self.assertEqual(t[3], "rewrited", "Failed to rewrite a node")
def test_06(self): """tree rewriting""" def checkMatch1(tree: Node, user_data, nodes): global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree), "Failed to match the node of tree") index = nodes[-1].index(nodes[0]) nodes[-1][index] = "rewrited" def checkMatch2(tree: Node, user_data, nodes): global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree), "Failed to match the node of tree") nodes[-1][nodes.last_index] = "rewrited" def checkMatch3(tree: Node, user_data, nodes): global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree), "Failed to match the node of tree") index = nodes[-1].index(nodes[0]) nodes[-1][index] = "rewrited" def checkMatch4(tree: Node, user_data, nodes): global in_test in_test = True index = nodes[-1].index(nodes[0]) nodes[-1][index] = "rewrited" global in_test # Test(.b = 42) -> #checkMatch1; m = MatchBlock([ MatchHook(checkMatch1, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't6_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") self.assertEqual(t[0], "rewrited", "Failed to rewrite a node") # L([2: 42]) -> #checkMatch2; m = MatchBlock([ MatchHook(checkMatch2, MatchType(L, [MatchIndice(2, MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't6_2.png') t = [L(), L(), L()] t[0].append(10) t[0].append(42) t[1].append(10) t[1].append(10) t[1].append(10) t[2].append(10) t[2].append(10) t[2].append(42) in_test = False walk(t, lc, (id(t[2]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") self.assertEqual(t[2], "rewrited", "Failed to rewrite a node") # H({'toto': 42}) -> #checkMatch3; m = MatchBlock([ MatchHook(checkMatch3, MatchType(H, [MatchKey('toto', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't6_3.png') t = [H(), H(), H()] t[0]['chausette'] = 12 t[0]['toto'] = 12 t[1]['toto'] = 42 t[2]['zozo'] = 42 in_test = False walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") self.assertEqual(t[1], "rewrited", "Failed to rewrite a node") # Test(.a = 12, .c = 42, ...) -> #checkMatch4; m = MatchBlock([ MatchHook( checkMatch4, MatchType(Test, [ MatchAttr('a', MatchValue(12)), MatchAttr('c', MatchValue(42)) ], strict=False)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't6_4.png') t = [Test(), Test(), Test(), Test(), Test()] t[0].a = 12 t[0].b = 42 t[1].a = 12 t[1].b = 22 t[1].c = 42 t[2] = "glubu" t[3].c = 42 t[3].a = 12 t[3].g = "plop" in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") self.assertEqual(t[1], "rewrited", "Failed to rewrite a node") self.assertEqual(t[3], "rewrited", "Failed to rewrite a node")
def test_07(self): """wildcard tree matching""" global in_test # Test(.b = *) -> #checkMatch; def checkMatch(tree: Node, user_data, nodes): global in_test in_test = True tree.is_rewrited = True m = MatchBlock([ MatchHook(checkMatch, MatchType(Test, [MatchAttr('b')])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t[0], "is_rewrited"), "Failed to rewrite a node") self.assertFalse( lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # L([2: *]) -> #checkMatch; def checkMatch(tree: Node, user_data, nodes): global in_test in_test = True # nodes[0] == nodes[-1] on root node if nodes[0] != nodes[-1]: index = nodes[-1].index(nodes[0]) nodes[-1][index] = Test() nodes[-1][index].is_rewrited = True else: nodes[0].is_rewrited = True m = MatchBlock([ MatchHook(checkMatch, MatchType(L, [MatchIndice(2)])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_2.png') t = L() t.append(Test()) t.append(A()) t.append(L()) t[0].a = 42 t[1].b = 42 t[2].c = 42 t[2].subls = [0, 1, L([2, 3, Test(), 4]), 5] in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t, "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t[2].subls[2], "is_rewrited"), "Failed to rewrite a node") self.assertFalse( lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # H({'toto': *}) -> #checkMatch; def checkMatch(tree: Node, user_data, nodes): global in_test in_test = True # nodes[0] == nodes[-1] on root node if nodes[0] != nodes[-1]: k = 'toto' nodes[-1][k] = Test() nodes[-1][k].is_rewrited = True else: nodes[0].is_rewrited = True m = MatchBlock([ MatchHook(checkMatch, MatchType(H, [MatchKey("toto")])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_3.png') t = H() t['bla'] = Test() t['bla'].a = 42 t['toto'] = Test() t['toto'].b = 42 t['blu'] = Test() t['blu'].c = 42 t['blu'].subh = { 't': 0, 'x': 1, 'toto': H({ '2': 2, '3': 3, 'toto': Test(), '4': 4 }), 'z': 5 } in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t, "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t['blu'].subh['toto'], "is_rewrited"), "Failed to rewrite a node") self.assertFalse( lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # Test([*: 12]) -> #checkMatch; print( '-------------------------------------------------------------------------------' ) def checkMatch(tree: Node, user_data, nodes): global in_test in_test = True print("HHHHHEEEERRRREEEE %r" % nodes) # nodes[0] == nodes[-1] on root node if nodes[0] != nodes[-1]: index = nodes[-1].index(nodes[0]) nodes[-1][index] = Test() nodes[-1][index].is_rewrited = True else: nodes[0].is_rewrited = True m = MatchBlock([ MatchHook(checkMatch, MatchType(L, [MatchIndice(None, MatchValue(12))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_4.png') t = L([1, 12, 2, 12, 3, 12]) in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called")
def test_05(self): """basic tree matching""" def checkMatch(tree: Node, user_data, nodes) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree), "Failed to match the node of tree") return tree def checkNoMatch(tree: Node, user_data, nodes) -> Node: global in_test in_test = True return tree global in_test # Test(.b = 42) -> #checkMatch; m = MatchBlock([ MatchHook(checkMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.b = 42) -> #checkNoMatch; m = MatchBlock([ MatchHook(checkNoMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_2.png') t = Test() t.a = 42 t.b = 12 in_test = False walk(t, lc, (id(t), self)) self.assertFalse(in_test, "Expect that the Hook checkNoMatch isn't called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.a=42, .c=1.2) -> #checkMatch; m = MatchBlock([ MatchHook( checkMatch, MatchType(Test, [ MatchAttr('a', MatchValue(42)), MatchAttr('c', MatchValue(1.2)) ])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_3.png') t = Test() t.a = 42 t.c = 1.2 in_test = False walk(t, lc, (id(t), self)) self.assertTrue(in_test, "Expect that the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") t = Test() t.a = 42 t.b = Test() t.b.c = 1.2 in_test = False walk(t, lc, (id(t), self)) self.assertFalse(in_test, "Expect that the Hook checkMatch isn't called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # L([2: 42]) -> #checkMatch; m = MatchBlock([ MatchHook(checkMatch, MatchType(L, [MatchIndice(2, MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_4.png') t = [L(), L(), L()] t[0].append(10) t[0].append(42) t[1].append(10) t[1].append(10) t[1].append(10) t[2].append(10) t[2].append(10) t[2].append(42) in_test = False walk(t, lc, (id(t[2]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # H({'toto': 42}) -> #checkMatch; m = MatchBlock([ MatchHook(checkMatch, MatchType(H, [MatchKey('toto', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_5.png') t = [H(), H(), H()] t[0]['chausette'] = 12 t[0]['toto'] = 12 t[1]['toto'] = 42 t[2]['zozo'] = 42 in_test = False walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.a = 12, .c = 42, ...) -> #checkMatch; m = MatchBlock([ MatchHook( checkMatch, MatchType(Test, [ MatchAttr('a', MatchValue(12)), MatchAttr('c', MatchValue(42)) ], strict=False)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_6.png') t = [Test(), Test()] t[0].a = 12 t[0].b = 42 t[1].a = 12 t[1].b = 22 t[1].c = 42 in_test = False walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test^(.b = 42) -> #checkMatch; class ChildTest(Test): pass m = MatchBlock([ MatchHook( checkMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))], iskindof=True)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_7.png') t = [ChildTest()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state")
def test_07(self): """wildcard tree matching""" global in_test # Test(.b = *) -> #checkMatch; def checkMatch1(tree: Node, user_data): global in_test in_test = True tree.node().is_rewrited = True m = MatchBlock([ MatchHook(checkMatch1, MatchType(Test, [MatchAttr('b')])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 666 t.append(Test()) t[2].b = "cool" in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t[0], "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t[2], "is_rewrited"), "Failed to rewrite a node") #self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # L([2: *]) -> #checkMatch2; def checkMatch2(tree: Node, user_data): global in_test in_test = True print("++++++++++") tree.get().is_rewrited = True print("==========") print("RECV %s" % tree.dbg_str()) m = MatchBlock([ MatchHook(checkMatch2, MatchType(L, [MatchIndice(2)])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_2.png') t = L() t.append(Test()) t.append(A()) t.append(L()) t[0].a = 42 t[1].b = 42 t[2].c = 42 t[2].subls = [0, 1, L([2, 3, Test(), 4]), 5] t = normalize(t) in_test = False with self.assertRaises(ValueError): walk(t, lc) t[2].subls = L([0, 1, L([2, 3, Test(), 4]), 5]) walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t[2], "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t[2].subls[2][2], "is_rewrited"), "Failed to rewrite a node") #self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # H({'toto': *}) -> #checkMatch; def checkMatch3(tree: Node, user_data): global in_test in_test = True tree.node().is_rewrited = True m = MatchBlock([ MatchHook(checkMatch3, MatchType(H, [MatchKey("toto")])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_3.png') t = H() t['bla'] = Test() t['bla'].a = 42 t['toto'] = Test() t['toto'].b = 42 t['blu'] = Test() t['blu'].c = 42 t['blu'].subh = { 't': 0, 'x': 1, 'toto': H({ '2': 2, '3': 3, 'toto': Test(), '4': 4 }), 'z': 5 } in_test = False with self.assertRaises(ValueError): walk(t, lc) t['blu'].subh = H({ 't': 0, 'x': 1, 'toto': H({ '2': 2, '3': 3, 'toto': Test(), '4': 4 }), 'z': 5 }) walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t, "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t['blu'].subh['toto'], "is_rewrited"), "Failed to rewrite a node") #self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # Test([*: 12]) -> #checkMatch; print( '-------------------------------------------------------------------------------' ) def checkMatch4(tree: Node, user_data): global in_test in_test = True tree.node().is_rewrited = True m = MatchBlock([ MatchHook(checkMatch4, MatchType(L, [MatchIndice(None, MatchValue(12))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_4.png') t = L([1, 12, 2, 12, 3, 12]) in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t, "is_rewrited"), "Failed to rewrite a node")
def test_05(self): """basic tree matching""" def checkMatch1(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].value, 'b', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].get(), 42, "Failed to match the node of tree") def checkMatch2(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].value, 'a', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].get(), 42, "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[1].value, 'c', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[1].get(), 1.2, "Failed to match the node of tree") def checkMatch3(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.indices[0].value, 2, "Failed to match the node of tree") user_data[1].assertEqual(tree.indices[0].get(), 42, "Failed to match the node of tree") def checkMatch4(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.keys[0].value, 'toto', "Failed to match the node of tree") user_data[1].assertEqual(tree.keys[0].get(), 42, "Failed to match the node of tree") def checkMatch5(tree: Node, user_data) -> Node: global in_test print("MATCH TREE %s" % repr(tree.attrs), flush=True) in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].value, 'a', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].get(), 12, "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[1].value, 'c', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[1].get(), 42, "Failed to match the node of tree") def checkMatch(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") def checkNoMatch(tree: Node, user_data) -> Node: global in_test in_test = True global in_test # Test(.b = 42) -> #checkMatch1; m = MatchBlock([ MatchHook(checkMatch1, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.b = 42) -> #checkNoMatch; m = MatchBlock([ MatchHook(checkNoMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_2.png') t = Test() t.a = 42 t.b = 12 in_test = False walk(t, lc, (id(t), self)) self.assertFalse(in_test, "Expect that the Hook checkNoMatch isn't called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.a=42, .c=1.2) -> #checkMatch2; m = MatchBlock([ MatchHook( checkMatch2, MatchType(Test, [ MatchAttr('a', MatchValue(42)), MatchAttr('c', MatchValue(1.2)) ])), ]) c = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_3.png') t = Test() t.a = 42 t.c = 1.2 in_test = False walk(t, lc, (id(t), self)) self.assertTrue(in_test, "Expect that the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") t = Test() t.a = 42 t.b = Test() t.b.c = 1.2 in_test = False walk(t, lc, (id(t), self)) self.assertFalse(in_test, "Expect that the Hook checkMatch isn't called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # L([2: 42]) -> #checkMatch3; m = MatchBlock([ MatchHook(checkMatch3, MatchType(L, [MatchIndice(2, MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_4.png') t = [L(), L(), L()] t[0].append(10) t[0].append(42) t[1].append(11) t[1].append(12) t[1].append(13) t[2].append(14) t[2].append(15) t[2].append(42) in_test = False walk(t, lc, (id(t[2]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # H({'toto': 42}) -> #checkMatch4; m = MatchBlock([ MatchHook(checkMatch4, MatchType(H, [MatchKey('toto', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_5.png') t = [H(), H(), H()] t[0]['chausette'] = 12 t[0]['toto'] = 12 t[1]['toto'] = 42 t[2]['zozo'] = 42 in_test = False walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.a = 12, .c = 42, ...) -> #checkMatch5; m = MatchBlock([ MatchHook( checkMatch5, MatchType(Test, [ MatchAttr('a', MatchValue(12)), MatchAttr('c', MatchValue(42)) ], strict=False)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_6.png') t = [Test(), Test()] t[0].a = 12 t[0].b = 42 t[1].a = 12 t[1].b = 22 t[1].c = 42 t = normalize(t) in_test = False print("WALK BEGIN") #pdb.set_trace() walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test^(.b = 42) -> #checkMatch; class ChildTest(Test): pass m = MatchBlock([ MatchHook( checkMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))], iskindof=True)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_7.png') t = [ChildTest()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called")
def test_07(self): """wildcard tree matching""" global in_test # Test(.b = *) -> #checkMatch; def checkMatch1(tree: Node, user_data): global in_test in_test = True tree.node().is_rewrited = True m = MatchBlock([ MatchHook(checkMatch1, MatchType(Test, [MatchAttr('b')])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 666 t.append(Test()) t[2].b = "cool" in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t[0], "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t[2], "is_rewrited"), "Failed to rewrite a node") #self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # L([2: *]) -> #checkMatch2; def checkMatch2(tree: Node, user_data): global in_test in_test = True print("++++++++++") tree.get().is_rewrited = True print("==========") print("RECV %s" % tree.dbg_str()) m = MatchBlock([ MatchHook(checkMatch2, MatchType(L, [MatchIndice(2)])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_2.png') t = L() t.append(Test()) t.append(A()) t.append(L()) t[0].a = 42 t[1].b = 42 t[2].c = 42 t[2].subls = [0, 1, L([2, 3, Test(), 4]), 5] t = normalize(t) in_test = False with self.assertRaises(ValueError): walk(t, lc) t[2].subls = L([0, 1, L([2, 3, Test(), 4]), 5]) walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t[2], "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t[2].subls[2][2], "is_rewrited"), "Failed to rewrite a node") #self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # H({'toto': *}) -> #checkMatch; def checkMatch3(tree: Node, user_data): global in_test in_test = True tree.node().is_rewrited = True m = MatchBlock([ MatchHook(checkMatch3, MatchType(H, [MatchKey("toto")])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_3.png') t = H() t['bla'] = Test() t['bla'].a = 42 t['toto'] = Test() t['toto'].b = 42 t['blu'] = Test() t['blu'].c = 42 t['blu'].subh = {'t': 0, 'x': 1, 'toto': H({'2': 2, '3': 3, 'toto': Test(), '4': 4}), 'z': 5} in_test = False with self.assertRaises(ValueError): walk(t, lc) t['blu'].subh = H({'t': 0, 'x': 1, 'toto': H({'2': 2, '3': 3, 'toto': Test(), '4': 4}), 'z': 5}) walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t, "is_rewrited"), "Failed to rewrite a node") self.assertTrue(hasattr(t['blu'].subh['toto'], "is_rewrited"), "Failed to rewrite a node") #self.assertFalse(lc.is_in_stable_state(), "LivingContext not in correct state due to WILDCAR MATCH") # Test([*: 12]) -> #checkMatch; print('-------------------------------------------------------------------------------') def checkMatch4(tree: Node, user_data): global in_test in_test = True tree.node().is_rewrited = True m = MatchBlock([ MatchHook(checkMatch4, MatchType(L, [MatchIndice(None, MatchValue(12))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't7_4.png') t = L([1, 12, 2, 12, 3, 12]) in_test = False walk(t, lc) self.assertTrue(in_test, "Expect the Hook checkMatch is called") self.assertTrue(hasattr(t, "is_rewrited"), "Failed to rewrite a node")
def test_05(self): """basic tree matching""" def checkMatch1(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].value, 'b', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].get(), 42, "Failed to match the node of tree") def checkMatch2(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].value, 'a', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].get(), 42, "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[1].value, 'c', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[1].get(), 1.2, "Failed to match the node of tree") def checkMatch3(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.indices[0].value, 2, "Failed to match the node of tree") user_data[1].assertEqual(tree.indices[0].get(), 42, "Failed to match the node of tree") def checkMatch4(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.keys[0].value, 'toto', "Failed to match the node of tree") user_data[1].assertEqual(tree.keys[0].get(), 42, "Failed to match the node of tree") def checkMatch5(tree: Node, user_data) -> Node: global in_test print("MATCH TREE %s" % repr(tree.attrs), flush=True) in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].value, 'a', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[0].get(), 12, "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[1].value, 'c', "Failed to match the node of tree") user_data[1].assertEqual(tree.attrs[1].get(), 42, "Failed to match the node of tree") def checkMatch(tree: Node, user_data) -> Node: global in_test in_test = True user_data[1].assertEqual(user_data[0], id(tree.node()), "Failed to match the node of tree") def checkNoMatch(tree: Node, user_data) -> Node: global in_test in_test = True global in_test # Test(.b = 42) -> #checkMatch1; m = MatchBlock([ MatchHook(checkMatch1, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_1.png') t = [Test()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.b = 42) -> #checkNoMatch; m = MatchBlock([ MatchHook(checkNoMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_2.png') t = Test() t.a = 42 t.b = 12 in_test = False walk(t, lc, (id(t), self)) self.assertFalse(in_test, "Expect that the Hook checkNoMatch isn't called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.a=42, .c=1.2) -> #checkMatch2; m = MatchBlock([ MatchHook(checkMatch2, MatchType(Test, [MatchAttr('a', MatchValue(42)), MatchAttr('c', MatchValue(1.2))])), ]) c = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_3.png') t = Test() t.a = 42 t.c = 1.2 in_test = False walk(t, lc, (id(t), self)) self.assertTrue(in_test, "Expect that the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") t = Test() t.a = 42 t.b = Test() t.b.c = 1.2 in_test = False walk(t, lc, (id(t), self)) self.assertFalse(in_test, "Expect that the Hook checkMatch isn't called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # L([2: 42]) -> #checkMatch3; m = MatchBlock([ MatchHook(checkMatch3, MatchType(L, [MatchIndice(2, MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_4.png') t = [L(), L(), L()] t[0].append(10) t[0].append(42) t[1].append(11) t[1].append(12) t[1].append(13) t[2].append(14) t[2].append(15) t[2].append(42) in_test = False walk(t, lc, (id(t[2]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # H({'toto': 42}) -> #checkMatch4; m = MatchBlock([ MatchHook(checkMatch4, MatchType(H, [MatchKey('toto', MatchValue(42))])), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_5.png') t = [H(), H(), H()] t[0]['chausette'] = 12 t[0]['toto'] = 12 t[1]['toto'] = 42 t[2]['zozo'] = 42 in_test = False walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test(.a = 12, .c = 42, ...) -> #checkMatch5; m = MatchBlock([ MatchHook(checkMatch5, MatchType(Test, [MatchAttr('a', MatchValue(12)), MatchAttr('c', MatchValue(42))], strict=False)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_6.png') t = [Test(), Test()] t[0].a = 12 t[0].b = 42 t[1].a = 12 t[1].b = 22 t[1].c = 42 t = normalize(t) in_test = False print("WALK BEGIN") pdb.set_trace() walk(t, lc, (id(t[1]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called") #self.assertTrue(lc.is_in_stable_state(), "LivingContext not in correct state") # Test^(.b = 42) -> #checkMatch; class ChildTest(Test): pass m = MatchBlock([ MatchHook(checkMatch, MatchType(Test, [MatchAttr('b', MatchValue(42))], iskindof=True)), ]) lc = LivingContext() lc.add_match_block(m) lc.build_automata() lc.to_png_file(rpath + os.sep + 't5_7.png') t = [ChildTest()] t[0].b = 42 t.append(A()) t[1].b = 42 in_test = False walk(t, lc, (id(t[0]), self)) self.assertTrue(in_test, "Expect the Hook checkMatch is called")