def test_add_child_root_appendix(self):
        """ Let's add an introductory paragraph child to a root interpretation
        node and ensure that the children are sorted correctly. """

        parent = {'children': [
            {'node_type': 'appendix', 'label': ['204', 'A', '4', 'b', 'i']},
            {'node_type': 'appendix', 'label': ['204', 'A', '4', 'b', 'v']}
            ], 'label': ['204', 'appendix']}

        tree_builder.add_child(parent, {'node_type': 'appendix',
                                        'label': ['204', 'A', '4', 'b', 'ii']})

        self.assertEqual([(1,), (2,), (5,)],
                         [c['sortable'] for c in parent['children']])

        parent = {'children': [
            {'node_type': 'appendix', 'label': ['204', 'A', '4', 'b']},
            {'node_type': 'appendix', 'label': ['204', 'A', '4', 'i']}
            ], 'label': ['204', 'appendix']}

        tree_builder.add_child(parent, {'node_type': 'appendix',
                                        'label': ['204', 'A', '4', 'g']})

        self.assertEqual([('b',), ('g',), ('i',)],
                         [c['sortable'] for c in parent['children']])
    def test_add_child(self):
        tree = self.build_tree()

        child = {
            "children": [],
            "label": ["204", "2"],
            "label_id": "204-2",
            "node_type": REGTEXT,
            "sortable": (2,),
            "text": "child text",
        }

        static_child = {
            "children": [],
            "label": ["204", "3"],
            "label_id": "204-3",
            "node_type": REGTEXT,
            "sortable": (3,),
            "text": "child text",
        }

        static_tree = {
            "children": [child, static_child],
            "text": "parent text",
            "label": ["204"],
            "label_id": "204",
            "node_type": REGTEXT,
        }

        tree_builder.add_child(tree, child)
        self.assertEquals(static_tree, tree)
Exemple #3
0
    def test_add_child_root_appendix(self):
        """ Let's add an introductory paragraph child to a root interpretation
        node and ensure that the children are sorted correctly. """

        parent = {'children': [
            {'node_type': 'appendix', 'label': ['204', 'A', '4', 'b', 'i']},
            {'node_type': 'appendix', 'label': ['204', 'A', '4', 'b', 'v']}
            ], 'label': ['204', 'appendix']}

        tree_builder.add_child(parent, {'node_type': 'appendix',
                                        'label': ['204', 'A', '4', 'b', 'ii']})

        self.assertEqual([(1,), (2,), (5,)],
                         [c['sortable'] for c in parent['children']])

        parent = {'children': [
            {'node_type': 'appendix', 'label': ['204', 'A', '4', 'b']},
            {'node_type': 'appendix', 'label': ['204', 'A', '4', 'i']}
            ], 'label': ['204', 'appendix']}

        tree_builder.add_child(parent, {'node_type': 'appendix',
                                        'label': ['204', 'A', '4', 'g']})

        self.assertEqual([('b',), ('g',), ('i',)],
                         [c['sortable'] for c in parent['children']])
    def test_add_child(self):
        tree = self.build_tree()

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

        static_child = {
            'children': [],
            'label': ['204', '3'],
            'label_id': '204-3',
            'node_type': REGTEXT,
            'sortable': (3,),
            'text': 'child text',
        }

        static_tree = {
            'children': [child, static_child],
            'text': 'parent text',
            'label': ['204'],
            'label_id': '204',
            'node_type': REGTEXT
        }

        tree_builder.add_child(tree, child)
        self.assertEquals(static_tree, tree)
Exemple #5
0
    def test_add_child(self):
        tree = self.build_tree()

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

        static_child = {
            'children': [],
            'label': ['204', '3'],
            'label_id': '204-3',
            'node_type': REGTEXT,
            'sortable': (3, ),
            'text': 'child text',
        }

        static_tree = {
            'children': [child, static_child],
            'text': 'parent text',
            'label': ['204'],
            'label_id': '204',
            'node_type': REGTEXT
        }

        tree_builder.add_child(tree, child)
        self.assertEquals(static_tree, tree)
    def test_add_child_appendix(self):
        parent = {
            "children": [
                {"node_type": "APPENDIX", "label": ["204", "A", "1"]},
                {"node_type": "APPENDIX", "label": ["204", "A", "3"]},
            ]
        }

        child_to_add = {"node_type": "APPENDIX", "label": ["204", "A", "2(a)"]}
        tree_builder.add_child(parent, child_to_add)
        self.assertEquals(["204-A-1", "204-A-2(a)", "204-A-3"], ["-".join(c["label"]) for c in parent["children"]])
    def test_add_child_appendix(self):
        parent = {'children': [
            {'node_type': 'APPENDIX', 'label': ['204', 'A', '1']},
            {'node_type': 'APPENDIX', 'label': ['204', 'A', '3']},
            ]}

        child_to_add = {'node_type': 'APPENDIX', 'label': ['204', 'A', '2(a)']}
        tree_builder.add_child(parent, child_to_add)
        self.assertEquals(
            ['204-A-1', '204-A-2(a)', '204-A-3'],
            ['-'.join(c['label']) for c in parent['children']]
            )
