コード例 #1
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 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)
コード例 #2
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 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)
コード例 #3
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 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)
コード例 #4
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 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)
コード例 #5
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 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)
コード例 #6
0
ファイル: main.py プロジェクト: emilkarlen/exactly
 def test_multiple_cells_with_different_number_of_lines(self):
     # ARRANGE
     row1 = [
         TableCell([single_text_para('row 1/cell 1 para 1'),
                    single_text_para('row 1/cell 1 para 2')]),
         TableCell([single_text_para('row 1/cell 2')]),
     ]
     table = Table(TableFormat('|'),
                   [row1])
     formatter = formatter_with_page_width(100)
     # ACT #
     actual = formatter.format_table(table)
     # ASSERT #
     expected = ['row 1/cell 1 para 1|row 1/cell 2',
                 '                   |            ',
                 'row 1/cell 1 para 2|            ']
     self.assertEqual(expected,
                      actual)
コード例 #7
0
ファイル: lists.py プロジェクト: emilkarlen/exactly
 def test_multi_element_list(self):
     list_format = lf.ListFormat(lf.HeaderAndIndentFormatWithNumbering(contents_indent_spaces=1),
                                 NO_SEPARATIONS,
                                 indent_str='')
     items = [item('h1',
                   [single_text_para('2345678')]),
              item('h2',
                   [single_text_para('content 1'),
                    single_text_para('content 2')])]
     formatter = formatter_with_page_width(10)
     actual = formatter.format_header_value_list_according_to_format(items,
                                                                     list_format)
     self.assertEqual(['1. h1',
                       ' 2345678',
                       '2. h2',
                       ' content 1',
                       BLANK_LINE,
                       ' content 2'],
                      actual)
コード例 #8
0
ファイル: lists.py プロジェクト: emilkarlen/exactly
 def test_item_with_content(self):
     items = [item('header',
                   [single_text_para('content')])]
     formatter = formatter_with_page_width(10)
     actual = formatter.format_header_value_list_according_to_format(items,
                                                                     self.list_format)
     self.assertEqual(['1. header',
                       BLANK_LINE,
                       ' content'],
                      actual)
コード例 #9
0
 def test_singleton_list(self):
     list_format = lf.ListFormat(
         lf.HeaderAndIndentFormatWithNumbering(contents_indent_spaces=1),
         NO_SEPARATIONS,
         indent_str='')
     items = [item('header', [single_text_para('2345678 abc def')])]
     formatter = formatter_with_page_width(10)
     actual = formatter.format_header_value_list_according_to_format(
         items, list_format)
     self.assertEqual(['1. header', ' 2345678', ' abc def'], actual)
コード例 #10
0
 def test_multi_element_list(self):
     list_format = lf.ListFormat(
         lf.HeaderAndIndentFormatWithNumbering(contents_indent_spaces=1),
         NO_SEPARATIONS,
         indent_str='')
     items = [
         item('h1', [single_text_para('2345678')]),
         item(
             'h2',
             [single_text_para('content 1'),
              single_text_para('content 2')])
     ]
     formatter = formatter_with_page_width(10)
     actual = formatter.format_header_value_list_according_to_format(
         items, list_format)
     self.assertEqual([
         '1. h1', ' 2345678', '2. h2', ' content 1', BLANK_LINE,
         ' content 2'
     ], actual)
コード例 #11
0
ファイル: lists.py プロジェクト: emilkarlen/exactly
 def test_with_given_indent(self):
     indent_str = '[INDENT]'
     list_format = lf.ListFormat(lf.HeaderAndIndentFormatPlain(contents_indent_spaces=4),
                                 NO_SEPARATIONS,
                                 indent_str=indent_str)
     items = [item('header',
                   [single_text_para('contents')])]
     formatter = formatter_with_page_width(100)
     actual = formatter.format_header_value_list_according_to_format(items,
                                                                     list_format)
     self.assertEqual([indent_str + 'header',
                       indent_str + (4 * ' ') + 'contents'],
                      actual)
コード例 #12
0
 def test_with_given_indent(self):
     indent_str = '[INDENT]'
     list_format = lf.ListFormat(
         lf.HeaderAndIndentFormatPlain(contents_indent_spaces=4),
         NO_SEPARATIONS,
         indent_str=indent_str)
     items = [item('header', [single_text_para('contents')])]
     formatter = formatter_with_page_width(100)
     actual = formatter.format_header_value_list_according_to_format(
         items, list_format)
     self.assertEqual(
         [indent_str + 'header', indent_str + (4 * ' ') + 'contents'],
         actual)
