コード例 #1
0
    def test_paragraph_tree_with_children(self):
        fill = "dsfdffsfs\n"
        t1 = 'Q-3 This is the title'
        p1 = '\nSome paragraph\nContent\nmore\ncontent\n'
        t2 = 'Q-5--Spacing spacing'
        p2 = '\nMore paragraphs\nWe love them all\nParagraphs\n'
        t3 = 'Q-44 - Title here'
        p3 = '\nThird paragraph here'
        root = tree.paragraph_tree(
            'Q', [(len(fill), len(fill + t1 + p1)),
                  (len(fill + t1 + p1), len(fill + t1 + p1 + t2 + p2)),
                  (len(fill + t1 + p1 + t2 + p2),
                   len(fill + t1 + p1 + t2 + p2 + t3 + p3))],
            fill + t1 + p1 + t2 + p2 + t3 + p3, ['l'])
        self.assertEqual(fill, root.text)
        self.assertEqual(['l'], root.label)
        self.assertEqual(3, len(root.children))

        node = root.children[0]
        self.assertEqual(p1, node.text)
        self.assertEqual(['l', '3'], node.label)
        self.assertEqual(t1, node.title)
        self.assertEqual(0, len(node.children))

        node = root.children[1]
        self.assertEqual(p2, node.text)
        self.assertEqual(['l', '5'], node.label)
        self.assertEqual(t2, node.title)
        self.assertEqual(0, len(node.children))

        node = root.children[2]
        self.assertEqual(p3, node.text)
        self.assertEqual(['l', '44'], node.label)
        self.assertEqual(t3, node.title)
        self.assertEqual(0, len(node.children))
コード例 #2
0
    def test_trees_from(self):
        reg_text = "Some reg text\nOther reg text\nSection 55. etc.\n"
        titleC = "Appendix C to Part 22 The Reckoning"
        bodyC = "\nSome content\nWith no structure\n"
        titleJ = "Appendix J to Part 22 Junior Notes"
        bodyJ = "\nTitle One\ncontent content\nTitle Two\nmore content\n"
        titleR = "Appendix R to Part 22 Reserved"
        bodyR = "\nR-1--Some Section\nmore more\nR-5--Header\nthen more"

        text = reg_text + titleC + bodyC + titleJ + bodyJ + titleR + bodyR

        nodes = tree.trees_from(text, 22, ['22'])
        self.assertTrue(3, len(nodes))

        self.assertEqual(tree.generic_tree(bodyC, ['22', 'C'], titleC),
                         nodes[0])
        self.assertEqual(tree.generic_tree(bodyJ, ['22', 'J'], titleJ),
                         nodes[1])
        self.assertEqual(
            tree.paragraph_tree('R', [(1, 29), (29, len(bodyR))], bodyR,
                                ['22', 'R'], titleR), nodes[2])
コード例 #3
0
    def test_trees_from(self):
        reg_text = "Some reg text\nOther reg text\nSection 55. etc.\n"
        titleC = "Appendix C to Part 22 The Reckoning"
        bodyC = "\nSome content\nWith no structure\n"
        titleJ = "Appendix J to Part 22 Junior Notes"
        bodyJ = "\nTitle One\ncontent content\nTitle Two\nmore content\n"
        titleR = "Appendix R to Part 22 Reserved"
        bodyR = "\nR-1--Some Section\nmore more\nR-5--Header\nthen more"

        text = reg_text + titleC + bodyC + titleJ + bodyJ + titleR + bodyR

        nodes = tree.trees_from(text, 22, ['22'])
        self.assertTrue(3, len(nodes))

        self.assertEqual(tree.generic_tree(bodyC, ['22', 'C'], titleC),
                         nodes[0])
        self.assertEqual(tree.generic_tree(bodyJ, ['22', 'J'], titleJ),
                         nodes[1])
        self.assertEqual(
            tree.paragraph_tree('R', [(1, 29), (29, len(bodyR))], bodyR,
                                ['22', 'R'], titleR),
            nodes[2])
コード例 #4
0
    def test_paragraph_tree_with_children(self):
        fill = "dsfdffsfs\n"
        t1 = 'Q-3 This is the title'
        p1 = '\nSome paragraph\nContent\nmore\ncontent\n'
        t2 = 'Q-5--Spacing spacing'
        p2 = '\nMore paragraphs\nWe love them all\nParagraphs\n'
        t3 = 'Q-44 - Title here'
        p3 = '\nThird paragraph here'
        root = tree.paragraph_tree(
            'Q',
            [(len(fill), len(fill+t1+p1)),
             (len(fill+t1+p1), len(fill+t1+p1+t2+p2)),
             (len(fill+t1+p1+t2+p2), len(fill+t1+p1+t2+p2+t3+p3))],
            fill+t1+p1+t2+p2+t3+p3,
            ['l'])
        self.assertEqual(fill, root.text)
        self.assertEqual(['l'], root.label)
        self.assertEqual(3, len(root.children))

        node = root.children[0]
        self.assertEqual(p1, node.text)
        self.assertEqual(['l', '3'], node.label)
        self.assertEqual(t1, node.title)
        self.assertEqual(0, len(node.children))

        node = root.children[1]
        self.assertEqual(p2, node.text)
        self.assertEqual(['l', '5'], node.label)
        self.assertEqual(t2, node.title)
        self.assertEqual(0, len(node.children))

        node = root.children[2]
        self.assertEqual(p3, node.text)
        self.assertEqual(['l', '44'], node.label)
        self.assertEqual(t3, node.title)
        self.assertEqual(0, len(node.children))
コード例 #5
0
 def test_paragraph_tree_no_children(self):
     text = "Non title text"
     node = tree.paragraph_tree('A', [], text, ['lab'])
     self.assertEqual(Node(text, label=['lab'], node_type=Node.APPENDIX),
                      node)
コード例 #6
0
 def test_paragraph_tree_no_children(self):
     text = "Non title text"
     node = tree.paragraph_tree('A', [], text, ['lab'])
     self.assertEqual(Node(text, label=['lab'], node_type=Node.APPENDIX),
                      node)