add project gutenberg
[docutils.git] / test / test_transforms / test_docinfo.py
blobacdee52ac1922e411752918a526b3df682ff47fd
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.frontmatter.DocInfo.
9 """
11 from __init__ import DocutilsTestSupport
12 from docutils.transforms.frontmatter import DocInfo
13 from docutils.parsers.rst import Parser
16 def suite():
17 parser = Parser()
18 s = DocutilsTestSupport.TransformTestSuite(parser)
19 s.generateTests(totest)
20 return s
22 totest = {}
24 totest['bibliographic_field_lists'] = ((DocInfo,), [
25 ["""\
26 .. Bibliographic element extraction.
28 :Abstract:
29 There can only be one abstract.
31 It is automatically moved to the end of the other bibliographic elements.
33 :Author: Me
34 :Version: 1
35 :Date: 2001-08-11
36 :Parameter i: integer
37 """,
38 """\
39 <document source="test data">
40 <docinfo>
41 <author>
43 <version>
45 <date>
46 2001-08-11
47 <field>
48 <field_name>
49 Parameter i
50 <field_body>
51 <paragraph>
52 integer
53 <topic classes="abstract">
54 <title>
55 Abstract
56 <paragraph>
57 There can only be one abstract.
58 <paragraph>
59 It is automatically moved to the end of the other bibliographic elements.
60 <comment xml:space="preserve">
61 Bibliographic element extraction.
62 """],
63 ["""\
64 .. Bibliographic element extraction.
66 :Abstract: Abstract 1.
67 :Author: Me
68 :Address: 123 My Street
69 Example, EX
70 :Contact: me@my.org
71 :Version: 1
72 :Abstract: Abstract 2 (should generate a warning).
73 :Date: 2001-08-11
74 :Parameter i: integer
75 """,
76 """\
77 <document source="test data">
78 <docinfo>
79 <author>
81 <address xml:space="preserve">
82 123 My Street
83 Example, EX
84 <contact>
85 <reference refuri="mailto:me@my.org">
86 me@my.org
87 <version>
89 <field>
90 <field_name>
91 Abstract
92 <field_body>
93 <paragraph>
94 Abstract 2 (should generate a warning).
95 <system_message level="2" line="9" source="test data" type="WARNING">
96 <paragraph>
97 There can only be one "Abstract" field.
98 <date>
99 2001-08-11
100 <field>
101 <field_name>
102 Parameter i
103 <field_body>
104 <paragraph>
105 integer
106 <topic classes="abstract">
107 <title>
108 Abstract
109 <paragraph>
110 Abstract 1.
111 <comment xml:space="preserve">
112 Bibliographic element extraction.
113 """],
114 ["""\
115 :Author: - must be a paragraph
116 :Status: a *simple* paragraph
117 :Date: But only one
119 paragraph.
120 :Version:
122 .. and not empty either
123 """,
124 """\
125 <document source="test data">
126 <docinfo>
127 <field>
128 <field_name>
129 Author
130 <field_body>
131 <bullet_list bullet="-">
132 <list_item>
133 <paragraph>
134 must be a paragraph
135 <system_message level="2" line="1" source="test data" type="WARNING">
136 <paragraph>
137 Cannot extract bibliographic field "Author" containing anything other than a single paragraph.
138 <status>
139 a \n\
140 <emphasis>
141 simple
142 paragraph
143 <field>
144 <field_name>
145 Date
146 <field_body>
147 <paragraph>
148 But only one
149 <paragraph>
150 paragraph.
151 <system_message level="2" line="3" source="test data" type="WARNING">
152 <paragraph>
153 Cannot extract compound bibliographic field "Date".
154 <field>
155 <field_name>
156 Version
157 <field_body>
158 <system_message level="2" line="6" source="test data" type="WARNING">
159 <paragraph>
160 Cannot extract empty bibliographic field "Version".
161 <comment xml:space="preserve">
162 and not empty either
163 """],
164 ["""\
165 :Authors: Me, Myself, **I**
166 :Authors: PacMan; Ms. PacMan; PacMan, Jr.
167 :Authors:
168 Here
170 There
172 *Everywhere*
173 :Authors: - First
174 - Second
175 - Third
176 """,
177 """\
178 <document source="test data">
179 <docinfo>
180 <authors>
181 <author>
183 <author>
184 Myself
185 <author>
187 <authors>
188 <author>
189 PacMan
190 <author>
191 Ms. PacMan
192 <author>
193 PacMan, Jr.
194 <authors>
195 <author>
196 Here
197 <author>
198 There
199 <author>
200 <emphasis>
201 Everywhere
202 <authors>
203 <author>
204 First
205 <author>
206 Second
207 <author>
208 Third
209 """],
210 ["""\
211 :Authors: Only One
212 :Authors: One, Only;
213 """,
214 """\
215 <document source="test data">
216 <docinfo>
217 <authors>
218 <author>
219 Only One
220 <authors>
221 <author>
222 One, Only
223 """],
224 ["""\
225 :Authors:
227 :Authors: 1. One
228 2. Two
230 :Authors:
234 :Authors:
235 - One
239 :Authors:
240 - One
243 """,
244 """\
245 <document source="test data">
246 <docinfo>
247 <field>
248 <field_name>
249 Authors
250 <field_body>
251 <system_message level="2" line="1" source="test data" type="WARNING">
252 <paragraph>
253 Cannot extract empty bibliographic field "Authors".
254 <field>
255 <field_name>
256 Authors
257 <field_body>
258 <enumerated_list enumtype="arabic" prefix="" suffix=".">
259 <list_item>
260 <paragraph>
262 <list_item>
263 <paragraph>
265 <system_message level="2" line="3" source="test data" type="WARNING">
266 <paragraph>
267 Bibliographic field "Authors" incompatible with extraction: it must contain either a single paragraph (with authors separated by one of ";,"), multiple paragraphs (one per author), or a bullet list with one paragraph (one author) per item.
268 <field>
269 <field_name>
270 Authors
271 <field_body>
272 <bullet_list bullet="-">
273 <list_item>
274 <list_item>
275 <system_message level="2" line="6" source="test data" type="WARNING">
276 <paragraph>
277 Bibliographic field "Authors" incompatible with extraction: it must contain either a single paragraph (with authors separated by one of ";,"), multiple paragraphs (one per author), or a bullet list with one paragraph (one author) per item.
278 <field>
279 <field_name>
280 Authors
281 <field_body>
282 <bullet_list bullet="-">
283 <list_item>
284 <paragraph>
286 <paragraph>
288 <system_message level="2" line="10" source="test data" type="WARNING">
289 <paragraph>
290 Bibliographic field "Authors" incompatible with extraction: it must contain either a single paragraph (with authors separated by one of ";,"), multiple paragraphs (one per author), or a bullet list with one paragraph (one author) per item.
291 <field>
292 <field_name>
293 Authors
294 <field_body>
295 <bullet_list bullet="-">
296 <list_item>
297 <paragraph>
299 <paragraph>
301 <system_message level="2" line="15" source="test data" type="WARNING">
302 <paragraph>
303 Bibliographic field "Authors" incompatible with extraction: it must contain either a single paragraph (with authors separated by one of ";,"), multiple paragraphs (one per author), or a bullet list with one paragraph (one author) per item.
304 """],
305 ["""\
306 .. RCS keyword extraction.
308 :Status: (some text) $""" + """RCSfile: test_docinfo.py,v $ (more text)
309 :Date: (some text) $""" + """Date: 2002/10/08 01:34:23 $ (more text)
310 :Date: (some text) $""" + """Date: 2005-03-26T16:21:28.693201Z $ (more text)
311 :Version: (some text) $""" + """Revision: 1.1 $ (more text)
312 """,
313 """\
314 <document source="test data">
315 <docinfo>
316 <status>
317 (some text) test_docinfo.py (more text)
318 <date>
319 (some text) 2002-10-08 (more text)
320 <date>
321 (some text) 2005-03-26 (more text)
322 <version>
323 (some text) 1.1 (more text)
324 <comment xml:space="preserve">
325 RCS keyword extraction.
326 """],
330 if __name__ == '__main__':
331 import unittest
332 unittest.main(defaultTest='suite')