Debian Codegraph @

test/test_parsers/test_recommonmark/test_paragraphs.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_paragraphs.py 9425 2023-06-30 14:56:47Z milde $
4 # Author: David Goodger <[email protected]>
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Tests for states.py.
9 """
10
11 from pathlib import Path
12 import sys
13 import unittest
14
15 if __name__ == '__main__':
16 # prepend the "docutils root" to the Python library path
17 # so we import the local `docutils` package.
18 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
19
20 from docutils.frontend import get_default_settings
21 from docutils.parsers.recommonmark_wrapper import Parser
22 from docutils.utils import new_document
23
24
25 class RecommonmarkParserTestCase(unittest.TestCase):
26 def test_parser(self):
27 parser = Parser()
28 settings = get_default_settings(Parser)
29 for name, cases in totest.items():
30 for casenum, (case_input, case_expected) in enumerate(cases):
31 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
32 document = new_document('test data', settings.copy())
33 parser.parse(case_input, document)
34 output = document.pformat()
35 self.assertEqual(case_expected, output)
36
37
38 totest = {}
39
40 totest['paragraphs'] = [
41 ["""\
42 A paragraph.
43 """,
44 """\
45 <document source="test data">
46 <paragraph>
47 A paragraph.
48 """],
49 ["""\
50 Paragraph 1.
51
52 Paragraph 2.
53 """,
54 """\
55 <document source="test data">
56 <paragraph>
57 Paragraph 1.
58 <paragraph>
59 Paragraph 2.
60 """],
61 ["""\
62 Line 1.
63 Line 2.
64 Line 3.
65 """,
66 """\
67 <document source="test data">
68 <paragraph>
69 Line 1.
70 Line 2.
71 Line 3.
72 """],
73 ["""\
74 Paragraph 1, Line 1.
75 Line 2.
76 Line 3.
77
78 Paragraph 2, Line 1.
79 Line 2.
80 Line 3.
81 """,
82 """\
83 <document source="test data">
84 <paragraph>
85 Paragraph 1, Line 1.
86 Line 2.
87 Line 3.
88 <paragraph>
89 Paragraph 2, Line 1.
90 Line 2.
91 Line 3.
92 """],
93 ]
94
95 if __name__ == '__main__':
96 unittest.main()