1 #! /usr/bin/env python3
4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
11 from pathlib
import Path
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]))
20 from docutils
.frontend
import get_default_settings
21 from docutils
.parsers
.rst
import Parser
22 from docutils
.utils
import new_document
25 class ParserTestCase(unittest
.TestCase
):
29 def test_parser(self
):
31 settings
= get_default_settings(Parser
)
32 settings
.warning_stream
= ''
33 for name
, cases
in totest
.items():
34 for casenum
, (case_input
, case_expected
) in enumerate(cases
):
35 with self
.subTest(id=f
'totest[{name!r}][{casenum}]'):
36 document
= new_document('test data', settings
.copy())
37 parser
.parse(case_input
, document
)
38 output
= document
.pformat()
39 self
.assertEqual(case_expected
, output
)
44 totest
['definition_lists'] = [
50 <document source="test data">
52 <definition_list_item>
66 <document source="test data">
68 <definition_list_item>
83 <document source="test data">
85 <definition_list_item>
91 <system_message level="2" line="3" source="test data" type="WARNING">
93 Definition list ends without a blank line; unexpected unindent.
99 A literal block without a blank line first?
102 <document source="test data">
104 <definition_list_item>
108 <system_message level="1" line="2" source="test data" type="INFO">
110 Blank line missing before literal block (after the "::")? Interpreted as a definition list item.
112 A literal block without a blank line first?
116 a term may only be one line long
117 this is not a definition
120 <document source="test data">
123 a term may only be one line long
124 <system_message level="3" line="3" source="test data" type="ERROR">
126 Unexpected indentation.
129 this is not a definition
139 <document source="test data">
141 <definition_list_item>
147 <definition_list_item>
156 definition 1 (no blank line below)
161 <document source="test data">
163 <definition_list_item>
168 definition 1 (no blank line below)
169 <definition_list_item>
178 definition 1 (no blank line below)
181 No blank line after the definition list.
184 <document source="test data">
186 <definition_list_item>
191 definition 1 (no blank line below)
192 <definition_list_item>
198 <system_message level="2" line="5" source="test data" type="WARNING">
200 Definition list ends without a blank line; unexpected unindent.
202 No blank line after the definition list.
220 <document source="test data">
222 <definition_list_item>
229 <definition_list_item>
235 <definition_list_item>
241 <definition_list_item>
252 The ' : ' indicates a classifier in
253 definition list item terms only.
256 <document source="test data">
258 <definition_list_item>
265 The ' : ' indicates a classifier in
266 definition list item terms only.
269 Term: not a classifier
270 Because there's no space before the colon.
271 Term :not a classifier
272 Because there's no space after the colon.
273 Term \\: not a classifier
274 Because the colon is escaped.
277 <document source="test data">
279 <definition_list_item>
281 Term: not a classifier
284 Because there's no space before the colon.
285 <definition_list_item>
287 Term :not a classifier
290 Because there's no space after the colon.
291 <definition_list_item>
293 Term : not a classifier
296 Because the colon is escaped.
299 ``Term : not a classifier``
300 Because the ' : ' is inside an inline literal.
303 <document source="test data">
305 <definition_list_item>
308 Term : not a classifier
311 Because the ' : ' is inside an inline literal.
314 Term `with *inline ``text **errors : classifier `with *errors ``too
315 Definition `with *inline ``text **markup errors.
318 <document source="test data">
320 <definition_list_item>
323 <problematic ids="problematic-1" refid="system-message-1">
326 <problematic ids="problematic-2" refid="system-message-2">
329 <problematic ids="problematic-3" refid="system-message-3">
332 <problematic ids="problematic-4" refid="system-message-4">
337 <problematic ids="problematic-5" refid="system-message-5">
340 <problematic ids="problematic-6" refid="system-message-6">
343 <problematic ids="problematic-7" refid="system-message-7">
347 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="1" source="test data" type="WARNING">
349 Inline interpreted text or phrase reference start-string without end-string.
350 <system_message backrefs="problematic-2" ids="system-message-2" level="2" line="1" source="test data" type="WARNING">
352 Inline emphasis start-string without end-string.
353 <system_message backrefs="problematic-3" ids="system-message-3" level="2" line="1" source="test data" type="WARNING">
355 Inline literal start-string without end-string.
356 <system_message backrefs="problematic-4" ids="system-message-4" level="2" line="1" source="test data" type="WARNING">
358 Inline strong start-string without end-string.
359 <system_message backrefs="problematic-5" ids="system-message-5" level="2" line="1" source="test data" type="WARNING">
361 Inline interpreted text or phrase reference start-string without end-string.
362 <system_message backrefs="problematic-6" ids="system-message-6" level="2" line="1" source="test data" type="WARNING">
364 Inline emphasis start-string without end-string.
365 <system_message backrefs="problematic-7" ids="system-message-7" level="2" line="1" source="test data" type="WARNING">
367 Inline literal start-string without end-string.
370 <problematic ids="problematic-8" refid="system-message-8">
373 <problematic ids="problematic-9" refid="system-message-9">
376 <problematic ids="problematic-10" refid="system-message-10">
379 <problematic ids="problematic-11" refid="system-message-11">
382 <system_message backrefs="problematic-8" ids="system-message-8" level="2" line="2" source="test data" type="WARNING">
384 Inline interpreted text or phrase reference start-string without end-string.
385 <system_message backrefs="problematic-9" ids="system-message-9" level="2" line="2" source="test data" type="WARNING">
387 Inline emphasis start-string without end-string.
388 <system_message backrefs="problematic-10" ids="system-message-10" level="2" line="2" source="test data" type="WARNING">
390 Inline literal start-string without end-string.
391 <system_message backrefs="problematic-11" ids="system-message-11" level="2" line="2" source="test data" type="WARNING">
393 Inline strong start-string without end-string.
397 classifier starting with a reference crashes from release 8197 to ...
400 <document source="test data">
402 <definition_list_item>
406 <reference name="reference" refname="reference">
410 classifier starting with a reference crashes from release 8197 to ...
413 Term : a `reference`_ in text : second
414 classifier with reference crashes from release 8197 to ...
417 <document source="test data">
419 <definition_list_item>
424 <reference name="reference" refname="reference">
431 classifier with reference crashes from release 8197 to ...
434 Term : classifier one : classifier two
438 <document source="test data">
440 <definition_list_item>
453 if __name__
== '__main__':