Debian Codegraph @

test/test_parsers/test_rst/test_bullet_lists.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_bullet_lists.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.rst import Parser
22 from docutils.utils import new_document
23
24
25 class ParserTestCase(unittest.TestCase):
26 def test_parser(self):
27 parser = Parser()
28 settings = get_default_settings(Parser)
29 settings.warning_stream = ''
30 for name, cases in totest.items():
31 for casenum, (case_input, case_expected) in enumerate(cases):
32 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
33 document = new_document('test data', settings.copy())
34 parser.parse(case_input, document)
35 output = document.pformat()
36 self.assertEqual(case_expected, output)
37
38
39 totest = {}
40
41 totest['bullet_lists'] = [
42 ["""\
43 - item
44 """,
45 """\
46 <document source="test data">
47 <bullet_list bullet="-">
48 <list_item>
49 <paragraph>
50 item
51 """],
52 ["""\
53 * item 1
54
55 * item 2
56 """,
57 """\
58 <document source="test data">
59 <bullet_list bullet="*">
60 <list_item>
61 <paragraph>
62 item 1
63 <list_item>
64 <paragraph>
65 item 2
66 """],
67 ["""\
68 No blank line between:
69
70 + item 1
71 + item 2
72 """,
73 """\
74 <document source="test data">
75 <paragraph>
76 No blank line between:
77 <bullet_list bullet="+">
78 <list_item>
79 <paragraph>
80 item 1
81 <list_item>
82 <paragraph>
83 item 2
84 """],
85 ["""\
86 - item 1, para 1.
87
88 item 1, para 2.
89
90 - item 2
91 """,
92 """\
93 <document source="test data">
94 <bullet_list bullet="-">
95 <list_item>
96 <paragraph>
97 item 1, para 1.
98 <paragraph>
99 item 1, para 2.
100 <list_item>
101 <paragraph>
102 item 2
103 """],
104 ["""\
105 - item 1, line 1
106 item 1, line 2
107 - item 2
108 """,
109 """\
110 <document source="test data">
111 <bullet_list bullet="-">
112 <list_item>
113 <paragraph>
114 item 1, line 1
115 item 1, line 2
116 <list_item>
117 <paragraph>
118 item 2
119 """],
120 ["""\
121 Different bullets:
122
123 - item 1
124
125 + item 1
126
127 * item 1
128 - item 1
129 """,
130 """\
131 <document source="test data">
132 <paragraph>
133 Different bullets:
134 <bullet_list bullet="-">
135 <list_item>
136 <paragraph>
137 item 1
138 <bullet_list bullet="+">
139 <list_item>
140 <paragraph>
141 item 1
142 <bullet_list bullet="*">
143 <list_item>
144 <paragraph>
145 item 1
146 <system_message level="2" line="8" source="test data" type="WARNING">
147 <paragraph>
148 Bullet list ends without a blank line; unexpected unindent.
149 <bullet_list bullet="-">
150 <list_item>
151 <paragraph>
152 item 1
153 """],
154 ["""\
155 - item
156 no blank line
157 """,
158 """\
159 <document source="test data">
160 <bullet_list bullet="-">
161 <list_item>
162 <paragraph>
163 item
164 <system_message level="2" line="2" source="test data" type="WARNING">
165 <paragraph>
166 Bullet list ends without a blank line; unexpected unindent.
167 <paragraph>
168 no blank line
169 """],
170 ["""\
171 -
172
173 empty item above
174 """,
175 """\
176 <document source="test data">
177 <bullet_list bullet="-">
178 <list_item>
179 <paragraph>
180 empty item above
181 """],
182 ["""\
183 -
184 empty item above, no blank line
185 """,
186 """\
187 <document source="test data">
188 <bullet_list bullet="-">
189 <list_item>
190 <system_message level="2" line="2" source="test data" type="WARNING">
191 <paragraph>
192 Bullet list ends without a blank line; unexpected unindent.
193 <paragraph>
194 empty item above, no blank line
195 """],
196 ["""\
197 Unicode bullets:
198
199 \u2022 BULLET
200
201 \u2023 TRIANGULAR BULLET
202
203 \u2043 HYPHEN BULLET
204 """,
205 """\
206 <document source="test data">
207 <paragraph>
208 Unicode bullets:
209 <bullet_list bullet="\u2022">
210 <list_item>
211 <paragraph>
212 BULLET
213 <bullet_list bullet="\u2023">
214 <list_item>
215 <paragraph>
216 TRIANGULAR BULLET
217 <bullet_list bullet="\u2043">
218 <list_item>
219 <paragraph>
220 HYPHEN BULLET
221 """],
222 ]
223
224 if __name__ == '__main__':
225 unittest.main()