Exemple #8
0
    def test_add_child_appendix(self):
        parent = {'children': [
            {'node_type': 'APPENDIX', 'label': ['204', 'A', '1']},
            {'node_type': 'APPENDIX', 'label': ['204', 'A', '3']},
            ]}

        child_to_add = {'node_type': 'APPENDIX', 'label': ['204', 'A', '2(a)']}
        tree_builder.add_child(parent, child_to_add)
        self.assertEquals(
            ['204-A-1', '204-A-2(a)', '204-A-3'],
            ['-'.join(c['label']) for c in parent['children']]
            )
    def test_add_child_root_interp(self):
        """ Let's add an introductory paragraph child to a root interpretation
        node and ensure that the children are sorted correctly. """

        parent = {'children': [
            {'node_type': 'INTERP', 'label': ['204', '4', 'Interp']},
            {'node_type': 'INTERP', 'label': ['204', '2', 'Interp']}
        ], 'label': ['204', 'Interp']}

        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': ['204', 'Interp', 'h1']})

        self.assertEqual([(1, 'h', 1), (2, 2), (2, 4)],
                         [c['sortable'] for c in parent['children']])
Exemple #10
0
    def test_add_child_root_interp(self):
        """ Let's add an introductory paragraph child to a root interpretation
        node and ensure that the children are sorted correctly. """

        parent = {'children': [
            {'node_type': 'INTERP', 'label': ['204', '4', 'Interp']},
            {'node_type': 'INTERP', 'label': ['204', '2', 'Interp']}
        ], 'label': ['204', 'Interp']}

        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': ['204', 'Interp', 'h1']})

        self.assertEqual([(1, 'h', 1), (2, 2), (2, 4)],
                         [c['sortable'] for c in parent['children']])
    def test_add_child_root_interp(self):
        """ Let's add an introductory paragraph child to a root interpretation
        node and ensure that the children are sorted correctly. """

        parent = {
            "children": [
                {"node_type": "INTERP", "label": ["204", "4", "Interp"]},
                {"node_type": "INTERP", "label": ["204", "2", "Interp"]},
            ],
            "label": ["204", "Interp"],
        }

        tree_builder.add_child(parent, {"node_type": "INTERP", "label": ["204", "Interp", "h1"]})

        self.assertEqual([(1, "h", 1), (2, 2), (2, 4)], [c["sortable"] for c in parent["children"]])
    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)
Exemple #13
0
    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)