コード例 #13
0
ファイル: lists.py プロジェクト: emilkarlen/exactly
 def test_singleton_list(self):
     list_format = lf.ListFormat(lf.HeaderAndIndentFormatWithNumbering(contents_indent_spaces=1),
                                 NO_SEPARATIONS,
                                 indent_str='')
     items = [item('header',
                   [single_text_para('2345678 abc def')])]
     formatter = formatter_with_page_width(10)
     actual = formatter.format_header_value_list_according_to_format(items,
                                                                     list_format)
     self.assertEqual(['1. header',
                       ' 2345678',
                       ' abc def'],
                      actual)
コード例 #14
0
    def test_with_content(self):
        list_format = lf.ListFormat(
            lf.HeaderAndIndentFormatWithNumbering(contents_indent_spaces=1),
            NO_SEPARATIONS)
        items = [item('header', [single_text_para('2345678')])]
        formatter = formatter_with_page_width(10)
        current_indent_before = formatter.wrapper.current_indent
        indent_stack_before = formatter.wrapper.saved_indents_stack.copy()
        formatter.format_header_value_list_according_to_format(
            items, list_format)
        self.assertEqual(current_indent_before,
                         formatter.wrapper.current_indent, 'Current indent')

        self.assertEqual(indent_stack_before,
                         formatter.wrapper.saved_indents_stack,
                         'Saved indents stack')
コード例 #15
0
ファイル: lists.py プロジェクト: emilkarlen/exactly
    def test_with_content(self):
        list_format = lf.ListFormat(lf.HeaderAndIndentFormatWithNumbering(contents_indent_spaces=1),
                                    NO_SEPARATIONS)
        items = [item('header',
                      [single_text_para('2345678')])]
        formatter = formatter_with_page_width(10)
        current_indent_before = formatter.wrapper.current_indent
        indent_stack_before = formatter.wrapper.saved_indents_stack.copy()
        formatter.format_header_value_list_according_to_format(items,
                                                               list_format)
        self.assertEqual(current_indent_before,
                         formatter.wrapper.current_indent,
                         'Current indent')

        self.assertEqual(indent_stack_before,
                         formatter.wrapper.saved_indents_stack,
                         'Saved indents stack')
コード例 #16
0
ファイル: lists.py プロジェクト: emilkarlen/exactly
 def test_with_resolved_indent(self):
     format_indent_spaces = 2
     indent_str = format_indent_spaces * ' '
     list_format = lf.ListFormat(lf.HeaderAndIndentFormatPlain(contents_indent_spaces=4),
                                 NO_SEPARATIONS,
                                 indent_str=indent_str)
     items = [item('header',
                   [single_text_para('contents')])]
     the_list = sut.HeaderContentList(items,
                                      lists.Format(lists.ListType.VARIABLE_LIST))
     formatter = sut.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                               sut.Wrapper(page_width=100),
                               list_formats=lf.ListFormats(variable_list_format=list_format))
     actual = formatter.format_header_content_list(the_list)
     self.assertEqual([indent_str + 'header',
                       indent_str + (4 * ' ') + 'contents'],
                      actual)
コード例 #17
0
 def test_with_resolved_indent(self):
     format_indent_spaces = 2
     indent_str = format_indent_spaces * ' '
     list_format = lf.ListFormat(
         lf.HeaderAndIndentFormatPlain(contents_indent_spaces=4),
         NO_SEPARATIONS,
         indent_str=indent_str)
     items = [item('header', [single_text_para('contents')])]
     the_list = sut.HeaderContentList(
         items, lists.Format(lists.ListType.VARIABLE_LIST))
     formatter = sut.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         sut.Wrapper(page_width=100),
         list_formats=lf.ListFormats(variable_list_format=list_format))
     actual = formatter.format_header_content_list(the_list)
     self.assertEqual(
         [indent_str + 'header', indent_str + (4 * ' ') + 'contents'],
         actual)
コード例 #18
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 def test_initial_paragraph_and_single_sub_section(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([single_text_para('initial paragraph')],
                                        [empty_section('Section Header')])
     actual = formatter.format_section_contents(section_contents)
     self.assertEqual(['initial paragraph',
                       BLANK_LINE,
                       BLANK_LINE,
                       BLANK_LINE,
                       'Section Header',
                       ],
                      actual)
コード例 #19
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 def test_only_initial_paragraphs(self):
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=5),
         num_item_separator_lines=1,
         list_formats=lf.ListFormats(variable_list_format=lf.ListFormat(
             lf.HeaderAndIndentFormatPlain(),
             lists.Separations(0, 0),
             indent_str='')))
     formatter = sut.Formatter(paragraph_item_formatter)
     section_contents = SectionContents([
         single_text_para('12345 123 5'),
         lists.HeaderContentList(
             [header_only_item('12345 123')],
             lists.Format(lists.ListType.VARIABLE_LIST),
         )
     ], [])
     actual = formatter.format_section_contents(section_contents)
     self.assertEqual(['12345', '123 5', BLANK_LINE, '12345', '123'],
                      actual)
