Debian Codegraph @

test/test_parsers/test_rst/test_doctest_blocks.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_doctest_blocks.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['doctest_blocks'] = [
42 ["""\
43 Paragraph.
44
45 >>> print("Doctest block.")
46 Doctest block.
47
48 Paragraph.
49 """,
50 """\
51 <document source="test data">
52 <paragraph>
53 Paragraph.
54 <doctest_block xml:space="preserve">
55 >>> print("Doctest block.")
56 Doctest block.
57 <paragraph>
58 Paragraph.
59 """],
60 ["""\
61 Paragraph.
62
63 >>> print(" Indented output.")
64 Indented output.
65 """,
66 """\
67 <document source="test data">
68 <paragraph>
69 Paragraph.
70 <doctest_block xml:space="preserve">
71 >>> print(" Indented output.")
72 Indented output.
73 """],
74 ["""\
75 Paragraph.
76
77 >>> print(" Indented block & output.")
78 Indented block & output.
79 """,
80 """\
81 <document source="test data">
82 <paragraph>
83 Paragraph.
84 <block_quote>
85 <doctest_block xml:space="preserve">
86 >>> print(" Indented block & output.")
87 Indented block & output.
88 """],
89 ]
90
91 if __name__ == '__main__':
92 unittest.main()