Exemple #14
0
    def test_add_child_odd_sort(self):
        """Appendices may have some strange orderings. Make sure they keep
        order."""
        parent = {'children': [], 'label': ['204', 'A'],
                  'node_type': 'appendix',
                  'child_labels': ['204-A-p1', '204-A-X', '204-A-L',
                                   '204-A-h1']}

        def mknode(label):
            return {'node_type': 'appendix', 'label': label.split('-')}
        tree_builder.add_child(parent, mknode('204-A-X'))
        tree_builder.add_child(parent, mknode('204-A-L'))
        tree_builder.add_child(parent, mknode('204-A-h1'))
        tree_builder.add_child(parent, mknode('204-A-p1'))
        self.assertEqual([['204', 'A', 'p1'], ['204', 'A', 'X'],
                          ['204', 'A', 'L'], ['204', 'A', 'h1']],
                         [c['label'] for c in parent['children']])
    def test_add_child_odd_sort(self):
        """Appendices may have some strange orderings. Make sure they keep
        order."""
        parent = {'children': [], 'label': ['204', 'A'],
                  'node_type': 'appendix',
                  'child_labels': ['204-A-p1', '204-A-X', '204-A-L',
                                   '204-A-h1']}

        def mknode(label):
            return {'node_type': 'appendix', 'label': label.split('-')}
        tree_builder.add_child(parent, mknode('204-A-X'))
        tree_builder.add_child(parent, mknode('204-A-L'))
        tree_builder.add_child(parent, mknode('204-A-h1'))
        tree_builder.add_child(parent, mknode('204-A-p1'))
        self.assertEqual([['204', 'A', 'p1'], ['204', 'A', 'X'],
                          ['204', 'A', 'L'], ['204', 'A', 'h1']],
                         [c['label'] for c in parent['children']])
    def test_add_child_interp(self):
        parent = {
            "children": [
                {"node_type": "INTERP", "label": ["204", "4", "Interp"]},
                {"node_type": "INTERP", "label": ["204", "2", "Interp"]},
            ],
            "label": ["204", "Interp"],
        }
        tree_builder.add_child(parent, {"node_type": "INTERP", "label": ["204", "3", "Interp"]})
        self.assertEqual([(2, 2), (2, 3), (2, 4)], [c["sortable"] for c in parent["children"]])

        prefix = ["204", "4", "a", "2"]
        parent = {
            "children": [
                {"node_type": "INTERP", "label": prefix + ["v", "Interp"]},
                {"node_type": "INTERP", "label": prefix + ["iv", "Interp"]},
            ],
            "label": ["204", "4", "a", "2", "Interp"],
        }
        tree_builder.add_child(parent, {"node_type": "INTERP", "label": prefix + ["ix", "Interp"]})
        self.assertEqual([(4,), (5,), (9,)], [c["sortable"] for c in parent["children"]])

        prefix = ["204", "4", "Interp"]
        parent = {
            "children": [
                {"node_type": "INTERP", "label": prefix + ["1"]},
                {"node_type": "INTERP", "label": prefix + ["3"]},
            ],
            "label": ["204", "Interp"],
        }
        tree_builder.add_child(parent, {"node_type": "INTERP", "label": prefix + ["2"]})
        self.assertEqual([(2, 1), (2, 2), (2, 3)], [c["sortable"] for c in parent["children"]])

        prefix = ["204", "Interp", "2"]
        parent = {
            "children": [
                {"node_type": "INTERP", "label": prefix + ["v"]},
                {"node_type": "INTERP", "label": prefix + ["iv"]},
            ],
            "label": prefix,
        }
        tree_builder.add_child(parent, {"node_type": "INTERP", "label": prefix + ["ix"]})
        self.assertEqual([(4,), (5,), (9,)], [c["sortable"] for c in parent["children"]])
    def test_add_child_interp(self):
        parent = {'children': [
            {'node_type': 'INTERP', 'label': ['204', '4', 'Interp']},
            {'node_type': 'INTERP', 'label': ['204', '2', 'Interp']}
        ]}
        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': ['204', '3', 'Interp']})
        self.assertEqual([(2,), (3,), (4,)],
                         [c['sortable'] for c in parent['children']])

        prefix = ['204', '4', 'a', '2']
        parent = {'children': [
            {'node_type': 'INTERP', 'label': prefix + ['v', 'Interp']},
            {'node_type': 'INTERP', 'label': prefix + ['iv', 'Interp']}
        ]}
        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': prefix + ['ix', 'Interp']})
        self.assertEqual([4, 5, 9],
                         [c['sortable'] for c in parent['children']])

        prefix = ['204', '4', 'Interp']
        parent = {'children': [
            {'node_type': 'INTERP', 'label': prefix + ['1']},
            {'node_type': 'INTERP', 'label': prefix + ['3']}
        ]}
        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': prefix + ['2']})
        self.assertEqual([(1,), (2,), (3,)],
                         [c['sortable'] for c in parent['children']])

        prefix = ['204', 'Interp', '2']
        parent = {'children': [
            {'node_type': 'INTERP', 'label': prefix + ['v']},
            {'node_type': 'INTERP', 'label': prefix + ['iv']}
        ]}
        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': prefix + ['ix']})
        self.assertEqual([4, 5, 9],
                         [c['sortable'] for c in parent['children']])
Exemple #18
0
    def test_add_child_interp(self):
        parent = {'children': [
            {'node_type': 'INTERP', 'label': ['204', '4', 'Interp']},
            {'node_type': 'INTERP', 'label': ['204', '2', 'Interp']}
        ], 'label': ['204', 'Interp']}
        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': ['204', '3', 'Interp']})
        self.assertEqual([(2, 2), (2, 3), (2, 4)],
                         [c['sortable'] for c in parent['children']])

        prefix = ['204', '4', 'a', '2']
        parent = {'children': [
            {'node_type': 'INTERP', 'label': prefix + ['v', 'Interp']},
            {'node_type': 'INTERP', 'label': prefix + ['iv', 'Interp']}
        ], 'label': ['204', '4', 'a', '2', 'Interp']}
        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': prefix + ['ix', 'Interp']})
        self.assertEqual([(4,), (5,), (9,)],
                         [c['sortable'] for c in parent['children']])

        prefix = ['204', '4', 'Interp']
        parent = {'children': [
            {'node_type': 'INTERP', 'label': prefix + ['1']},
            {'node_type': 'INTERP', 'label': prefix + ['3']}
        ], 'label': ['204', 'Interp']}
        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': prefix + ['2']})
        self.assertEqual([(2, 1), (2, 2), (2, 3)],
                         [c['sortable'] for c in parent['children']])

        prefix = ['204', 'Interp', '2']
        parent = {'children': [
            {'node_type': 'INTERP', 'label': prefix + ['v']},
            {'node_type': 'INTERP', 'label': prefix + ['iv']}
        ], 'label': prefix}
        tree_builder.add_child(parent, {'node_type': 'INTERP',
                                        'label': prefix + ['ix']})
        self.assertEqual([(4,), (5,), (9,)],
                         [c['sortable'] for c in parent['children']])