Exemple #1
0
    def test_add_nodes_empty_tree(self):
        tree = {}
        new_node = {
            'text': 'new node text',
            'children': [],
            'label_id': '204-2',
            'label': ['204', '2'],
            'node_type': REGTEXT
        }
        da = diff_applier.DiffApplier({}, None)
        adds = tree_builder.AddQueue()
        adds.insert_all([('204-2', new_node)])

        da.add_nodes_to_tree(tree, adds)
Exemple #2
0
    def test_add_nodes_child_ops(self):
        """If we don't know the correct order of children, attempt to use data
        from `child_ops`"""
        def mk_node(section):
            return {
                'label': ['100', section],
                'node_type': 'regtext',
                'children': []
            }

        node_1, node_2 = mk_node('1'), mk_node('2')
        node_2a, node_3 = mk_node('2a'), mk_node('3')
        original = {
            'label': ['100'],
            'node_type': 'regtext',
            'children': [node_1, node_2]
        }

        diff = {
            '100': {
                'op':
                diff_applier.DiffApplier.MODIFIED_OP,
                'child_ops': [[diff_applier.DiffApplier.EQUAL, 0, 1],
                              [diff_applier.DiffApplier.DELETE, 1, 2],
                              [diff_applier.DiffApplier.INSERT, 1, ['100-2a']],
                              [diff_applier.DiffApplier.INSERT, 2, ['100-3']]]
            },
            '100-2': {
                'op': diff_applier.DiffApplier.DELETED_OP
            },
            '100-2a': {
                'op': diff_applier.DiffApplier.ADDED_OP,
                'node': node_2a
            },
            '100-3': {
                'op': diff_applier.DiffApplier.ADDED_OP,
                'node': node_3
            }
        }

        adds = tree_builder.AddQueue()
        adds.insert_all([('100-2a', node_2a), ('100-3', node_3)])

        da = diff_applier.DiffApplier(diff, None)
        da.add_nodes_to_tree(original, adds)
        self.assertEqual(original['child_labels'],
                         ['100-1', '100-2', '100-2a', '100-3'])
Exemple #3
0
    def test_add_nodes_to_tree(self):
        tree = self.build_tree()

        new_node = {
            'text': 'child text',
            'children': [],
            'label_id': '204-2',
            'label': ['204', '2'],
            'node_type': REGTEXT
        }

        da = diff_applier.DiffApplier({}, None)
        adds = tree_builder.AddQueue()
        adds.insert_all([('204-2', new_node)])

        da.add_nodes_to_tree(tree, adds)
        self.assertEqual(len(tree['children']), 2)
        self.assertEqual(tree['children'][0], new_node)
Exemple #4
0
    def tree_changes(self, original_tree):
        """ Apply additions to the regulation tree. """
        def node(diff_node, label):
            """ Take diff's specification of a node, and actually turn it into
            a regulation node. """

            node = copy.deepcopy(diff_node)
            node['children'] = []
            if 'title' in node and node['title'] is None:
                del node['title']
            return node

        new_nodes = [(label, node(self.diff[label]['node'], label))
                     for label in self.diff if self.relevant_added(label)]

        adds = tree_builder.AddQueue()
        adds.insert_all(new_nodes)

        self.add_nodes_to_tree(original_tree, adds)