Example #1
0
 def test(self):
     # ARRANGE #
     root_element_to_mutate = Element('root')
     header_1_text = 'header 1'
     header_2_text = 'header 2'
     sc = SectionContents([], [
         Section(StringText(header_1_text), SectionContents([], [])),
         Section(StringText(header_2_text), SectionContents([], [])),
     ])
     expected_element = element(root_element_to_mutate.tag,
                                children=[
                                    element('section',
                                            children=[
                                                _header_w_h(header_1_text),
                                            ]),
                                    element('section',
                                            children=[
                                                _header_w_h(header_2_text),
                                            ]),
                                ])
     # ACT #
     ret_val = TEST_RENDERER.render_section_contents(
         sut.Environment(0), root_element_to_mutate, sc)
     # ASSERT #
     assert_contents_and_that_last_child_is_returned(
         expected_element, root_element_to_mutate, ret_val, self)
Example #2
0
    def test_complex_structure_with_reset_of_section_level(self):
        # ARRANGE #
        s = Article(
            StringText('article header'),
            ArticleContents(
                [para('para in abstract')],
                SectionContents([para('initial para in contents')], [
                    Section(
                        StringText('header 1/1'),
                        SectionContents([para('para 1/1')], [
                            Section(StringText('header 1/1/1'),
                                    SectionContents([para('para 1/1/1')], []))
                        ]))
                ])))
        for section_level in range(3):
            with self.subTest('section level = ' + str(section_level)):
                root = Element('root')
                environment = sut.Environment(section_level)
                # ACT #
                ret_val = TEST_RENDERER.render_section_item(
                    environment, root, s)
                # ASSERT #
                expected_element = element(
                    'root',
                    children=[
                        element('article',
                                children=[
                                    element(
                                        'header',
                                        children=[
                                            element('h1',
                                                    text='article header'),
                                            element('p',
                                                    text='para in abstract'),
                                        ],
                                    ),
                                    element('p',
                                            text='initial para in contents'),
                                    element(
                                        'section',
                                        children=[
                                            _header_w_h('header 1/1'),
                                            element('p', text='para 1/1'),
                                            element(
                                                'section',
                                                children=[
                                                    _header_w_h(
                                                        'header 1/1/1', 'h2'),
                                                    element('p',
                                                            text='para 1/1/1'),
                                                ])
                                        ])
                                ])
                    ])

                assert_contents_and_that_last_child_is_returned(
                    expected_element, root, ret_val, self)
Example #3
0
 def test_section_content_indent__for_nested_sections(self):
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=100),
         num_item_separator_lines=0)
     content_indent = '  '
     formatter = sut.Formatter(
         paragraph_item_formatter,
         section_content_indent_str=content_indent,
         separation=sut.Separation(
             between_sections=1,
             between_header_and_content=2,
             between_initial_paragraphs_and_sub_sections=3))
     header = text('Section 1')
     contents = SectionContents([], [
         Section(
             text('Section 1.1'),
             SectionContents(
                 [single_text_para('paragraph in section 1.1')], [
                     Section(
                         text('Section 1.1.1'),
                         SectionContents([
                             single_text_para('paragraph in section 1.1.1')
                         ], []))
                 ]))
     ])
     cases = [
         ('section', Section(header, contents)),
         ('article', Article(header, ArticleContents([], contents))),
     ]
     for test_case_name, section_item in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(section_item)
             #  ASSERT #
             self.assertEqual([
                 'Section 1',
                 BLANK_LINE,
                 BLANK_LINE,
                 (1 * content_indent) + 'Section 1.1',
                 BLANK_LINE,
                 BLANK_LINE,
                 (2 * content_indent) + 'paragraph in section 1.1',
                 BLANK_LINE,
                 BLANK_LINE,
                 BLANK_LINE,
                 (2 * content_indent) + 'Section 1.1.1',
                 BLANK_LINE,
                 BLANK_LINE,
                 (3 * content_indent) + 'paragraph in section 1.1.1',
             ], actual)
Example #4
0
 def test_simple_document(self):
     # ARRANGE #
     section_contents = SectionContents([para('para 0')], [
         Section(StringText('header 1'),
                 SectionContents([para('para 1'), para('')], []))
     ])
     document_setup = sut.DocumentSetup('page title')
     # ACT #
     output_file = io.StringIO()
     DOCUMENT_RENDERER.apply(output_file, document_setup, section_contents)
     actual = output_file.getvalue()
     # ASSERT #
     expected = (DOCTYPE_XHTML1_0 + '<html>'
                 '<head>'
                 '<title>page title</title>'
                 '</head>'
                 '<body>'
                 '<p>para 0</p>'
                 '<section>'
                 '<header>'
                 '<h1>header 1</h1>'
                 '</header>'
                 '<p>para 1</p>'
                 '<p></p>'
                 '</section>'
                 '</body>'
                 '</html>')
     self.assertEqual(expected, actual)
