Fix [ 320 ] Russian docinfo fields not recognized.
[docutils.git] / docutils / test / test_transforms / test_docinfo.py
blobbab166d56b1fcc50a8946bd07ef4e69ce6e7afc3
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # $Id$
5 # Author: David Goodger <goodger@python.org>
6 # Copyright: This module has been placed in the public domain.
8 """
9 Tests for docutils.transforms.frontmatter.DocInfo.
10 """
12 from __init__ import DocutilsTestSupport
13 from docutils.transforms.frontmatter import DocInfo
14 from docutils.parsers.rst import Parser
17 def suite():
18 parser = Parser()
19 settings = {'language_code': 'en'}
20 s = DocutilsTestSupport.TransformTestSuite(
21 parser, suite_settings=settings)
22 s.generateTests(totest)
23 settings['language_code'] = 'de'
24 s.generateTests(totest_de)
25 settings['language_code'] = 'ru'
26 s.generateTests(totest_ru)
27 return s
29 totest = {}
30 totest_de = {}
31 totest_ru = {}
33 totest['bibliographic_field_lists'] = ((DocInfo,), [
34 ["""\
35 .. Bibliographic element extraction.
37 :Abstract:
38 There can only be one abstract.
40 It is automatically moved to the end of the other bibliographic elements.
42 :Author: Me
43 :Version: 1
44 :Date: 2001-08-11
45 :Parameter i: integer
46 """,
47 """\
48 <document source="test data">
49 <docinfo>
50 <author>
52 <version>
54 <date>
55 2001-08-11
56 <field classes="parameter-i">
57 <field_name>
58 Parameter i
59 <field_body>
60 <paragraph>
61 integer
62 <topic classes="abstract">
63 <title>
64 Abstract
65 <paragraph>
66 There can only be one abstract.
67 <paragraph>
68 It is automatically moved to the end of the other bibliographic elements.
69 <comment xml:space="preserve">
70 Bibliographic element extraction.
71 """],
72 ["""\
73 .. Bibliographic element extraction.
75 :Abstract: Abstract 1.
76 :Author: Me
77 :Address: 123 My Street
78 Example, EX
79 :Contact: me@my.org
80 :Version: 1
81 :Abstract: Abstract 2 (should generate a warning).
82 :Date: 2001-08-11
83 :Parameter i: integer
84 """,
85 """\
86 <document source="test data">
87 <docinfo>
88 <author>
90 <address xml:space="preserve">
91 123 My Street
92 Example, EX
93 <contact>
94 <reference refuri="mailto:me@my.org">
95 me@my.org
96 <version>
98 <field>
99 <field_name>
100 Abstract
101 <field_body>
102 <paragraph>
103 Abstract 2 (should generate a warning).
104 <system_message level="2" line="9" source="test data" type="WARNING">
105 <paragraph>
106 There can only be one "Abstract" field.
107 <date>
108 2001-08-11
109 <field classes="parameter-i">
110 <field_name>
111 Parameter i
112 <field_body>
113 <paragraph>
114 integer
115 <topic classes="abstract">
116 <title>
117 Abstract
118 <paragraph>
119 Abstract 1.
120 <comment xml:space="preserve">
121 Bibliographic element extraction.
122 """],
123 ["""\
124 :Author: - must be a paragraph
125 :Status: a *simple* paragraph
126 :Date: But only one
128 paragraph.
129 :Version:
131 .. and not empty either
132 """,
133 """\
134 <document source="test data">
135 <docinfo>
136 <field>
137 <field_name>
138 Author
139 <field_body>
140 <bullet_list bullet="-">
141 <list_item>
142 <paragraph>
143 must be a paragraph
144 <system_message level="2" line="1" source="test data" type="WARNING">
145 <paragraph>
146 Cannot extract bibliographic field "Author" containing anything other than a single paragraph.
147 <status>
148 a \n\
149 <emphasis>
150 simple
151 paragraph
152 <field>
153 <field_name>
154 Date
155 <field_body>
156 <paragraph>
157 But only one
158 <paragraph>
159 paragraph.
160 <system_message level="2" line="3" source="test data" type="WARNING">
161 <paragraph>
162 Cannot extract compound bibliographic field "Date".
163 <field>
164 <field_name>
165 Version
166 <field_body>
167 <system_message level="2" line="6" source="test data" type="WARNING">
168 <paragraph>
169 Cannot extract empty bibliographic field "Version".
170 <comment xml:space="preserve">
171 and not empty either
172 """],
173 ["""\
174 :Authors: Me, Myself, **I**
175 :Authors: PacMan; Ms. PacMan; PacMan, Jr.
176 :Authors:
177 Here
179 There
181 *Everywhere*
182 :Authors: - First
183 - Second
184 - Third
185 """,
186 """\
187 <document source="test data">
188 <docinfo>
189 <authors>
190 <author>
192 <author>
193 Myself
194 <author>
196 <authors>
197 <author>
198 PacMan
199 <author>
200 Ms. PacMan
201 <author>
202 PacMan, Jr.
203 <authors>
204 <author>
205 Here
206 <author>
207 There
208 <author>
209 <emphasis>
210 Everywhere
211 <authors>
212 <author>
213 First
214 <author>
215 Second
216 <author>
217 Third
218 """],
219 ["""\
220 :Authors: Only One
221 :Authors: One, Only;
222 """,
223 """\
224 <document source="test data">
225 <docinfo>
226 <authors>
227 <author>
228 Only One
229 <authors>
230 <author>
231 One, Only
232 """],
233 ["""\
234 :Authors:
236 :Authors: 1. One
237 2. Two
239 :Authors:
243 :Authors:
244 - One
248 :Authors:
249 - One
252 """,
253 """\
254 <document source="test data">
255 <docinfo>
256 <field>
257 <field_name>
258 Authors
259 <field_body>
260 <system_message level="2" line="1" source="test data" type="WARNING">
261 <paragraph>
262 Cannot extract empty bibliographic field "Authors".
263 <field>
264 <field_name>
265 Authors
266 <field_body>
267 <enumerated_list enumtype="arabic" prefix="" suffix=".">
268 <list_item>
269 <paragraph>
271 <list_item>
272 <paragraph>
274 <system_message level="2" line="3" source="test data" type="WARNING">
275 <paragraph>
276 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.
277 <field>
278 <field_name>
279 Authors
280 <field_body>
281 <bullet_list bullet="-">
282 <list_item>
283 <list_item>
284 <system_message level="2" line="6" source="test data" type="WARNING">
285 <paragraph>
286 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.
287 <field>
288 <field_name>
289 Authors
290 <field_body>
291 <bullet_list bullet="-">
292 <list_item>
293 <paragraph>
295 <paragraph>
297 <system_message level="2" line="10" source="test data" type="WARNING">
298 <paragraph>
299 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.
300 <field>
301 <field_name>
302 Authors
303 <field_body>
304 <bullet_list bullet="-">
305 <list_item>
306 <paragraph>
308 <paragraph>
310 <system_message level="2" line="15" source="test data" type="WARNING">
311 <paragraph>
312 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.
313 """],
314 ["""\
315 .. RCS keyword extraction.
317 :Status: (some text) $""" + """RCSfile: test_docinfo.py,v $ (more text)
318 :Date: (some text) $""" + """Date: 2002/10/08 01:34:23 $ (more text)
319 :Date: (some text) $""" + """Date: 2005-03-26T16:21:28.693201Z $ (more text)
320 :Version: (some text) $""" + """Revision: 1.1 $ (more text)
321 """,
322 """\
323 <document source="test data">
324 <docinfo>
325 <status>
326 (some text) test_docinfo.py (more text)
327 <date>
328 (some text) 2002-10-08 (more text)
329 <date>
330 (some text) 2005-03-26 (more text)
331 <version>
332 (some text) 1.1 (more text)
333 <comment xml:space="preserve">
334 RCS keyword extraction.
335 """],
338 totest_de['bibliographic_field_lists'] = ((DocInfo,), [
339 [u"""\
340 .. Bibliographic element extraction for a German document.
342 :Zusammenfassung: Abstract 1.
343 :Autor: Me
344 :Adresse: 123 My Street
345 Example, EX
346 :Kontakt: me@my.org
347 :Version: 1
348 :Datum: 2001-08-11
349 :Parameter i: integer
350 """,
351 u"""\
352 <document source="test data">
353 <docinfo>
354 <author>
356 <address xml:space="preserve">
357 123 My Street
358 Example, EX
359 <contact>
360 <reference refuri="mailto:me@my.org">
361 me@my.org
362 <version>
364 <date>
365 2001-08-11
366 <field classes="parameter-i">
367 <field_name>
368 Parameter i
369 <field_body>
370 <paragraph>
371 integer
372 <topic classes="abstract">
373 <title>
374 Zusammenfassung
375 <paragraph>
376 Abstract 1.
377 <comment xml:space="preserve">
378 Bibliographic element extraction for a German document.
379 """],])
381 totest_ru['bibliographic_field_lists'] = ((DocInfo,), [
382 [u"""\
383 .. Bibliographic element extraction for a Russian document.
385 :аннотация: Abstract 1.
386 :автор: Me
387 :адрес: 123 My Street
388 Example, EX
389 :контакт: me@my.org
390 :версия: 1
391 :дата: 2001-08-11
392 :Parameter i: integer
393 """,
394 u"""\
395 <document source="test data">
396 <docinfo>
397 <author>
399 <address xml:space="preserve">
400 123 My Street
401 Example, EX
402 <contact>
403 <reference refuri="mailto:me@my.org">
404 me@my.org
405 <version>
407 <date>
408 2001-08-11
409 <field classes="parameter-i">
410 <field_name>
411 Parameter i
412 <field_body>
413 <paragraph>
414 integer
415 <topic classes="abstract">
416 <title>
417 Аннотация
418 <paragraph>
419 Abstract 1.
420 <comment xml:space="preserve">
421 Bibliographic element extraction for a Russian document.
422 """],])
425 if __name__ == '__main__':
426 import unittest
427 unittest.main(defaultTest='suite')