Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_compound.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_compound.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 the 'compound' directive from body.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[4]))
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['compound'] = [
42 ["""\
43 .. compound::
44
45 Compound paragraphs are single logical paragraphs
46 which contain embedded
47
48 * lists
49 * tables
50 * literal blocks
51 * and other body elements
52
53 and are split into multiple physical paragraphs.
54 """,
55 """\
56 <document source="test data">
57 <compound>
58 <paragraph>
59 Compound paragraphs are single logical paragraphs
60 which contain embedded
61 <bullet_list bullet="*">
62 <list_item>
63 <paragraph>
64 lists
65 <list_item>
66 <paragraph>
67 tables
68 <list_item>
69 <paragraph>
70 literal blocks
71 <list_item>
72 <paragraph>
73 and other body elements
74 <paragraph>
75 and are split into multiple physical paragraphs.
76 """],
77 ["""\
78 .. compound::
79 :name: interesting
80 :class: log
81
82 This is an extremely interesting compound paragraph containing a
83 simple paragraph, a literal block with some useless log messages::
84
85 Connecting... OK
86 Transmitting data... OK
87 Disconnecting... OK
88
89 and another simple paragraph which is actually just a continuation
90 of the first simple paragraph, with the literal block in between.
91 """,
92 """\
93 <document source="test data">
94 <compound classes="log" ids="interesting" names="interesting">
95 <paragraph>
96 This is an extremely interesting compound paragraph containing a
97 simple paragraph, a literal block with some useless log messages:
98 <literal_block xml:space="preserve">
99 Connecting... OK
100 Transmitting data... OK
101 Disconnecting... OK
102 <paragraph>
103 and another simple paragraph which is actually just a continuation
104 of the first simple paragraph, with the literal block in between.
105 """],
106 ["""\
107 .. compound:: content may start on same line
108
109 second paragraph
110 """,
111 """\
112 <document source="test data">
113 <compound>
114 <paragraph>
115 content may start on same line
116 <paragraph>
117 second paragraph
118 """],
119 ]
120
121
122 if __name__ == '__main__':
123 unittest.main()