Example #5
0
 def test_empty_section_item(self):
     # ARRANGE #
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=100),
         num_item_separator_lines=0)
     formatter = sut.Formatter(
         paragraph_item_formatter,
         sut.Separation(between_sections=1,
                        between_header_and_content=2,
                        between_initial_paragraphs_and_sub_sections=3))
     header_string = 'Section Header'
     cases = [
         ('section', empty_section(header_string)),
         ('section with target',
          Section(text(header_string),
                  empty_section_contents(),
                  target=CrossReferenceTarget())),
         ('article', empty_article(header_string)),
         ('article with target',
          Article(text(header_string),
                  empty_article_contents(),
                  target=CrossReferenceTarget())),
     ]
     for test_case_name, section_item in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(section_item)
             # ASSERT #
             self.assertEqual([header_string], actual)
Example #6
0
 def test_separation_between_header_and_content__with_both_initial_paragraphs_and_sub_sections(
         self):
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=100),
         num_item_separator_lines=0)
     formatter = sut.Formatter(
         paragraph_item_formatter,
         sut.Separation(between_sections=1,
                        between_header_and_content=2,
                        between_initial_paragraphs_and_sub_sections=3))
     header_string = 'Section Header'
     contents = SectionContents([single_text_para('initial paragraph')],
                                [empty_section('Content Section Header')])
     cases = [
         ('section', Section(text(header_string), contents)),
         ('article',
          Article(text(header_string), ArticleContents([], contents))),
     ]
     for test_case_name, section_item in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(section_item)
             #  ASSERT #
             self.assertEqual([
                 header_string,
                 BLANK_LINE,
                 BLANK_LINE,
                 'initial paragraph',
                 BLANK_LINE,
                 BLANK_LINE,
                 BLANK_LINE,
                 'Content Section Header',
             ], actual)
Example #7
0
    def test(self):
        # ARRANGE #
        root_element_to_mutate = Element('root')
        section_header_text = 'section header'
        article_header_text = 'article header'
        sc = SectionContents([], [
            Section(StringText(section_header_text), SectionContents([], [])),
            Article(StringText(article_header_text),
                    ArticleContents([], SectionContents([], []))),
        ])
        expected_element = element(
            root_element_to_mutate.tag,
            children=[
                element('section',
                        children=[
                            _header_w_h(section_header_text, 'h3'),
                        ]),
                element('article',
                        children=[
                            _header_w_h(article_header_text),
                        ]),
            ])

        # ACT #
        ret_val = TEST_RENDERER.render_section_contents(
            sut.Environment(2), root_element_to_mutate, sc)
        # ASSERT #
        assert_contents_and_that_last_child_is_returned(
            expected_element, root_element_to_mutate, ret_val, self)
Example #8
0
 def test_section_content_indent_w_literal_layout_indent(self):
     ll_indent = 'LLI '
     content_indent = 'CI '
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=100),
         num_item_separator_lines=0,
         literal_layout_indent=ll_indent)
     formatter = sut.Formatter(
         paragraph_item_formatter,
         section_content_indent_str=content_indent,
         separation=sut.Separation(
             between_sections=1,
             between_header_and_content=2,
             between_initial_paragraphs_and_sub_sections=3))
     header = text('Section Header')
     contents = SectionContents([LiteralLayout('literal layout 1')], [
         Section(text('Sub Section Header'),
                 SectionContents([LiteralLayout('literal layout 2')]))
     ])
     cases = [
         ('section', Section(header, contents)),
         ('article', Article(header, ArticleContents([], contents))),
     ]
     for test_case_name, section_item in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(section_item)
             # ASSERT #
             self.assertEqual([
                 'Section Header',
                 BLANK_LINE,
                 BLANK_LINE,
                 content_indent + ll_indent + 'literal layout 1',
                 BLANK_LINE,
                 BLANK_LINE,
                 BLANK_LINE,
                 content_indent + 'Sub Section Header',
                 BLANK_LINE,
                 BLANK_LINE,
                 content_indent * 2 + ll_indent + 'literal layout 2',
             ], actual)
def path_type_path_rendering() -> SectionItem:
    tp = TextParser({
        'current_directory_concept': formatting.concept_(concepts.CURRENT_WORKING_DIRECTORY_CONCEPT_INFO),
        'def_instruction': InstructionName(instruction_names.SYMBOL_DEFINITION_INSTRUCTION_NAME),
        'symbol_concept': formatting.concept(concepts.SYMBOL_CONCEPT_INFO.singular_name),
        'rel_cd_option': formatting.cli_option(path.REL_CWD_OPTION),
        'path_type': types.PATH_TYPE_INFO.name,
        'external_program': misc_texts.EXTERNAL_PROGRAM,
        'os_process': misc_texts.OS_PROCESS_NAME,
        'Note': headers.NOTE_LINE_HEADER,
    })
    return Section(tp.text(_PATH_TYPE_PATH_RENDERING_DESCRIPTION_HEADER),
                   tp.section_contents(_PATH_TYPE_PATH_RENDERING_DESCRIPTION))
