コード例 #1
0
 def test_list_with_item_multiple_paragraphs_contents_before_other_item(self):
     expected = [
         lists.HeaderContentList([
             _list_item('item 1',
                        [
                            Paragraph([StringText('item 1 contents paragraph 1')]),
                            Paragraph([StringText('item 1 contents paragraph 2')]),
                        ]),
             _list_item('item 2',
                        [
                            Paragraph([StringText('item 2 contents paragraph 1')]),
                        ]),
         ],
             self.EXPECTED_LIST_FORMAT),
         Paragraph([StringText('last paragraph')]),
     ]
     actual = sut.parse(['  * item 1',
                         '',
                         '    item 1 contents paragraph 1',
                         '',
                         '',
                         '    item 1 contents paragraph 2',
                         '',
                         '  * item 2',
                         '',
                         '    item 2 contents paragraph 1',
                         '',
                         'last paragraph'])
     check(self, expected, actual)
コード例 #2
0
 def test_single_line_text_blocks(self):
     check(self,
           [Paragraph([StringText('text in para 1')]),
            Paragraph([StringText('text in para 2')])],
           sut.parse(['text in para 1'] +
                     sut.PARAGRAPH_SEPARATOR_LINES +
                     ['text in para 2']))
コード例 #3
0
 def test_list_with_item_multiple_paragraphs_contents_in_middle_of_paragraphs(self):
     expected = [
         Paragraph([StringText('first paragraph')]),
         lists.HeaderContentList([
             _list_item('item 1',
                        [
                            Paragraph([StringText('line 1 in contents paragraph 1'),
                                       StringText('line 2 in contents paragraph 1')]),
                            Paragraph([StringText('line 1 in contents paragraph 2')]),
                        ]),
         ],
             self.EXPECTED_LIST_FORMAT),
         Paragraph([StringText('last paragraph')]),
     ]
     actual = sut.parse(['first paragraph',
                         '',
                         '',
                         '  * item 1',
                         '',
                         '    line 1 in contents paragraph 1',
                         '',
                         '    line 2 in contents paragraph 1',
                         '',
                         '',
                         '    line 1 in contents paragraph 2',
                         '',
                         '',
                         'last paragraph'])
     check(self, expected, actual)
コード例 #4
0
 def test_larger_paragraph_separator(self):
     check(self,
           [Paragraph([StringText('text in para 1')]),
            Paragraph([StringText('text in para 2')])],
           sut.parse(['text in para 1'] +
                     sut.PARAGRAPH_SEPARATOR_LINES +
                     sut.PARAGRAPH_SEPARATOR_LINES +
                     ['text in para 2']))
コード例 #5
0
 def test_multiple_text_blocks(self):
     check(self,
           [Paragraph([StringText('text 1 in para 1'),
                       StringText('text 2 in para 1')]),
            Paragraph([StringText('text 1 in para 2'),
                       StringText('text 2 in para 2')])],
           sut.parse(['text 1 in para 1'] +
                     sut.TEXT_SEPARATOR_LINES +
                     ['text 2 in para 1'] +
                     sut.PARAGRAPH_SEPARATOR_LINES +
                     ['text 1 in para 2'] +
                     sut.TEXT_SEPARATOR_LINES +
                     ['text 2 in para 2']))
コード例 #6
0
 def test_literal_block_between_paragraph_blocks(self):
     check(self,
           [
               Paragraph([StringText('para 1')]),
               sut.LiteralLayout(lines_content(['literal line'])),
               Paragraph([StringText('para 2')]),
           ],
           sut.parse(['para 1'] +
                     sut.PARAGRAPH_SEPARATOR_LINES +
                     ['```',
                      'literal line',
                      '```'] +
                     sut.PARAGRAPH_SEPARATOR_LINES +
                     ['para 2']))
コード例 #7
0
    def test(self):
        # ARRANGE #
        const_pi = Paragraph([])
        cases = [
            NEA('empty sequence of paragraphs',
                expected=asrt.matches_sequence([]),
                actual=[]
                ),
            NEA('single paragraph',
                expected=asrt.matches_sequence([
                    asrt.is__any(const_pi)
                ]),
                actual=[const_pi]
                ),
        ]

        for case in cases:
            with self.subTest(case.name):
                # ACT #

                actual = sut.constant(case.actual).apply(CONSTRUCTION_ENVIRONMENT)

                # ASSERT #

                case.expected.apply_without_message(self, actual)
コード例 #8
0
ファイル: parse.py プロジェクト: emilkarlen/exactly
 def parse_paragraph(self) -> Paragraph:
     texts = []
     while self.has_more_lines() and not self.is_at_paragraph_separator():
         self.consume_separator_lines()
         texts.append(self.parse_text())
     self.consume_separator_lines()
     return Paragraph(texts)
コード例 #9
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #10
0
 def test_single_line_text_blocks(self):
     check(self,
           [Paragraph([StringText('text 1'),
                       StringText('text 2')])],
           sut.parse(['text 1'] +
                     sut.TEXT_SEPARATOR_LINES +
                     ['text 2']))
コード例 #11
0
 def test_single_text_block_on_multiple_lines(self):
     input_lines = ['the',
                    'text',
                    'block'
                    ]
     check(self,
           [Paragraph([StringText(' '.join(input_lines))])],
           sut.parse(input_lines))
