def runTest(self): # ARRANGE # root = Element('root') table = Table(TableFormat(first_row_is_header=True), [ [text_cell('ignored'), text_cell('ignored')], [text_cell('ignored'), text_cell('ignored')], ]) # ACT # ret_val = sut.render(ConstantPRenderer('para text'), root, table) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<table>' '<tr>' '<th>para text</th>' '<th>para text</th>' '</tr>' '<tr>' '<td>para text</td>' '<td>para text</td>' '</tr>' '</table>' '</root>', xml_string) self.assertIs(list(root)[0], ret_val)
def test_single_anchor_with_cross_reference_as_anchored_text(self): # ARRANGE # root = Element('root') para = Paragraph([ core.AnchorText( core.CrossReferenceText( StringText('cross ref title'), CrossReferenceTargetTestImpl('cross ref target'), target_is_id_in_same_document=True), CrossReferenceTargetTestImpl('anchor target')), ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<span id="anchor target">' '<a href="#cross ref target">cross ref title</a>' '</span>' '</root>', xml_string) self.assertIs(root, ret_val)
def runTest(self): # ARRANGE # root = Element('root') table = Table(TableFormat(first_row_is_header=True), [ [text_cell('ignored'), text_cell('ignored')], [text_cell('ignored'), text_cell('ignored')], ]) # ACT # ret_val = sut.render(ConstantPRenderer('para text'), root, table) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<table>' '<tr>' '<th>para text</th>' '<th>para text</th>' '</tr>' '<tr>' '<td>para text</td>' '<td>para text</td>' '</tr>' '</table>' '</root>', xml_string) self.assertIs(list(root)[0], ret_val)
def test_empty(self): # ARRANGE # root = Element('root') para = Paragraph([]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def test_single_empty_row(self): # ARRANGE # root = Element('root') table = Table(TableFormat(), [[]]) # ACT # ret_val = sut.render(ConstantPRenderer('para text'), root, table) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def test_two_string_text(self): # ARRANGE # root = Element('root') para = Paragraph([core.StringText('_1_'), core.StringText('_2_')]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<p>_1_<br />_2_</p>' '</root>', xml_string) self._assert_first_child__of_actual_is_same_object_as(root, ret_val)
def test_empty(self): # ARRANGE # root = Element('root') sc = SectionContents([], []) # ACT # ret_val = TEST_RENDERER.render_section_contents( sut.Environment(0), root, sc) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def test_empty(self): # ARRANGE # root = Element('root') para = Paragraph([]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def runTest(self): # ARRANGE # root = Element('root') ll = LiteralLayout(LITERAL_MULTI_LINE_TEXT, 'the-class') # ACT # ret_val = sut.render(root, ll) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual(LITERAL_MULTI_LINE_TEXT_RESULT_W_CLASS, xml_string) self.assertIs(list(root)[0], ret_val)
def runTest(self): # ARRANGE # root = Element('root') ll = LiteralLayout(LITERAL_MULTI_LINE_TEXT) # ACT # ret_val = sut.render(root, ll) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual(LITERAL_MULTI_LINE_TEXT_RESULT, xml_string) self.assertIs(list(root)[0], ret_val)
def test_single_string_text(self): # ARRANGE # root = Element('root') para = Paragraph([core.StringText('string text')]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<p>string text</p>' '</root>', xml_string) self._assert_first_child__of_actual_is_same_object_as(root, ret_val)
def test_two_string_text(self): # ARRANGE # root = Element('root') para = Paragraph([core.StringText('_1_'), core.StringText('_2_')]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '_1_<br />_2_' '</root>', xml_string) self.assertIs(root, ret_val)
def test_empty(self): # ARRANGE # root = Element('root') sc = SectionContents([], []) # ACT # ret_val = TEST_RENDERER.render_section_contents(sut.Environment(0), root, sc) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def test_empty(self): # ARRANGE # for list_type in ListType: with self.subTest(list_type=list_type): root = Element('root') the_list = HeaderContentList([], Format(list_type)) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), ConstantPRenderer('para text'), root, the_list) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def test_single_string_text(self): # ARRANGE # root = Element('root') para = Paragraph([core.StringText('string text')]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' 'string text' '</root>', xml_string) self.assertIs(root, ret_val)
def test_single_empty_row(self): # ARRANGE # root = Element('root') table = Table(TableFormat(), [[]]) # ACT # ret_val = sut.render(ConstantPRenderer('para text'), root, table) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def test_simple_document(self): # ARRANGE # root = Element('root') complex_populator = sut.ComplexElementPopulator([ SingleParaPopulator('first'), SingleParaPopulator('second'), ]) # ACT # complex_populator.apply(root) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<p>first</p>' '<p>second</p>' '</root>', xml_string)
def test_simple_document(self): # ARRANGE # root = Element('root') complex_populator = sut.ComplexElementPopulator([ SingleParaPopulator('first'), SingleParaPopulator('second'), ]) # ACT # complex_populator.apply(root) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<p>first</p>' '<p>second</p>' '</root>', xml_string)
def test_single_anchor_with_string_as_anchored_text(self): # ARRANGE # root = Element('root') para = Paragraph([core.AnchorText(core.StringText('concrete string'), CrossReferenceTargetTestImpl('target')), ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<span id="target">concrete string</span>' '</root>', xml_string) self.assertIs(root, ret_val)
def test_empty(self): # ARRANGE # for list_type in ListType: with self.subTest(list_type=list_type): root = Element('root') the_list = HeaderContentList([], Format(list_type)) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), ConstantPRenderer('para text'), root, the_list) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root />', xml_string) self.assertIs(root, ret_val)
def test_single_anchor_with_string_as_anchored_text(self): # ARRANGE # root = Element('root') para = Paragraph([core.AnchorText(core.StringText('concrete string'), CrossReferenceTargetTestImpl('target')), ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<p>' '<span id="target">concrete string</span>' '</p>' '</root>', xml_string) self._assert_first_child__of_actual_is_same_object_as(root, ret_val)
def test_cross_reference_and_string(self): # ARRANGE # root = Element('root') para = Paragraph([core.CrossReferenceText(StringText('title'), CrossReferenceTargetTestImpl('target'), target_is_id_in_same_document=True), core.StringText('string')]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<a href="#target">title</a><br />string' '</root>', xml_string) self.assertIs(root, ret_val)
def test(self): cases = [ Case( 'test_singleton_element_without_contents', items= [HeaderContentListItem(text('header'))], expected= '<root>' '<dl>' '<dt>header</dt>' '</dl>' '</root>' ), Case( 'test_singleton_element_with_multiple_content_paragraphs', items= [HeaderContentListItem(text('header'), [para('ignored'), para('ignored')])], expected= '<root>' '<dl>' '<dt>header</dt>' '<dd>' '<p>every para text</p>' '<p>every para text</p>' '</dd>' '</dl>' '</root>' ), ] for case in cases: with self.subTest(case.name): root = Element('root') the_list = HeaderContentList(case.items, Format(ListType.VARIABLE_LIST)) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), ConstantPRenderer('every para text'), root, the_list) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual(case.expected, xml_string) self.assertIs(list(root)[0], ret_val)
def test_single_anchor_with_string_as_anchored_text(self): # ARRANGE # root = Element('root') para = Paragraph([ core.AnchorText(core.StringText('concrete string'), CrossReferenceTargetTestImpl('target')), ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<p>' '<span id="target">concrete string</span>' '</p>' '</root>', xml_string) self._assert_first_child__of_actual_is_same_object_as(root, ret_val)
def test_single_cross_reference_to_not_id_in_same_document(self): # ARRANGE # root = Element('root') para = Paragraph([core.CrossReferenceText(StringText('title'), CrossReferenceTargetTestImpl('target'), target_is_id_in_same_document=False), ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<p>' '<a href="target">title</a>' '</p>' '</root>', xml_string) self._assert_first_child__of_actual_is_same_object_as(root, ret_val)
def test_single_anchor_with_string_as_anchored_text(self): # ARRANGE # root = Element('root') para = Paragraph([ core.AnchorText(core.StringText('concrete string'), CrossReferenceTargetTestImpl('target')), ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<span id="target">concrete string</span>' '</root>', xml_string) self.assertIs(root, ret_val)
def test_two_cross_reference(self): # ARRANGE # root = Element('root') para = Paragraph([core.CrossReferenceText(StringText('title 1'), CrossReferenceTargetTestImpl('target 1')), core.CrossReferenceText(StringText('title 2'), CrossReferenceTargetTestImpl('target 2'))]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<a href="#target 1">' 'title 1</a><br /><a href="#target 2">title 2' '</a>' '</root>', xml_string) self.assertIs(root, ret_val)
def test_single_cross_reference_to_not_id_in_same_document(self): # ARRANGE # root = Element('root') para = Paragraph([ core.CrossReferenceText(StringText('title'), CrossReferenceTargetTestImpl('target'), target_is_id_in_same_document=False), ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<p>' '<a href="target">title</a>' '</p>' '</root>', xml_string) self._assert_first_child__of_actual_is_same_object_as(root, ret_val)
def test_two_cross_reference(self): # ARRANGE # root = Element('root') para = Paragraph([core.CrossReferenceText(StringText('title 1'), CrossReferenceTargetTestImpl('target 1')), core.CrossReferenceText(StringText('title 2'), CrossReferenceTargetTestImpl('target 2'))]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<p>' '<a href="#target 1">' 'title 1</a><br /><a href="#target 2">title 2' '</a>' '</p>' '</root>', xml_string) self._assert_first_child__of_actual_is_same_object_as(root, ret_val)
def test_single_anchor_with_cross_reference_as_anchored_text(self): # ARRANGE # root = Element('root') para = Paragraph([ core.AnchorText(core.CrossReferenceText(StringText('cross ref title'), CrossReferenceTargetTestImpl('cross ref target'), target_is_id_in_same_document=True), CrossReferenceTargetTestImpl('anchor target')), ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual('<root>' '<span id="anchor target">' '<a href="#cross ref target">cross ref title</a>' '</span>' '</root>', xml_string) self.assertIs(root, ret_val)
def test_cross_reference_and_string(self): # ARRANGE # root = Element('root') para = Paragraph([ core.CrossReferenceText(StringText('title'), CrossReferenceTargetTestImpl('target'), target_is_id_in_same_document=True), core.StringText('string') ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<a href="#target">title</a><br />string' '</root>', xml_string) self.assertIs(root, ret_val)
def test_two_cross_reference(self): # ARRANGE # root = Element('root') para = Paragraph([ core.CrossReferenceText(StringText('title 1'), CrossReferenceTargetTestImpl('target 1')), core.CrossReferenceText(StringText('title 2'), CrossReferenceTargetTestImpl('target 2')) ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<p>' '<a href="#target 1">' 'title 1</a><br /><a href="#target 2">title 2' '</a>' '</p>' '</root>', xml_string) self._assert_first_child__of_actual_is_same_object_as(root, ret_val)
def test(self): cases = [ Case('test_singleton_element_without_contents', items=[HeaderContentListItem(text('header'))], expected='<root>' '<dl>' '<dt>header</dt>' '</dl>' '</root>'), Case('test_singleton_element_with_multiple_content_paragraphs', items=[ HeaderContentListItem( text('header'), [para('ignored'), para('ignored')]) ], expected='<root>' '<dl>' '<dt>header</dt>' '<dd>' '<p>every para text</p>' '<p>every para text</p>' '</dd>' '</dl>' '</root>'), ] for case in cases: with self.subTest(case.name): root = Element('root') the_list = HeaderContentList(case.items, Format(ListType.VARIABLE_LIST)) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), ConstantPRenderer('every para text'), root, the_list) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual(case.expected, xml_string) self.assertIs(list(root)[0], ret_val)
def test_two_cross_reference(self): # ARRANGE # root = Element('root') para = Paragraph([ core.CrossReferenceText(StringText('title 1'), CrossReferenceTargetTestImpl('target 1')), core.CrossReferenceText(StringText('title 2'), CrossReferenceTargetTestImpl('target 2')) ]) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), root, para, skip_surrounding_p_element=True) # ASSERT # xml_string = as_unicode_str(root) self.assertEqual( '<root>' '<a href="#target 1">' 'title 1</a><br /><a href="#target 2">title 2' '</a>' '</root>', xml_string) self.assertIs(root, ret_val)
def test_non_empty(self): # ARRANGE # cases = [ Case( 'test_singleton_element_without_contents', items=[HeaderContentListItem(text('header'))], expected='<root>' '<{L}><li>header</li></{L}>' '</root>', ), Case( 'test_multiple_element_without_contents', items=[ HeaderContentListItem(text('header 1')), HeaderContentListItem(text('header 2')) ], expected='<root>' '<{L}>' '<li>header 1</li>' '<li>header 2</li>' '</{L}>' '</root>', ), Case( 'test_single_element_with_single_para_contents', items=[ HeaderContentListItem(text('header'), paras('ignored')) ], expected='<root>' '<{L}>' '<li>header<p>every para text</p></li>' '</{L}>' '</root>', ), Case( 'test_single_element_with_multiple_para_contents', items=[ HeaderContentListItem( text('header'), [para('ignored'), para('ignored')]) ], expected='<root>' '<{L}>' '<li>header' '<p>every para text</p>' '<p>every para text</p>' '</li>' '</{L}>' '</root>', ), ] for list_type, element in [(ListType.ITEMIZED_LIST, 'ul'), (ListType.ORDERED_LIST, 'ol')]: for case in cases: with self.subTest(list_type=list_type, case=case.name): root = Element('root') the_list = HeaderContentList(case.items, Format(list_type)) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), ConstantPRenderer('every para text'), root, the_list) # ASSERT # expected = case.expected.format(L=element) xml_string = as_unicode_str(root) self.assertEqual(expected, xml_string) self.assertIs(list(root)[0], ret_val)
def test_non_empty(self): # ARRANGE # cases = [ Case('test_singleton_element_without_contents', items= [HeaderContentListItem(text('header'))], expected= '<root>' '<{L}><li>header</li></{L}>' '</root>', ), Case('test_multiple_element_without_contents', items= [HeaderContentListItem(text('header 1')), HeaderContentListItem(text('header 2'))], expected= '<root>' '<{L}>' '<li>header 1</li>' '<li>header 2</li>' '</{L}>' '</root>', ), Case('test_single_element_with_single_para_contents', items= [HeaderContentListItem(text('header'), paras('ignored'))], expected= '<root>' '<{L}>' '<li>header<p>every para text</p></li>' '</{L}>' '</root>', ), Case('test_single_element_with_multiple_para_contents', items= [HeaderContentListItem(text('header'), [para('ignored'), para('ignored')])], expected= '<root>' '<{L}>' '<li>header' '<p>every para text</p>' '<p>every para text</p>' '</li>' '</{L}>' '</root>', ), ] for list_type, element in [(ListType.ITEMIZED_LIST, 'ul'), (ListType.ORDERED_LIST, 'ol')]: for case in cases: with self.subTest(list_type=list_type, case=case.name): root = Element('root') the_list = HeaderContentList(case.items, Format(list_type)) # ACT # ret_val = sut.render(TextRenderer(TARGET_RENDERER), ConstantPRenderer('every para text'), root, the_list) # ASSERT # expected = case.expected.format(L=element) xml_string = as_unicode_str(root) self.assertEqual(expected, xml_string) self.assertIs(list(root)[0], ret_val)