Example #10
0
    def test_single_sub_section_with_initial_paras_everywhere(self):
        # ARRANGE #
        root_element_to_mutate = Element('root')
        para_0_text = 'para 0'
        header_1_text = 'header 1'
        para_1_text = 'para 1'
        header_1_1_text = 'header 1/1'
        para_2_text = 'para 2'
        sc = SectionContents([para(para_0_text)], [
            Section(
                StringText(header_1_text),
                SectionContents([para(para_1_text)], [
                    Section(StringText(header_1_1_text),
                            SectionContents([para(para_2_text)], []))
                ]))
        ])
        expected_element = element(
            root_element_to_mutate.tag,
            children=[
                element('p', text=para_0_text),
                element('section',
                        children=[
                            _header_w_h(header_1_text),
                            element('p', text=para_1_text),
                            element('section',
                                    children=[
                                        _header_w_h(header_1_1_text, 'h2'),
                                        element('p', text=para_2_text),
                                    ])
                        ]),
            ])

        # ACT #
        ret_val = TEST_RENDERER.render_section_contents(
            sut.Environment(0), root_element_to_mutate, sc)
        # ASSERT #
        assert_contents_and_that_last_child_is_returned(
            expected_element, root_element_to_mutate, ret_val, self)
Example #11
0
 def test_section_with_single_initial_para(self):
     # ARRANGE #
     root_element_to_mutate = Element('root')
     section_header_text = 'section header'
     initial_para_text = 'initial para'
     sc = SectionContents([], [
         Section(StringText(section_header_text),
                 SectionContents([para(initial_para_text)], []))
     ])
     expected_element = element(
         root_element_to_mutate.tag,
         children=[
             element('section',
                     children=[
                         _header_w_h(section_header_text),
                         element('p', text=initial_para_text)
                     ])
         ])
     # ACT #
     ret_val = TEST_RENDERER.render_section_contents(
         sut.Environment(0), root_element_to_mutate, sc)
     # ASSERT #
     assert_contents_and_that_last_child_is_returned(
         expected_element, root_element_to_mutate, ret_val, self)
Example #12
0
    def visit_article(self, article: Article) -> List[str]:
        as_section = Section(article.header,
                             article.contents.combined_as_section_contents)

        return self.format_section(as_section)
Example #13
0
def name_parts_description() -> Section:
    return Section(docs.text('File name parts'),
                   docs.SectionContents([_name_parts_table()]))
Example #14
0
def section(header_str_or_text: StrOrText,
            paragraphs: List[ParagraphItem],
            sub_sections: List[SectionItem] = None) -> Section:
    return Section(
        text_from_unknown(header_str_or_text),
        SectionContents(paragraphs, _empty_list_if_none(sub_sections)))
Example #15
0
 def test(self):
     # ARRANGE #
     cases = [
         ('empty', Section(StringText('header 1'),
                           empty_section_contents()),
          element('root',
                  children=[
                      element('section',
                              children=[
                                  _header_w_h('header 1'),
                              ])
                  ])),
         ('empty with target',
          Section(
              StringText('header 1'),
              empty_section_contents(),
              target=CrossReferenceTargetTestImpl('section-target-name')),
          element('root',
                  children=[
                      element('section',
                              attributes={'id': 'section-target-name'},
                              children=[_header_w_h('header 1')])
                  ])),
         ('empty with tags',
          Section(StringText('header 1'),
                  empty_section_contents(),
                  tags={'first-label', 'second-label'}),
          element('root',
                  children=[
                      element(
                          'section',
                          attributes={'class': 'first-label second-label'},
                          children=[_header_w_h('header 1')])
                  ])),
         ('empty with target and tags',
          Section(StringText('header 1'),
                  empty_section_contents(),
                  target=CrossReferenceTargetTestImpl('t'),
                  tags={'l1', 'l2'}),
          element('root',
                  children=[
                      element('section',
                              attributes={
                                  'class': 'l1 l2',
                                  'id': 't'
                              },
                              children=[_header_w_h('header 1')])
                  ])),
         ('with contents',
          Section(
              StringText('header 1'),
              SectionContents([para('para 1')], [
                  Section(StringText('header 1/1'),
                          SectionContents([para('para 1/1')], []))
              ])),
          element('root',
                  children=[
                      element('section',
                              children=[
                                  _header_w_h('header 1'),
                                  element('p', text='para 1'),
                                  element('section',
                                          children=[
                                              _header_w_h(
                                                  'header 1/1', 'h2'),
                                              element('p', text='para 1/1'),
                                          ])
                              ])
                  ])),
     ]
     for test_case_name, section, expected in cases:
         with self.subTest(test_case_name):
             root_element_to_mutate = Element('root')
             # ACT #
             ret_val = TEST_RENDERER.render_section_item(
                 sut.Environment(0), root_element_to_mutate, section)
             # ASSERT #
             assert_contents_and_that_last_child_is_returned(
                 expected, root_element_to_mutate, ret_val, self)