Example #1
0
 def test_section_content_indent(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 Header')
     contents = SectionContents([single_text_para('initial paragraph')],
                                [Section(text('Sub Section Header'),
                                         empty_section_contents())])
     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 + 'initial paragraph',
                               BLANK_LINE,
                               BLANK_LINE,
                               BLANK_LINE,
                               content_indent + 'Sub Section Header',
                               ],
                              actual)
Example #2
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 #3
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 #4
0
 def test_separation_between_header_and_content__with_only_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([], [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,
                               'Content Section Header',
                               ],
                              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_multiple_new_line_blocks(self):
     p = para([text('1234 12'),
               text('34 5678')])
     formatter = formatter_with_page_width(5)
     actual = formatter.format_paragraph(p)
     self.assertEqual(['1234',
                       '12',
                       '34',
                       '5678'],
                      actual)
 def test_multiple_items_with_zero_separator_lines(self):
     p1 = para([text('1234 12 34')])
     p2 = para([text('abc')])
     formatter = sut.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                               sut.Wrapper(5),
                               num_item_separator_lines=0)
     actual = formatter.format_paragraph_items([p1, p2])
     self.assertEqual(['1234',
                       '12 34',
                       'abc'],
                      actual)
Example #8
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 #9
0
 def test_too_long_line(self):
     p = para([text('1234567')])
     formatter = formatter_with_page_width(5)
     actual = formatter.format_paragraph(p)
     self.assertEqual(['12345',
                       '67'],
                      actual)
Example #10
0
 def test_multiple_and_nested_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))
     section_contents = SectionContents([], [
         empty_section('Section 1'),
         sut.Section(
             text('Section 2'),
             sut.SectionContents([], [empty_article('Section 2.1')]))
     ])
     actual = formatter.format_section_contents(section_contents)
     self.assertEqual([
         'Section 1',
         BLANK_LINE,
         'Section 2',
         BLANK_LINE,
         BLANK_LINE,
         'Section 2.1',
     ], actual)
Example #11
0
 def test_single_new_line_block_with_alternate_page_width(self):
     p = para([text('1234 67 90')])
     formatter = formatter_with_page_width(7)
     actual = formatter.format_paragraph(p)
     self.assertEqual(['1234 67',
                       '90'],
                      actual)
Example #12
0
 def test_single_new_line_block(self):
     p = para([text('1234 12 34')])
     formatter = formatter_with_page_width(5)
     actual = formatter.format_paragraph(p)
     self.assertEqual(['1234',
                       '12 34'],
                      actual)
Example #13
0
 def test_header_text__element_number_2(self):
     formatter = sut.HeaderAndIndentFormatWithNumbering(
         contents_indent_spaces=5)
     actual = formatter.header_text(2, 1,
                                    CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                                    text('header'))
     self.assertEqual('2. header', actual)
Example #14
0
 def test_header_text(self):
     formatter = sut.HeaderAndIndentFormatWithMarker(
         marker='MARKER', contents_indent_spaces=3)
     actual = formatter.header_text(1, 1,
                                    CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                                    text('header'))
     self.assertEqual('MARKER header', actual)
Example #15
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)
 def test_single_item(self):
     p = para([text('1234 12 34')])
     formatter = sut.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                               sut.Wrapper(5),
                               num_item_separator_lines=1)
     actual = formatter.format_paragraph_items([p])
     self.assertEqual(['1234',
                       '12 34'],
                      actual)
Example #17
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)
Example #18
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)
Example #19
0
 def test_multiple_and_nested_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))
     section_contents = SectionContents([],
                                        [empty_section('Section 1'),
                                         sut.Section(text('Section 2'),
                                                     sut.SectionContents(
                                                         [],
                                                         [empty_article('Section 2.1')]))
                                         ])
     actual = formatter.format_section_contents(section_contents)
     self.assertEqual(['Section 1',
                       BLANK_LINE,
                       'Section 2',
                       BLANK_LINE,
                       BLANK_LINE,
                       'Section 2.1',
                       ],
                      actual)
Example #20
0
 def test_header_text__element_number_2(self):
     formatter = sut.HeaderAndIndentFormatWithNumbering(contents_indent_spaces=5)
     actual = formatter.header_text(2, 1, CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, text('header'))
     self.assertEqual('2. header',
                      actual)
Example #21
0
 def test_header_text(self):
     formatter = sut.HeaderAndIndentFormatPlain(contents_indent_spaces=5)
     actual = formatter.header_text(1, 1, CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, text('header'))
     self.assertEqual('header',
                      actual)
Example #22
0
 def test_header_text(self):
     formatter = sut.HeaderAndIndentFormatWithMarker(marker='MARKER',
                                                     contents_indent_spaces=3)
     actual = formatter.header_text(1, 1, CROSS_REF_TITLE_ONLY_TEXT_FORMATTER, text('header'))
     self.assertEqual('MARKER header',
                      actual)
Example #23
0
def empty_article(header: str) -> Article:
    return document.empty_article(text(header))
Example #24
0
def empty_section(header: str) -> Section:
    return document.empty_section(text(header))
Example #25
0
def empty_article(header: str) -> Article:
    return document.empty_article(text(header))
Example #26
0
def empty_section(header: str) -> Section:
    return document.empty_section(text(header))
Example #27
0
 def test_header_text(self):
     formatter = sut.HeaderAndIndentFormatPlain(contents_indent_spaces=5)
     actual = formatter.header_text(1, 1,
                                    CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                                    text('header'))
     self.assertEqual('header', actual)