Allow also non-ASCII whitespace characters around inline markup.
[docutils.git] / test / test_transforms / test_transitions.py
blob23605206aa5f4612c55a1fe5a555146a7e21f179
1 #! /usr/bin/env python
3 # $Id$
4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Test module for misc.Transitions transform.
9 """
11 from __init__ import DocutilsTestSupport # must be imported before docutils
12 from docutils.transforms.misc import Transitions
13 from docutils.parsers.rst import Parser
15 def suite():
16 parser = Parser()
17 s = DocutilsTestSupport.TransformTestSuite(parser)
18 s.generateTests(totest)
19 return s
22 totest = {}
24 totest['transitions'] = ((Transitions,), [
25 ["""\
26 Section 1
27 =========
29 Subsection 1
30 ------------
32 Some text.
34 ----------
36 Section 2
37 =========
39 Some text.
40 """,
41 """\
42 <document source="test data">
43 <section ids="section-1" names="section\ 1">
44 <title>
45 Section 1
46 <section ids="subsection-1" names="subsection\ 1">
47 <title>
48 Subsection 1
49 <paragraph>
50 Some text.
51 <transition>
52 <section ids="section-2" names="section\ 2">
53 <title>
54 Section 2
55 <paragraph>
56 Some text.
57 """],
58 ["""\
59 A paragraph.
61 ----------
63 Section 1
64 =========
66 Paragraph.
67 """,
68 """\
69 <document source="test data">
70 <paragraph>
71 A paragraph.
72 <transition>
73 <section ids="section-1" names="section\ 1">
74 <title>
75 Section 1
76 <paragraph>
77 Paragraph.
78 """],
79 ["""\
80 --------
82 A section or document may not begin with a transition.
84 The DTD specifies that two transitions may not
85 be adjacent:
87 --------
89 --------
91 --------
93 The DTD also specifies that a section or document
94 may not end with a transition.
96 --------
97 """,
98 """\
99 <document source="test data">
100 <system_message level="3" line="1" source="test data" type="ERROR">
101 <paragraph>
102 Document or section may not begin with a transition.
103 <transition>
104 <paragraph>
105 A section or document may not begin with a transition.
106 <paragraph>
107 The DTD specifies that two transitions may not
108 be adjacent:
109 <transition>
110 <system_message level="3" line="10" source="test data" type="ERROR">
111 <paragraph>
112 At least one body element must separate transitions; adjacent transitions are not allowed.
113 <transition>
114 <system_message level="3" line="12" source="test data" type="ERROR">
115 <paragraph>
116 At least one body element must separate transitions; adjacent transitions are not allowed.
117 <transition>
118 <paragraph>
119 The DTD also specifies that a section or document
120 may not end with a transition.
121 <transition>
122 <system_message level="3" line="17" source="test data" type="ERROR">
123 <paragraph>
124 Document may not end with a transition.
125 """],
126 ["""\
127 Sections with transitions at beginning and end.
129 Section 1
130 =========
132 ----------
134 The next transition is legal:
136 ----------
138 Section 2
139 =========
141 ----------
142 """,
143 """\
144 <document source="test data">
145 <paragraph>
146 Sections with transitions at beginning and end.
147 <section ids="section-1" names="section\ 1">
148 <title>
149 Section 1
150 <system_message level="3" line="6" source="test data" type="ERROR">
151 <paragraph>
152 Document or section may not begin with a transition.
153 <transition>
154 <paragraph>
155 The next transition is legal:
156 <transition>
157 <section ids="section-2" names="section\ 2">
158 <title>
159 Section 2
160 <system_message level="3" line="15" source="test data" type="ERROR">
161 <paragraph>
162 Document or section may not begin with a transition.
163 <transition>
164 <system_message level="3" line="15" source="test data" type="ERROR">
165 <paragraph>
166 Document may not end with a transition.
167 """],
168 ["""\
169 A paragraph and two transitions.
171 ----------
173 ----------
174 """, # the same:
175 """\
176 <document source="test data">
177 <paragraph>
178 A paragraph and two transitions.
179 <transition>
180 <system_message level="3" line="5" source="test data" type="ERROR">
181 <paragraph>
182 At least one body element must separate transitions; adjacent transitions are not allowed.
183 <transition>
184 <system_message level="3" line="5" source="test data" type="ERROR">
185 <paragraph>
186 Document may not end with a transition.
187 """],
188 ["""\
189 A paragraph, two transitions, and a blank line.
191 ----------
193 ----------
195 """,
196 """\
197 <document source="test data">
198 <paragraph>
199 A paragraph, two transitions, and a blank line.
200 <transition>
201 <system_message level="3" line="5" source="test data" type="ERROR">
202 <paragraph>
203 At least one body element must separate transitions; adjacent transitions are not allowed.
204 <transition>
205 <system_message level="3" line="5" source="test data" type="ERROR">
206 <paragraph>
207 Document may not end with a transition.
208 """],
209 ["""\
210 ----------
212 Document beginning with a transition.
213 """,
214 """\
215 <document source="test data">
216 <system_message level="3" line="1" source="test data" type="ERROR">
217 <paragraph>
218 Document or section may not begin with a transition.
219 <transition>
220 <paragraph>
221 Document beginning with a transition.
222 """],
223 ["""\
224 Section 1
225 =========
227 ----------
229 ----------
231 ----------
233 Section 2
234 =========
236 Some text.
237 """,
238 """\
239 <document source="test data">
240 <section ids="section-1" names="section\ 1">
241 <title>
242 Section 1
243 <system_message level="3" line="4" source="test data" type="ERROR">
244 <paragraph>
245 Document or section may not begin with a transition.
246 <transition>
247 <system_message level="3" line="6" source="test data" type="ERROR">
248 <paragraph>
249 At least one body element must separate transitions; adjacent transitions are not allowed.
250 <transition>
251 <system_message level="3" line="8" source="test data" type="ERROR">
252 <paragraph>
253 At least one body element must separate transitions; adjacent transitions are not allowed.
254 <transition>
255 <section ids="section-2" names="section\ 2">
256 <title>
257 Section 2
258 <paragraph>
259 Some text.
260 """],
261 ["""\
262 ----------
264 ----------
266 ----------
267 """,
268 """\
269 <document source="test data">
270 <system_message level="3" line="1" source="test data" type="ERROR">
271 <paragraph>
272 Document or section may not begin with a transition.
273 <transition>
274 <system_message level="3" line="3" source="test data" type="ERROR">
275 <paragraph>
276 At least one body element must separate transitions; adjacent transitions are not allowed.
277 <transition>
278 <system_message level="3" line="5" source="test data" type="ERROR">
279 <paragraph>
280 At least one body element must separate transitions; adjacent transitions are not allowed.
281 <transition>
282 <system_message level="3" line="5" source="test data" type="ERROR">
283 <paragraph>
284 Document may not end with a transition.
285 """],
286 ["""\
287 A paragraph.
289 ----------
291 """,
292 """\
293 <document source="test data">
294 <paragraph>
295 A paragraph.
296 <transition>
297 <system_message level="3" line="3" source="test data" type="ERROR">
298 <paragraph>
299 Document may not end with a transition.
300 """],
304 if __name__ == '__main__':
305 import unittest
306 unittest.main(defaultTest='suite')