コード例 #12
0
 def test_list_in_middle_of_paragraphs(self):
     expected = [
         Paragraph([StringText('first paragraph')]),
         lists.HeaderContentList([_list_item('item 1'),
                                  _list_item('item 2')],
                                 self.EXPECTED_LIST_FORMAT),
         Paragraph([StringText('last paragraph')]),
     ]
     actual = sut.parse(['first paragraph',
                         '',
                         '',
                         '  * item 1',
                         '  * item 2',
                         '',
                         '',
                         'last paragraph'])
     check(self, expected, actual)
コード例 #13
0
def transform_list_to_table(l: lists.HeaderContentList) -> table.Table:
    rows = []
    for item in l.items:
        assert isinstance(item, lists.HeaderContentListItem)
        header_cell = cell([Paragraph([item.header])])
        value_cell = cell(item.content_paragraph_items)
        rows.append([header_cell, value_cell])
    return table.Table(table.TableFormat(),
                       rows)
コード例 #14
0
 def test_visit_paragraph(self):
     # ARRANGE #
     item = Paragraph([StringText('string text')])
     visitor = AVisitorThatRecordsVisitedMethods()
     # ACT #
     ret_val = visitor.visit(item)
     # ASSERT #
     self.assertEqual([Paragraph], visitor.visited_types)
     self.assertIs(item, ret_val)
コード例 #15
0
    def test_single_list_with_with_contents(self):
        expected = [lists.HeaderContentList([
            _list_item('item 1',
                       [
                           Paragraph([StringText('contents 1')]),
                       ]),
            _list_item('item 2',
                       [
                           Paragraph([StringText('contents 2')]),
                       ]),
        ],
            self.EXPECTED_LIST_FORMAT)]
        actual = sut.parse(['  * item 1',

                            '    contents 1',
                            '  * item 2',
                            '    contents 2',
                            ])
        check(self, expected, actual)
コード例 #16
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #17
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #18
0
 def test_multi_line_text_blocks(self):
     input_lines = ['text',
                    '1'] + \
                   sut.TEXT_SEPARATOR_LINES + \
                   ['text',
                    '2']
     check(self,
           [Paragraph([StringText('text 1'),
                       StringText('text 2')])],
           sut.parse(input_lines))
コード例 #19
0
 def test_single_list_with_single_item_with_contents_on_next_line(self):
     expected = [lists.HeaderContentList([
         _list_item('item',
                    [
                        Paragraph([StringText('contents')]),
                    ])],
         self.EXPECTED_LIST_FORMAT)]
     actual = sut.parse(['  1. item',
                         '     contents',
                         ])
     check(self, expected, actual)
コード例 #20
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #21
0
 def test_misc(self):
     lines = ['',
              '   ',
              'para 1 text 1',
              '  ',
              '',
              '   ',
              '  para 2 text 1',
              '  ',
              'para 2 text 2  ',
              '  ',
              '\tpara 2 text 3  ',
              '',
              '   ']
     indented_lines = ['  ' + line for line in lines]
     actual = sut.normalize_and_parse(lines_content(indented_lines))
     check(self,
           [Paragraph([StringText('para 1 text 1')]),
            Paragraph([StringText('para 2 text 1'),
                       StringText('para 2 text 2'),
                       StringText('para 2 text 3')])],
           actual)
コード例 #22
0
    def test(self):
        # ARRANGE #
        const_pi_1 = Paragraph([])
        const_pi_2 = Paragraph([StringText('const pi 2')])
        const_pi_3 = Paragraph([StringText('const pi 3')])
        cases = [
            NEA('empty sequence of paragraphs',
                expected=asrt.matches_sequence([]),
                actual=[]
                ),
            NEA('single constructor',
                expected=asrt.matches_sequence([
                    asrt.is__any(const_pi_1)
                ]),
                actual=[sut.constant([const_pi_1])]
                ),
            NEA('multiple constructors',
                expected=asrt.matches_sequence([
                    asrt.is__any(const_pi_1),
                    asrt.is__any(const_pi_2),
                    asrt.is__any(const_pi_3),
                ]),
                actual=[sut.constant([const_pi_1,
                                      const_pi_2]),
                        sut.constant([const_pi_3])]
                ),
        ]

        for case in cases:
            with self.subTest(case.name):
                # ACT #

                actual = sut.sequence(case.actual).apply(CONSTRUCTION_ENVIRONMENT)

                # ASSERT #

                case.expected.apply_without_message(self, actual)
コード例 #23
0
 def test_nested_lists(self):
     expected = [
         lists.HeaderContentList([
             _list_item('itemized item 1',
                        [
                            Paragraph([StringText('item 1 contents paragraph')]),
                            lists.HeaderContentList(
                                [
                                    _list_item('ordered item 1/1',
                                               [
                                                   Paragraph([StringText('item 1/1 contents paragraph')]),
                                               ]),
                                    _list_item('ordered item 1/2',
                                               []),
                                ],
                                self.EXPECTED_ORDERED_LIST_FORMAT),
                        ]),
             _list_item('itemized item 2',
                        []),
         ],
             self.EXPECTED_ITEMIZED_LIST_FORMAT),
     ]
     actual = sut.parse(['  * itemized item 1',
                         '',
                         '    item 1 contents paragraph',
                         '',
                         '',
                         '      1. ordered item 1/1',
                         '',
                         '         item 1/1 contents paragraph',
                         '',
                         '      1. ordered item 1/2',
                         '',
                         '  * itemized item 2',
                         ])
     check(self, expected, actual)
コード例 #24
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #25
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #26
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #27
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #28
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #29
0
ファイル: paragraph.py プロジェクト: emilkarlen/exactly
 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)
コード例 #30
0
def para(str_or_text: StrOrText) -> ParagraphItem:
    return Paragraph([text_from_unknown(str_or_text)])