def test_generic_tree_with_children(self): start = "some text\n" t1 = "Title Text One" b1 = "\nSome body text\nsomething\nsomething\n" t2 = "Section Two" b2 = "\nSomething else\nhere" t = tree.generic_tree(start + t1 + b1 + t2 + b2, ['s', 'l'], 'Some label') self.assertEqual(start, t.text) self.assertEqual(['s', 'l'], t.label) self.assertEqual('Some label', t.title) self.assertEqual(2, len(t.children)) node = t.children[0] self.assertEqual(b1, node.text) self.assertEqual(['s', 'l', 'a'], node.label) self.assertEqual(t1, node.title) self.assertEqual(0, len(node.children)) node = t.children[1] self.assertEqual(b2, node.text) self.assertEqual(['s', 'l', 'b'], node.label) self.assertEqual(t2, node.title) self.assertEqual(0, len(node.children))
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])
def test_generic_tree_no_children(self): text = "Non title text" node = tree.generic_tree(text, ['lab']) self.assertEqual(Node(text, label=['lab'], node_type=Node.APPENDIX), node)