コード例 #20
0
ファイル: lists.py プロジェクト: emilkarlen/exactly
 def test_with_custom_indent(self):
     custom_indent_spaces = 5
     custom_indent_str = custom_indent_spaces * ' '
     content_indent_spaces = 4
     content_indent_str = content_indent_spaces * ' '
     list_format = lf.ListFormat(lf.HeaderAndIndentFormatPlain(contents_indent_spaces=content_indent_spaces),
                                 NO_SEPARATIONS,
                                 indent_str='should not be used since overridden by custom indent')
     items = [item('header',
                   [single_text_para('contents')])]
     the_list = sut.HeaderContentList(items,
                                      lists.Format(lists.ListType.VARIABLE_LIST,
                                                   custom_indent_spaces=custom_indent_spaces))
     formatter = sut.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                               sut.Wrapper(page_width=100),
                               list_formats=lf.ListFormats(variable_list_format=list_format))
     actual = formatter.format_header_content_list(the_list)
     self.assertEqual([custom_indent_str + 'header',
                       custom_indent_str + content_indent_str + 'contents'],
                      actual)
コード例 #21
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 def test_initial_paragraph_and_single_sub_section(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(
         [single_text_para('initial paragraph')],
         [empty_section('Section Header')])
     actual = formatter.format_section_contents(section_contents)
     self.assertEqual([
         'initial paragraph',
         BLANK_LINE,
         BLANK_LINE,
         BLANK_LINE,
         'Section Header',
     ], actual)
コード例 #22
0
ファイル: section.py プロジェクト: emilkarlen/exactly
 def test_only_initial_paragraphs(self):
     paragraph_item_formatter = paragraph_item.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                                                         paragraph_item.Wrapper(page_width=5),
                                                         num_item_separator_lines=1,
                                                         list_formats=lf.ListFormats(
                                                             variable_list_format=lf.ListFormat(
                                                                 lf.HeaderAndIndentFormatPlain(),
                                                                 lists.Separations(0, 0),
                                                                 indent_str='')))
     formatter = sut.Formatter(paragraph_item_formatter)
     section_contents = SectionContents([single_text_para('12345 123 5'),
                                         lists.HeaderContentList([header_only_item('12345 123')],
                                                                 lists.Format(lists.ListType.VARIABLE_LIST),
                                                                 )],
                                        [])
     actual = formatter.format_section_contents(section_contents)
     self.assertEqual(['12345',
                       '123 5',
                       BLANK_LINE,
                       '12345',
                       '123'],
                      actual)
コード例 #23
0
 def test_with_custom_indent(self):
     custom_indent_spaces = 5
     custom_indent_str = custom_indent_spaces * ' '
     content_indent_spaces = 4
     content_indent_str = content_indent_spaces * ' '
     list_format = lf.ListFormat(
         lf.HeaderAndIndentFormatPlain(
             contents_indent_spaces=content_indent_spaces),
         NO_SEPARATIONS,
         indent_str='should not be used since overridden by custom indent')
     items = [item('header', [single_text_para('contents')])]
     the_list = sut.HeaderContentList(
         items,
         lists.Format(lists.ListType.VARIABLE_LIST,
                      custom_indent_spaces=custom_indent_spaces))
     formatter = sut.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         sut.Wrapper(page_width=100),
         list_formats=lf.ListFormats(variable_list_format=list_format))
     actual = formatter.format_header_content_list(the_list)
     self.assertEqual([
         custom_indent_str + 'header',
         custom_indent_str + content_indent_str + 'contents'
     ], actual)
コード例 #24
0
 def test_item_with_content(self):
     items = [item('header', [single_text_para('content')])]
     formatter = formatter_with_page_width(10)
     actual = formatter.format_header_value_list_according_to_format(
         items, self.list_format)
     self.assertEqual(['1. header', BLANK_LINE, ' content'], actual)
コード例 #25
0
ファイル: section.py プロジェクト: emilkarlen/exactly
def single_para_contents(paragraph_text: str) -> SectionContents:
    return SectionContents([single_text_para(paragraph_text)],
                           [])
コード例 #26
0
ファイル: section.py プロジェクト: emilkarlen/exactly
def single_para_contents(paragraph_text: str) -> SectionContents:
    return SectionContents([single_text_para(paragraph_text)], [])
コード例 #27
0
ファイル: main.py プロジェクト: emilkarlen/exactly
def _text_cell(text_as_string: str) -> TableCell:
    return single_paragraph_cell(single_text_para(text_as_string))