def test_build_tree_hash(self): tree = self.build_tree() tree['children'][0]['children'] = [{ 'text': 'child child test', 'children': [], 'label_id': '204-3-a', 'label': ['204', '3', 'a'], 'node_type': REGTEXT }] tree_hash = tree_builder.build_tree_hash(tree) self.assertEqual(set(tree_hash.keys()), set(['204-3-a', '204-3', '204']))
def test_build_tree_hash(self): tree = self.build_tree() tree["children"][0]["children"] = [ { "text": "child child test", "children": [], "label_id": "204-3-a", "label": ["204", "3", "a"], "node_type": REGTEXT, } ] tree_hash = tree_builder.build_tree_hash(tree) self.assertEqual(set(tree_hash.keys()), set(["204-3-a", "204-3", "204"]))
def add_nodes_to_tree(self, original, adds): """ Add all the nodes from new_nodes into the original tree. """ tree = tree_builder.build_tree_hash(original) for label, node in adds.queue: p_label = '-'.join(tree_builder.parent_label(node)) if tree_builder.parent_in_tree(p_label, tree): tree_builder.add_node_to_tree(node, p_label, tree) adds.delete(label) else: parent = adds.find(p_label) if parent: tree_builder.add_child(parent[1], node) else: original.update(node)
def test_add_node(self): new_node = { 'text': 'new node text', 'children': [], 'label_id': '204-4', 'label': ['204', '4'], 'node_type': REGTEXT } tree = self.build_tree() tree_hash = tree_builder.build_tree_hash(tree) self.assertEqual(tree_hash.keys(), ['204-3', '204']) self.assertEqual(len(tree_hash['204']['children']), 1) tree_builder.add_node_to_tree(new_node, '204', tree_hash) self.assertEqual(len(tree_hash['204']['children']), 2) child_labels = [c['label_id'] for c in tree_hash['204']['children']] self.assertEqual(child_labels, ['204-3', '204-4'])
def test_add_node(self): new_node = { "text": "new node text", "children": [], "label_id": "204-4", "label": ["204", "4"], "node_type": REGTEXT, } tree = self.build_tree() tree_hash = tree_builder.build_tree_hash(tree) self.assertEqual(tree_hash.keys(), ["204-3", "204"]) self.assertEqual(len(tree_hash["204"]["children"]), 1) tree_builder.add_node_to_tree(new_node, "204", tree_hash) self.assertEqual(len(tree_hash["204"]["children"]), 2) child_labels = [c["label_id"] for c in tree_hash["204"]["children"]] self.assertEqual(child_labels, ["204-3", "204-4"])
def test_parent_in_tree(self): tree = self.build_tree() tree_hash = tree_builder.build_tree_hash(tree) self.assertEqual(tree_hash.keys(), ['204-3', '204']) self.assertTrue(tree_builder.parent_in_tree('204-3', tree_hash))
def test_parent_in_tree(self): tree = self.build_tree() tree_hash = tree_builder.build_tree_hash(tree) self.assertEqual(tree_hash.keys(), ["204-3", "204"]) self.assertTrue(tree_builder.parent_in_tree("204-3", tree_hash))