Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_admonitions_de.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_admonitions_de.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 admonitions.py directives in German document.
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, directives, roles
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 settings.language_code = 'de'
31 for name, cases in totest.items():
32 for casenum, (case_input, case_expected) in enumerate(cases):
33 # Language-specific roles and roles added by the
34 # "default-role" and "role" directives are currently stored
35 # globally in the roles._roles dictionary.
36 # Language-specific directives are currently stored
37 # globally in the directives._directives dictionary.
38 # This workaround empties these dictionaries.
39 directives._directives = {}
40 roles._roles = {}
41 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
42 document = new_document('test data', settings.copy())
43 parser.parse(case_input, document)
44 output = document.pformat()
45 self.assertEqual(case_expected, output)
46
47
48 totest = {}
49
50 totest['admonitions'] = [
51 ["""\
52 .. Achtung:: Directives at large.
53
54 .. Notiz:: :name: mynote
55 :class: testnote
56
57 Admonitions support the generic "name" and "class" options.
58
59 .. Tipp:: 15% if the
60 service is good.
61
62 .. Hinweis:: It's bigger than a bread box.
63
64 - .. WARNUNG:: Strong prose may provoke extreme mental exertion.
65 Reader discretion is strongly advised.
66 - .. Fehler:: Does not compute.
67
68 .. Vorsicht::
69
70 Don't take any wooden nickels.
71
72 .. GEFAHR:: Mad scientist at work!
73
74 .. Wichtig::
75 - Wash behind your ears.
76 - Clean up your room.
77 - Call your mother.
78 - Back up your data.
79 """,
80 """\
81 <document source="test data">
82 <attention>
83 <paragraph>
84 Directives at large.
85 <note classes="testnote" ids="mynote" names="mynote">
86 <paragraph>
87 Admonitions support the generic "name" and "class" options.
88 <tip>
89 <paragraph>
90 15% if the
91 service is good.
92 <hint>
93 <paragraph>
94 It's bigger than a bread box.
95 <bullet_list bullet="-">
96 <list_item>
97 <warning>
98 <paragraph>
99 Strong prose may provoke extreme mental exertion.
100 Reader discretion is strongly advised.
101 <list_item>
102 <error>
103 <paragraph>
104 Does not compute.
105 <caution>
106 <paragraph>
107 Don't take any wooden nickels.
108 <danger>
109 <paragraph>
110 Mad scientist at work!
111 <important>
112 <bullet_list bullet="-">
113 <list_item>
114 <paragraph>
115 Wash behind your ears.
116 <list_item>
117 <paragraph>
118 Clean up your room.
119 <list_item>
120 <paragraph>
121 Call your mother.
122 <list_item>
123 <paragraph>
124 Back up your data.
125 """],
126 ["""\
127 .. Notiz:: One-line notes.
128 .. Notiz:: One after the other.
129 .. Notiz:: No blank lines in-between.
130 """,
131 """\
132 <document source="test data">
133 <note>
134 <paragraph>
135 One-line notes.
136 <note>
137 <paragraph>
138 One after the other.
139 <note>
140 <paragraph>
141 No blank lines in-between.
142 """],
143 ["""\
144 .. Notiz:: Content before options
145 is possible too.
146 :class: mynote
147
148 .. Notiz:: :strong:`a role is not an option`.
149 :name: role not option
150
151 .. Notiz:: a role is
152 :strong:`not an option`, even if its starts a line.
153 """,
154 """\
155 <document source="test data">
156 <note classes="mynote">
157 <paragraph>
158 Content before options
159 is possible too.
160 <note ids="role-not-option" names="role\\ not\\ option">
161 <paragraph>
162 <strong>
163 a role is not an option
164 .
165 <system_message level="1" line="5" source="test data" type="INFO">
166 <paragraph>
167 No role entry for "strong" in module "docutils.parsers.rst.languages.de".
168 Using English fallback for role "strong".
169 <note>
170 <paragraph>
171 a role is
172 <strong>
173 not an option
174 , even if its starts a line.
175 """],
176 ["""\
177 .. Notiz::
178 """,
179 """\
180 <document source="test data">
181 <system_message level="3" line="1" source="test data" type="ERROR">
182 <paragraph>
183 Content block expected for the "Notiz" directive; none found.
184 <literal_block xml:space="preserve">
185 .. Notiz::
186 """],
187 ["""\
188 .. admonition:: Admonition
189
190 This is a generic admonition.
191 """,
192 """\
193 <document source="test data">
194 <system_message level="1" line="1" source="test data" type="INFO">
195 <paragraph>
196 No directive entry for "admonition" in module "docutils.parsers.rst.languages.de".
197 Using English fallback for directive "admonition".
198 <admonition classes="admonition-admonition">
199 <title>
200 Admonition
201 <paragraph>
202 This is a generic admonition.
203 """],
204 ["""\
205 .. admonition:: And, by the way...
206
207 You can make up your own admonition too.
208 """,
209 """\
210 <document source="test data">
211 <system_message level="1" line="1" source="test data" type="INFO">
212 <paragraph>
213 No directive entry for "admonition" in module "docutils.parsers.rst.languages.de".
214 Using English fallback for directive "admonition".
215 <admonition classes="admonition-and-by-the-way">
216 <title>
217 And, by the way...
218 <paragraph>
219 You can make up your own admonition too.
220 """],
221 ["""\
222 .. admonition:: Admonition
223 :class: emergency
224 :name: reference name
225
226 Test the "class" override.
227 """,
228 """\
229 <document source="test data">
230 <system_message level="1" line="1" source="test data" type="INFO">
231 <paragraph>
232 No directive entry for "admonition" in module "docutils.parsers.rst.languages.de".
233 Using English fallback for directive "admonition".
234 <admonition classes="emergency" ids="reference-name" names="reference\\ name">
235 <title>
236 Admonition
237 <paragraph>
238 Test the "class" override.
239 """],
240 ["""\
241 .. admonition::
242
243 Generic admonitions require a title.
244 """,
245 """\
246 <document source="test data">
247 <system_message level="1" line="1" source="test data" type="INFO">
248 <paragraph>
249 No directive entry for "admonition" in module "docutils.parsers.rst.languages.de".
250 Using English fallback for directive "admonition".
251 <system_message level="3" line="1" source="test data" type="ERROR">
252 <paragraph>
253 Error in "admonition" directive:
254 1 argument(s) required, 0 supplied.
255 <literal_block xml:space="preserve">
256 .. admonition::
257 \n\
258 Generic admonitions require a title.
259 """],
260 ]
261
262
263 if __name__ == '__main__':
264 unittest.main()