def assert_tree(test, nodes, tups, tree=None, history=None): if tree is None: tree = nodes if history is None: history = [] for node, tup in overzip(nodes, tups): if isinstance(node, lexer.Token): continue subhistory = history + [node] message = (" for node {} at\n {} \n\n\n" "If the actual result is expected, then update the test with" " this:\n{}" .format(node, formatter.tree_string(tree, subhistory), formatter.test_string(tree))) test.assertIsNotNone(node, msg="Missing node" + message) test.assertIsNotNone(tup, msg="Extra node" + message) if len(tup) == 6: ntype, wrap, row, col, colextent, expect_children = tup test.assertEqual(node.wrap, wrap, msg="Expected wrap={}".format(wrap) + message) else: ntype, row, col, colextent, expect_children = tup test.assertEqual(node.type, ntype, msg="Expected type={}".format(ntype) + message) test.assertEqual(node.position[0], row, msg="Expected row={}".format(row) + message) test.assertEqual(node.position[1], col, msg="Expected col={}".format(col) + message) test.assertEqual(node.colextent, colextent, msg="Expected colextent={}".format(colextent) + message) assert_tree(test, node.children, expect_children, tree, subhistory)
def assert_tree(test, nodes, tups, tree=None, history=None): if tree is None: tree = nodes if history is None: history = [] for node, tup in overzip(nodes, tups): if isinstance(node, lexer.Token): continue subhistory = history + [node] message = (" for node {} at\n {} \n\n\n" "If the actual result is expected, then update the test with" " this:\n{}" .format(node, formatter.tree_string(tree, subhistory), formatter.test_string(tree))) test.assertIsNotNone(node, msg="Missing node" + message) test.assertIsNotNone(tup, msg="Extra node" + message) if len(tup) == 6: ntype, wrap, row, col, colextent, expect_children = tup test.assertEqual(node.wrap, wrap, msg="Expected wrap={}".format(wrap) + message) else: ntype, row, col, colextent, expect_children = tup test.assertEqual(node.type, ntype, msg="Expected type={}".format(ntype) + message) test.assertEqual(node.position[0], row, msg="Expected row={}".format(row) + message) test.assertEqual(node.position[1], col, msg="Expected col={}".format(col) + message) test.assertEqual(node.colextent, colextent, msg="Expected colextent={}".format(colextent) + message) assert_tree(test, node.children, expect_children, tree, subhistory)