Ejemplo n.º 1
0
 def test_article_separation_between_header_and_content(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 = text('Article Header')
     cases = [
         ('single abstract para / no contents para',
          Article(
              header,
              ArticleContents([single_text_para('abstract paragraph')],
                              empty_section_contents())), [
                                  'Article Header',
                                  BLANK_LINE,
                                  BLANK_LINE,
                                  'abstract paragraph',
                              ]),
         ('single abstract para / single contents para',
          Article(
              header,
              ArticleContents([single_text_para('abstract paragraph')],
                              single_para_contents('contents paragraph'))),
          [
              'Article Header',
              BLANK_LINE,
              BLANK_LINE,
              'abstract paragraph',
              'contents paragraph',
          ]),
         ('single abstract para / single contents para',
          Article(
              header,
              ArticleContents(
                  [single_text_para('abstract paragraph')],
                  SectionContents([],
                                  [empty_section('Sub Section Header')]))),
          [
              'Article Header',
              BLANK_LINE,
              BLANK_LINE,
              'abstract paragraph',
              BLANK_LINE,
              BLANK_LINE,
              BLANK_LINE,
              'Sub Section Header',
          ]),
     ]
     for test_case_name, article, expected_lines in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(article)
             #  ASSERT #
             self.assertEqual(expected_lines, actual)
Ejemplo n.º 2
0
 def apply(self, environment: ConstructionEnvironment) -> doc.Article:
     article_contents = self._contents_renderer.apply(environment)
     return doc.Article(self._node_target_info.presentation_text,
                        ArticleContents(article_contents.abstract_paragraphs,
                                        article_contents.section_contents),
                        target=self._node_target_info.target,
                        tags=self._tags)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def test_article(self):
     # ARRANGE   #
     article = sut.Article(
         StringText('header'),
         ArticleContents([], sut.empty_section_contents()))
     visitor = SectionItemVisitorThatRecordsExpectedClassAndReturnsArg()
     # ACT #
     ret_val = article.accept(visitor)
     # ASSERT #
     self.assertEqual([sut.Article], visitor.visited_classes)
     self.assertIs(article, ret_val)
Ejemplo n.º 7
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)
Ejemplo n.º 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)
Ejemplo n.º 9
0
 def test_simple(self):
     cases = [
         ('empty',
          Article(StringText('header'),
                  ArticleContents([], empty_section_contents())),
          element('root',
                  children=[
                      element('article', children=[
                          _header_w_h('header'),
                      ])
                  ])),
         ('empty with target',
          Article(StringText('header'),
                  ArticleContents([], empty_section_contents()),
                  target=CrossReferenceTargetTestImpl('target-name')),
          element('root',
                  children=[
                      element('article',
                              attributes={'id': 'target-name'},
                              children=[_header_w_h('header')])
                  ])),
         ('empty with tags',
          Article(StringText('header'),
                  ArticleContents([], empty_section_contents()),
                  tags={'label1', 'label2'}),
          element('root',
                  children=[
                      element('article',
                              attributes={'class': 'label1 label2'},
                              children=[_header_w_h('header')])
                  ])),
         ('empty with target and tags',
          Article(StringText('header'),
                  ArticleContents([], empty_section_contents()),
                  target=CrossReferenceTargetTestImpl('article-target'),
                  tags={'label1', 'label2'}),
          element('root',
                  children=[
                      element('article',
                              attributes={
                                  'class': 'label1 label2',
                                  'id': 'article-target'
                              },
                              children=[_header_w_h('header')])
                  ])),
         ('single abstract paragraph',
          Article(
              StringText('header'),
              ArticleContents([para('abstract paragraph')],
                              empty_section_contents())),
          element('root',
                  children=[
                      element('article',
                              children=[
                                  element(
                                      'header',
                                      children=[
                                          element('h1', text='header'),
                                          element(
                                              'p',
                                              text='abstract paragraph'),
                                      ],
                                  )
                              ])
                  ]))
     ]
     for test_case_name, article, expected in cases:
         with self.subTest(test_case_name):
             root = Element('root')
             environment = sut.Environment(0)
             # ACT #
             ret_val = TEST_RENDERER.render_section_item(
                 environment, root, article)
             # ASSERT #
             assert_contents_and_that_last_child_is_returned(
                 expected, root, ret_val, self)