示例#1
0
    def test_get_next_paragraph(self):
        # given
        doc_render = DocRender([
            'This is a sample docstring.',
            'and the paragraph continues here',
            '',
            '',
            'This is another sample'])

        # when/then
        self.assertEqual(
            doc_render.get_next_paragraph(),
            ['This is a sample docstring.',
             'and the paragraph continues here'])
        self.assertEqual(
            doc_render.docstring, ['', '', 'This is another sample'])

        # when/then
        self.assertEqual(doc_render.get_next_paragraph(), [])
        self.assertEqual(
            doc_render.docstring, ['', '', 'This is another sample'])

        # when/then
        doc_render.index = 2
        self.assertEqual(
            doc_render.get_next_paragraph(),
            ['This is another sample'])
        self.assertEqual(doc_render.docstring, ['', ''])

        # when/then
        self.assertEqual(
            doc_render.get_next_paragraph(), [])
示例#2
0
    def test_get_next_block(self):
        doc_render = DocRender([
            'term1',
            '    Definition1',
            'term2 : classifier',
            '    Definition2',
            '     ',
            'term3',
            '',
            '',
            'term4 : classifier',
            '    Definition3',
            '',
            '    MoreDefinition3',
            ''])

        self.assertEqual(
            doc_render.get_next_block(),
            ['term1', '    Definition1'])
        self.assertEqual(
            doc_render.get_next_block(),
            ['term2 : classifier', '    Definition2'])
        self.assertEqual(
            doc_render.get_next_block(), ['term3'])
        doc_render.index = 2
        self.assertEqual(
            doc_render.get_next_block(),
            ['term4 : classifier',
             '    Definition3', '', '    MoreDefinition3'])
示例#3
0
    def test_seek_to_next_empty_line(self):
        # given
        doc_render = DocRender([
            'This is a sample docstring.',
            'and the paragraph continues here',
            '',
            '',
            'This is another sample'])

        # when
        doc_render.seek_to_next_non_empty_line()

        # then
        self.assertEqual(doc_render.index, 0)

        # when
        doc_render.index = 2
        doc_render.seek_to_next_non_empty_line()

        # then
        self.assertEqual(doc_render.index, 4)

        # when
        doc_render.seek_to_next_non_empty_line()

        # then
        self.assertEqual(doc_render.index, 4)
示例#4
0
    def test_extract_item_blocks(self):
        # given
        doc_render = DocRender([
            'Section',
            '=======',
            '',
            'Section',
            '=======',
            'term1',
            '    Definition1',
            'term2 : classifier',
            '    Definition2',
            '     ',
            'Section',
            '=======',
            'term4 : classifier',
            '    Definition3',
            '',
            '    MoreDefinition3',
            ''])

        # when/then
        self.assertEqual(doc_render.extract_items(), [])

        # when/then
        doc_render.index = 5
        self.assertEqual(
            doc_render.extract_items(),
            [('term1', [], ['Definition1']),
             ('term2', ['classifier'], ['Definition2'])])

        # when/then
        doc_render.index = 7
        self.assertEqual(
            doc_render.extract_items(),
            [('term4', ['classifier'],
              ['Definition3', '', 'MoreDefinition3'])])
示例#5
0
    def test_is_section(self):
        # given
        doc_render = DocRender([
            "My Header  ",
            "---------     ",
            "MyHeader  ",
            "---------     ",
            "No header",
            "Input\Output header",
            "===================",
            "My Header  ",
            " --------     "])

        # when/then
        doc_render.index = 0
        self.assertTrue(doc_render.is_section())

        # when/then
        doc_render.index = 1
        self.assertFalse(doc_render.is_section())

        # when/then
        doc_render.index = 2
        self.assertFalse(doc_render.is_section())

        # when/then
        doc_render.index = 4
        self.assertFalse(doc_render.is_section())

        # when/then
        doc_render.index = 5
        self.assertTrue(doc_render.is_section())

        # when/then
        doc_render.index = 7
        self.assertFalse(doc_render.is_section())

        # when/then
        doc_render.index = 8
        self.assertFalse(doc_render.is_section())