def test_paragraph_with_marker(): ap = appendices.AppendixProcessor(1111) for text in ('(a) A paragraph', '(b) A paragraph', '(1) A paragraph', '(2) A paragraph', '(c) A paragraph'): ap.paragraph_with_marker(text, text) ap.paragraph_no_marker('some text') ap.paragraph_with_marker('(d) A paragraph', '(d) A paragraph') ap.end_group() stack = ap.m_stack.m_stack assert len(stack) == 1 level2 = [el[1] for el in stack[0]] assert len(level2) == 5 a, b, c, other, d = level2 assert a.label == ['a'] assert a.children == [] assert b.label == ['b'] assert len(b.children) == 2 assert c.label == ['c'] assert c.children == [] assert other.label == ['p1'] assert other.children == [] assert d.label == ['d'] assert d.children == [] b1, b2 = b.children assert b1.label == ['b', '1'] assert b1.children == [] assert b2.label == ['b', '2'] assert b2.children == []
def test_process_collapsed_keyterm(): with XMLBuilder('APPENDIX') as ctx: ctx.EAR("Pt. 1111, App. A") ctx.HD("Appendix A to Part 1111-Awesome", SOURCE="HED") ctx.child_from_string('<P>(a) <E T="03">Keyterm</E> (1) Content</P>') appendix = appendices.AppendixProcessor(1111).process(ctx.xml) appendix = NodeAccessor(appendix) assert appendix.child_labels == ['a'] assert appendix['a'].child_labels == ['1'] assert appendix['a']['1'].children == []
def test_process_part_cap(): with XMLBuilder('APPENDIX') as ctx: ctx.EAR("Pt. 1111, App. A") ctx.HD("Appendix A to Part 1111-Awesome", SOURCE="HED") ctx.HD("Part I - Stuff", SOURCE="HD1") ctx.P("A. Content") appendix = appendices.AppendixProcessor(1111).process(ctx.xml) assert len(appendix.children) == 1 ai = appendix.children[0] assert len(ai.children) == 1
def test_process_collapsed(): with XMLBuilder('APPENDIX') as ctx: ctx.EAR("Pt. 1111, App. A") ctx.HD("Appendix A to Part 1111-Awesome", SOURCE="HED") ctx.HD("Part I - Something", SOURCE="HD1") ctx.P(u"(a) Something referencing § 999.2(a)(1). (1) Content") ctx.P("(2) Something else") appendix = appendices.AppendixProcessor(1111).process(ctx.xml) appendix = NodeAccessor(appendix) assert appendix.child_labels == ['I'] assert appendix['I'].child_labels == ['a'] assert appendix['I']['a'].child_labels == ['1', '2'] assert appendix['I']['a']['1'].text == '(1) Content' assert appendix['I']['a']['2'].text == '(2) Something else'
def test_process_header_depth(): with XMLBuilder('APPENDIX') as ctx: ctx.EAR("Pt. 1111, App. A") ctx.HD("Appendix A to Part 1111-Awesome", SOURCE="HED") ctx.HD("Title 1", SOURCE="HD1") ctx.P("(1) Content 1") ctx.P("(2) Content 2") ctx.HD("Title 2", SOURCE="HD1") ctx.P("A. Content") appendix = appendices.AppendixProcessor(1111).process(ctx.xml) appendix = NodeAccessor(appendix) assert appendix.child_labels == ['h1', 'h2'] assert appendix['h1'].child_labels == ['1', '2'] assert appendix['h2'].child_labels == ['A']
def test_process_depth_look_forward(): with XMLBuilder('APPENDIX') as ctx: ctx.EAR("Pt. 1111, App. A") ctx.HD("Appendix A to Part 1111-Awesome", SOURCE='HED') ctx.P("(a) aaaaa") ctx.P("(i) iiiii") ctx.P("Text text") ctx.P("(ii) ii ii ii") appendix = appendices.AppendixProcessor(1111).process(ctx.xml) assert len(appendix.children) == 1 aa = appendix.children[0] child_labels = [child.label for child in aa.children] assert ['1111', 'A', 'a', 'i'] in child_labels assert ['1111', 'A', 'a', 'ii'] in child_labels
def test_process_separated_by_header(): with XMLBuilder('APPENDIX') as ctx: ctx.EAR('Pt. 1111, App. A') ctx.HD('Appendix A to Part 1111-Awesome', SOURCE='HED') ctx.P('(a) aaaaaa') ctx.P('(1) 111111') ctx.HD('Random Header', SOURCE='HD1') ctx.P('(2) 222222') ctx.P('Markerless') appendix = appendices.AppendixProcessor(1111).process(ctx.xml) appendix = NodeAccessor(appendix) assert appendix.child_labels == ['a'] assert appendix['a'].child_labels == ['1', '2', 'p1'] assert appendix['a']['1'].child_labels == ['h1'] assert appendix['a']['2'].children == [] assert appendix['a']['p1'].children == []
def test_paragraph_no_marker(): ap = appendices.AppendixProcessor(1111) ap.paragraph_no_marker("Paragraph Text") ap.end_group() lvl, node = ap.m_stack.peek_last() assert node.text == 'Paragraph Text' assert lvl == 1 assert node.label == ['p1'] # If a header was before the paragraph, increment the level 1 ap.m_stack.add(1, Node(label=['h1'], title='Some section')) ap.paragraph_no_marker("Paragraph Text") ap.end_group() lvl, node = ap.m_stack.peek_last() assert node.text == 'Paragraph Text' assert lvl == 2 assert node.label == ['p2']
def test_paragraph_roman(): ap = appendices.AppendixProcessor(1111) for text in ("(1) A paragraph", "(a) A paragraph", "(i) A paragraph", "(ii) A paragraph", "(iii) A paragraph", "(iv) A paragraph", "(v) A paragraph"): ap.paragraph_with_marker(text, text) ap.end_group() stack = ap.m_stack.m_stack assert len(stack) == 3 level2, level3, level4 = [[el[1] for el in lvl] for lvl in stack] assert len(level2) == 1 assert level2[0].label == ['1'] assert len(level3) == 1 assert level3[0].label == ['a'] assert len(level4) == 5 assert [el.label[0] for el in level4] == ['i', 'ii', 'iii', 'iv', 'v']
def test_paragraph_period(): ap = appendices.AppendixProcessor(1111) for text in ("1. A paragraph", "(a) A paragraph", "A. A paragraph"): ap.paragraph_with_marker(text, text) ap.paragraph_no_marker("code . is here") ap.end_group() stack = ap.m_stack.m_stack assert len(stack) == 3 level2, level3, level4 = [[el[1] for el in lvl] for lvl in stack] assert len(level2) == 1 assert level2[0].label == ['1'] assert len(level3) == 1 assert level3[0].label == ['a'] assert len(level4) == 2 assert level4[0].label == ['A'] assert level4[1].label == ['p1']
def test_paragraph_double_depth(): ap = appendices.AppendixProcessor(1111) for text in ("(a) A paragraph", "(1) A paragraph", "(i) A paragraph", "(A) A paragraph", "(a) A paragraph"): ap.paragraph_with_marker(text, text) ap.end_group() stack = ap.m_stack.m_stack assert len(stack) == 5 levels = [[el[1] for el in lvl] for lvl in stack] assert len(levels) == 5 for lvl in levels: assert len(lvl) == 1 level2, level3, level4, level5, level6 = levels assert level2[0].label == ['a'] assert level3[0].label == ['1'] assert level4[0].label == ['i'] assert level5[0].label == ['A'] assert level6[0].label == ['a']