Debian Codegraph @

test/test_parsers/test_rst/test_outdenting.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_outdenting.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['outdenting'] = [
42 ["""\
43 Anywhere a paragraph would have an effect on the current
44 indentation level, a comment or list item should also.
45
46 + bullet
47
48 This paragraph ends the bullet list item before a block quote.
49
50 Block quote.
51 """,
52 """\
53 <document source="test data">
54 <paragraph>
55 Anywhere a paragraph would have an effect on the current
56 indentation level, a comment or list item should also.
57 <bullet_list bullet="+">
58 <list_item>
59 <paragraph>
60 bullet
61 <paragraph>
62 This paragraph ends the bullet list item before a block quote.
63 <block_quote>
64 <paragraph>
65 Block quote.
66 """],
67 ["""\
68 + bullet
69
70 .. Comments swallow up all indented text following.
71
72 (Therefore this is not a) block quote.
73
74 - bullet
75
76 If we want a block quote after this bullet list item,
77 we need to use an empty comment:
78
79 ..
80
81 Block quote.
82 """,
83 """\
84 <document source="test data">
85 <bullet_list bullet="+">
86 <list_item>
87 <paragraph>
88 bullet
89 <comment xml:space="preserve">
90 Comments swallow up all indented text following.
91 \n\
92 (Therefore this is not a) block quote.
93 <bullet_list bullet="-">
94 <list_item>
95 <paragraph>
96 bullet
97 <paragraph>
98 If we want a block quote after this bullet list item,
99 we need to use an empty comment:
100 <comment xml:space="preserve">
101 <block_quote>
102 <paragraph>
103 Block quote.
104 """],
105 ]
106
107 if __name__ == '__main__':
108 unittest.main()