remove unused or duplicate imports (mercurial)
[docutils.git] / test / test_transforms / test_contents.py
blob42620ab558185189e3389ca0ec05b9d9c2a1da00
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 Tests for `docutils.transforms.parts.Contents` (via
9 `docutils.transforms.universal.LastReaderPending`).
10 """
12 from __init__ import DocutilsTestSupport
13 from docutils.transforms.references import Substitutions
14 from docutils.parsers.rst import Parser
17 def suite():
18 parser = Parser()
19 s = DocutilsTestSupport.TransformTestSuite(parser)
20 s.generateTests(totest)
21 return s
23 totest = {}
25 totest['tables_of_contents'] = ((Substitutions,), [
26 ["""\
27 .. contents::
29 Title 1
30 =======
31 Paragraph 1.
33 Title_ 2
34 --------
35 Paragraph 2.
37 _`Title` 3
38 ``````````
39 Paragraph 3.
41 Title 4
42 -------
43 Paragraph 4.
44 """,
45 """\
46 <document source="test data">
47 <topic classes="contents" ids="contents" names="contents">
48 <title>
49 Contents
50 <bullet_list>
51 <list_item>
52 <paragraph>
53 <reference ids="id1" refid="title-1">
54 Title 1
55 <bullet_list>
56 <list_item>
57 <paragraph>
58 <reference ids="id2" refid="title-2">
59 Title
61 <bullet_list>
62 <list_item>
63 <paragraph>
64 <reference ids="id3" refid="title-3">
65 Title
67 <list_item>
68 <paragraph>
69 <reference ids="id4" refid="title-4">
70 Title 4
71 <section ids="title-1" names="title\ 1">
72 <title refid="id1">
73 Title 1
74 <paragraph>
75 Paragraph 1.
76 <section ids="title-2" names="title\ 2">
77 <title>
78 <reference name="Title" refname="title">
79 Title
81 <paragraph>
82 Paragraph 2.
83 <section ids="title-3" names="title\ 3">
84 <title refid="id3">
85 <target ids="title" names="title">
86 Title
88 <paragraph>
89 Paragraph 3.
90 <section ids="title-4" names="title\ 4">
91 <title refid="id4">
92 Title 4
93 <paragraph>
94 Paragraph 4.
95 """],
96 ["""\
97 .. contents:: Table of Contents
99 Title 1
100 =======
101 Paragraph 1.
103 Title 2
104 -------
105 Paragraph 2.
106 """,
107 """\
108 <document source="test data">
109 <topic classes="contents" ids="table-of-contents" names="table\ of\ contents">
110 <title>
111 Table of Contents
112 <bullet_list>
113 <list_item>
114 <paragraph>
115 <reference ids="id1" refid="title-1">
116 Title 1
117 <bullet_list>
118 <list_item>
119 <paragraph>
120 <reference ids="id2" refid="title-2">
121 Title 2
122 <section ids="title-1" names="title\ 1">
123 <title refid="id1">
124 Title 1
125 <paragraph>
126 Paragraph 1.
127 <section ids="title-2" names="title\ 2">
128 <title refid="id2">
129 Title 2
130 <paragraph>
131 Paragraph 2.
132 """],
133 ["""\
134 .. contents:: There's an image in Title 2
136 Title 1
137 =======
138 Paragraph 1.
140 |Title 2|
141 =========
142 Paragraph 2.
144 .. |Title 2| image:: title2.png
145 """,
146 """\
147 <document source="test data">
148 <topic classes="contents" ids="there-s-an-image-in-title-2" names="there's\ an\ image\ in\ title\ 2">
149 <title>
150 There's an image in Title 2
151 <bullet_list>
152 <list_item>
153 <paragraph>
154 <reference ids="id1" refid="title-1">
155 Title 1
156 <list_item>
157 <paragraph>
158 <reference ids="id2" refid="title-2">
159 Title 2
160 <section ids="title-1" names="title\ 1">
161 <title refid="id1">
162 Title 1
163 <paragraph>
164 Paragraph 1.
165 <section ids="title-2" names="title\ 2">
166 <title refid="id2">
167 <image alt="Title 2" uri="title2.png">
168 <paragraph>
169 Paragraph 2.
170 <substitution_definition names="Title\ 2">
171 <image alt="Title 2" uri="title2.png">
172 """], # emacs cruft: "
173 ["""\
174 .. contents::
175 :depth: 2
177 Title 1
178 =======
179 Paragraph 1.
181 Title 2
182 -------
183 Paragraph 2.
185 Title 3
186 ```````
187 Paragraph 3.
189 Title 4
190 -------
191 Paragraph 4.
192 """,
193 """\
194 <document source="test data">
195 <topic classes="contents" ids="contents" names="contents">
196 <title>
197 Contents
198 <bullet_list>
199 <list_item>
200 <paragraph>
201 <reference ids="id1" refid="title-1">
202 Title 1
203 <bullet_list>
204 <list_item>
205 <paragraph>
206 <reference ids="id2" refid="title-2">
207 Title 2
208 <list_item>
209 <paragraph>
210 <reference ids="id3" refid="title-4">
211 Title 4
212 <section ids="title-1" names="title\ 1">
213 <title refid="id1">
214 Title 1
215 <paragraph>
216 Paragraph 1.
217 <section ids="title-2" names="title\ 2">
218 <title refid="id2">
219 Title 2
220 <paragraph>
221 Paragraph 2.
222 <section ids="title-3" names="title\ 3">
223 <title>
224 Title 3
225 <paragraph>
226 Paragraph 3.
227 <section ids="title-4" names="title\ 4">
228 <title refid="id3">
229 Title 4
230 <paragraph>
231 Paragraph 4.
232 """],
233 ["""\
234 Title 1
235 =======
237 .. contents::
238 :local:
240 Paragraph 1.
242 Title 2
243 -------
244 Paragraph 2.
246 Title 3
247 ```````
248 Paragraph 3.
250 Title 4
251 -------
252 Paragraph 4.
253 """,
254 """\
255 <document source="test data">
256 <section ids="title-1" names="title\ 1">
257 <title>
258 Title 1
259 <topic classes="contents local" ids="contents" names="contents">
260 <bullet_list>
261 <list_item>
262 <paragraph>
263 <reference ids="id1" refid="title-2">
264 Title 2
265 <bullet_list>
266 <list_item>
267 <paragraph>
268 <reference ids="id2" refid="title-3">
269 Title 3
270 <list_item>
271 <paragraph>
272 <reference ids="id3" refid="title-4">
273 Title 4
274 <paragraph>
275 Paragraph 1.
276 <section ids="title-2" names="title\ 2">
277 <title refid="id1">
278 Title 2
279 <paragraph>
280 Paragraph 2.
281 <section ids="title-3" names="title\ 3">
282 <title refid="id2">
283 Title 3
284 <paragraph>
285 Paragraph 3.
286 <section ids="title-4" names="title\ 4">
287 <title refid="id3">
288 Title 4
289 <paragraph>
290 Paragraph 4.
291 """],
292 ["""\
293 .. contents::
294 :local:
296 Test duplicate name "Contents".
298 Section
299 --------
300 Paragraph.
301 """,
302 """\
303 <document source="test data">
304 <topic classes="contents local" ids="contents" names="contents">
305 <bullet_list>
306 <list_item>
307 <paragraph>
308 <reference ids="id1" refid="section">
309 Section
310 <paragraph>
311 Test duplicate name "Contents".
312 <section ids="section" names="section">
313 <title refid="id1">
314 Section
315 <paragraph>
316 Paragraph.
317 """],
318 ["""\
319 .. contents::
320 :backlinks: top
322 Section
323 --------
324 Paragraph.
325 """,
326 """\
327 <document source="test data">
328 <topic classes="contents" ids="contents" names="contents">
329 <title>
330 Contents
331 <bullet_list>
332 <list_item>
333 <paragraph>
334 <reference ids="id1" refid="section">
335 Section
336 <section ids="section" names="section">
337 <title refid="contents">
338 Section
339 <paragraph>
340 Paragraph.
341 """],
342 ["""\
343 .. contents::
344 :backlinks: none
346 Section
347 --------
348 Paragraph.
349 """,
350 """\
351 <document source="test data">
352 <topic classes="contents" ids="contents" names="contents">
353 <title>
354 Contents
355 <bullet_list>
356 <list_item>
357 <paragraph>
358 <reference ids="id1" refid="section">
359 Section
360 <section ids="section" names="section">
361 <title>
362 Section
363 <paragraph>
364 Paragraph.
365 """],
366 ["""\
367 .. contents::
369 Degenerate case, no table of contents generated.
370 """,
371 """\
372 <document source="test data">
373 <paragraph>
374 Degenerate case, no table of contents generated.
375 """],
376 ["""\
377 Title 1
378 =======
380 Paragraph 1.
382 .. sidebar:: Contents
384 .. contents::
385 :local:
387 Title 2
388 -------
389 Paragraph 2.
391 Title 3
392 ```````
393 Paragraph 3.
394 """,
395 """\
396 <document source="test data">
397 <section ids="title-1" names="title\ 1">
398 <title>
399 Title 1
400 <paragraph>
401 Paragraph 1.
402 <sidebar>
403 <title>
404 Contents
405 <topic classes="contents local" ids="contents" names="contents">
406 <bullet_list>
407 <list_item>
408 <paragraph>
409 <reference ids="id1" refid="title-2">
410 Title 2
411 <bullet_list>
412 <list_item>
413 <paragraph>
414 <reference ids="id2" refid="title-3">
415 Title 3
416 <section ids="title-2" names="title\ 2">
417 <title refid="id1">
418 Title 2
419 <paragraph>
420 Paragraph 2.
421 <section ids="title-3" names="title\ 3">
422 <title refid="id2">
423 Title 3
424 <paragraph>
425 Paragraph 3.
426 """],
430 if __name__ == '__main__':
431 import unittest
432 unittest.main(defaultTest='suite')