Use `field_marker` pattern to look for start of a directive option block
[docutils.git] / test / test_parsers / test_rst / test_directives / test_images.py
blob67d898eb4a190ae44768e5ebf93fc588c0ad04d1
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 images.py image directives.
9 """
11 from __init__ import DocutilsTestSupport
13 from docutils.nodes import reprunicode
15 def suite():
16 s = DocutilsTestSupport.ParserTestSuite()
17 s.generateTests(totest)
18 return s
20 totest = {}
22 totest['images'] = [
23 ["""\
24 .. image:: picture.png
25 """,
26 """\
27 <document source="test data">
28 <image uri="picture.png">
29 """],
30 ["""\
31 .. image::
32 """,
33 """\
34 <document source="test data">
35 <system_message level="3" line="1" source="test data" type="ERROR">
36 <paragraph>
37 Error in "image" directive:
38 1 argument(s) required, 0 supplied.
39 <literal_block xml:space="preserve">
40 .. image::
41 """],
42 ["""\
43 .. image:: one two three.png
44 """,
45 """\
46 <document source="test data">
47 <image uri="onetwothree.png">
48 """],
49 ["""\
50 .. image:: picture.png
51 :height: 100
52 :width: 200
53 :scale: 50
54 """,
55 """\
56 <document source="test data">
57 <image height="100" scale="50" uri="picture.png" width="200">
58 """],
59 ["""\
60 .. image::
61 picture.png
62 :height: 100
63 :width: 200
64 :scale: 50
65 """,
66 """\
67 <document source="test data">
68 <image height="100" scale="50" uri="picture.png" width="200">
69 """],
70 ["""\
71 .. image::
72 :height: 100
73 :width: 200
74 :scale: 50
75 """,
76 """\
77 <document source="test data">
78 <system_message level="3" line="1" source="test data" type="ERROR">
79 <paragraph>
80 Error in "image" directive:
81 1 argument(s) required, 0 supplied.
82 <literal_block xml:space="preserve">
83 .. image::
84 :height: 100
85 :width: 200
86 :scale: 50
87 """],
88 # If there are multiple lines in the link block, they are stripped of
89 # leading and trailing whitespace and joined together:
90 ["""\
91 .. image:: a/very/long/path/to/
92 picture.png
93 :height: 100
94 :width: 200
95 :scale: 50
96 """,
97 """\
98 <document source="test data">
99 <image height="100" scale="50" uri="a/very/long/path/to/picture.png" width="200">
100 """],
101 # The following two misspellings were detected in Docutils <= 0.8
102 # (the option block was started by any line starting with a colon
103 # which led to problems with named roles in other directives):
104 ["""\
105 .. image:: picture.png
106 :scale 50
107 """,
108 """\
109 <document source="test data">
110 <image uri="picture.png:scale50">
111 """],
112 ["""\
113 .. image:: picture.png
114 :: 50
115 """,
116 """\
117 <document source="test data">
118 <image uri="picture.png::50">
119 """],
120 # a missing leading colon went undetected also in Docutils <= 0.8:
121 ["""\
122 .. image:: picture.png
123 scale: 50
124 """,
125 """\
126 <document source="test data">
127 <image uri="picture.pngscale:50">
128 """],
129 ["""\
130 .. image:: picture.png
131 :width: 200px
132 :height: 100 em
133 """,
134 """\
135 <document source="test data">
136 <image height="100em" uri="picture.png" width="200px">
137 """],
138 ["""\
139 .. image:: picture.png
140 :width: 50%
141 :height: 10mm
142 """,
143 """\
144 <document source="test data">
145 <image height="10mm" uri="picture.png" width="50%">
146 """],
147 ["""\
148 .. image:: picture.png
149 :width: 50%
150 :height: 40%
151 """,
152 """\
153 <document source="test data">
154 <system_message level="3" line="1" source="test data" type="ERROR">
155 <paragraph>
156 Error in "image" directive:
157 invalid option value: (option: "height"; value: \'40%\')
158 not a positive measure of one of the following units:
159 "em" "ex" "px" "in" "cm" "mm" "pt" "pc" "".
160 <literal_block xml:space="preserve">
161 .. image:: picture.png
162 :width: 50%
163 :height: 40%
164 """],
165 ["""\
166 .. image:: picture.png
167 :height: 100
168 :width: 200
169 :scale: 50
170 :alt: Alternate text for the picture
171 """,
172 """\
173 <document source="test data">
174 <image alt="Alternate text for the picture" height="100" scale="50" uri="picture.png" width="200">
175 """],
176 ["""\
177 .. image:: picture.png
178 :scale: -50
179 """,
180 """\
181 <document source="test data">
182 <system_message level="3" line="1" source="test data" type="ERROR">
183 <paragraph>
184 Error in "image" directive:
185 invalid option value: (option: "scale"; value: '-50')
186 negative value; must be positive or zero.
187 <literal_block xml:space="preserve">
188 .. image:: picture.png
189 :scale: -50
190 """],
191 ["""\
192 .. image:: picture.png
193 :scale:
194 """,
195 """\
196 <document source="test data">
197 <system_message level="3" line="1" source="test data" type="ERROR">
198 <paragraph>
199 Error in "image" directive:
200 invalid option value: (option: "scale"; value: None)
202 <literal_block xml:space="preserve">
203 .. image:: picture.png
204 :scale:
205 """ % DocutilsTestSupport.exception_data(int, None)[1][0]],
206 ["""\
207 .. image:: picture.png
208 :height: 100
209 :scale 50
210 """,
211 """\
212 <document source="test data">
213 <system_message level="3" line="1" source="test data" type="ERROR">
214 <paragraph>
215 Error in "image" directive:
216 invalid option block.
217 <literal_block xml:space="preserve">
218 .. image:: picture.png
219 :height: 100
220 :scale 50
221 """],
222 ["""\
223 .. image:: picture.png
224 :sale: 50
225 """,
226 """\
227 <document source="test data">
228 <system_message level="3" line="1" source="test data" type="ERROR">
229 <paragraph>
230 Error in "image" directive:
231 unknown option: "sale".
232 <literal_block xml:space="preserve">
233 .. image:: picture.png
234 :sale: 50
235 """],
236 ["""\
237 .. image:: picture.png
238 :scale is: 50
239 """,
240 """\
241 <document source="test data">
242 <system_message level="3" line="1" source="test data" type="ERROR">
243 <paragraph>
244 Error in "image" directive:
245 invalid option data: extension option field name may not contain multiple words.
246 <literal_block xml:space="preserve">
247 .. image:: picture.png
248 :scale is: 50
249 """],
250 ["""\
251 .. image:: picture.png
252 :scale: fifty
253 """,
254 """\
255 <document source="test data">
256 <system_message level="3" line="1" source="test data" type="ERROR">
257 <paragraph>
258 Error in "image" directive:
259 invalid option value: (option: "scale"; value: 'fifty')
261 <literal_block xml:space="preserve">
262 .. image:: picture.png
263 :scale: fifty
264 """ % DocutilsTestSupport.exception_data(int, "fifty")[1][0]],
265 ["""\
266 .. image:: picture.png
267 :scale: 50
268 :scale: 50
269 """,
270 """\
271 <document source="test data">
272 <system_message level="3" line="1" source="test data" type="ERROR">
273 <paragraph>
274 Error in "image" directive:
275 invalid option data: duplicate option "scale".
276 <literal_block xml:space="preserve">
277 .. image:: picture.png
278 :scale: 50
279 :scale: 50
280 """],
281 ["""\
282 .. image:: picture.png
283 :alt:
285 (Empty "alt" option.)
286 """,
287 """\
288 <document source="test data">
289 <image alt="" uri="picture.png">
290 <paragraph>
291 (Empty "alt" option.)
292 """],
293 ["""\
294 .. image:: picture.png
295 :target: bigpicture.png
296 :name: fig:pix
297 """,
298 """\
299 <document source="test data">
300 <reference refuri="bigpicture.png">
301 <image ids="fig-pix" names="fig:pix" uri="picture.png">
302 """],
303 ["""\
304 .. image:: picture.png
305 :target: indirect_
306 """,
307 """\
308 <document source="test data">
309 <reference name="indirect" refname="indirect">
310 <image uri="picture.png">
311 """],
312 ["""\
313 .. image:: picture.png
314 :target: a/multi/
315 line/uri
317 .. image:: picture.png
318 :target: `a multi line
319 internal reference`_
320 """,
321 """\
322 <document source="test data">
323 <reference refuri="a/multi/line/uri">
324 <image uri="picture.png">
325 <reference name="a multi line internal reference" refname="a multi line internal reference">
326 <image uri="picture.png">
327 """],
328 ["""\
329 .. image:: picture.png
330 :target:
331 """,
332 """\
333 <document source="test data">
334 <system_message level="3" line="1" source="test data" type="ERROR">
335 <paragraph>
336 Error in "image" directive:
337 invalid option value: (option: "target"; value: None)
338 argument required but none supplied.
339 <literal_block xml:space="preserve">
340 .. image:: picture.png
341 :target:
342 """],
343 ["""\
344 .. image:: picture.png
345 :align: left
346 """,
347 """\
348 <document source="test data">
349 <image align="left" uri="picture.png">
350 """],
351 ["""\
352 .. image:: picture.png
353 :align: top
354 """,
355 """\
356 <document source="test data">
357 <system_message level="3" line="1" source="test data" type="ERROR">
358 <paragraph>
359 Error in "image" directive: "top" is not a valid value for the "align" option. Valid values for "align" are: "left", "center", "right".
360 <literal_block xml:space="preserve">
361 .. image:: picture.png
362 :align: top
363 """],
364 ["""\
365 .. |img| image:: picture.png
366 :align: top
367 """,
368 """\
369 <document source="test data">
370 <substitution_definition names="img">
371 <image align="top" alt="img" uri="picture.png">
372 """],
373 ["""\
374 .. |img| image:: picture.png
375 :align: left
376 """,
377 """\
378 <document source="test data">
379 <system_message level="3" line="1" source="test data" type="ERROR">
380 <paragraph>
381 Error in "image" directive: "left" is not a valid value for the "align" option within a substitution definition. Valid values for "align" are: "top", "middle", "bottom".
382 <literal_block xml:space="preserve">
383 image:: picture.png
384 :align: left
385 <system_message level="2" line="1" source="test data" type="WARNING">
386 <paragraph>
387 Substitution definition "img" empty or invalid.
388 <literal_block xml:space="preserve">
389 .. |img| image:: picture.png
390 :align: left
391 """],
392 [u"""\
393 .. image:: picture.png
394 :align: \xe4
395 """,
396 u"""\
397 <document source="test data">
398 <system_message level="3" line="1" source="test data" type="ERROR">
399 <paragraph>
400 Error in "image" directive:
401 invalid option value: (option: "align"; value: %s)
402 "\xe4" unknown; choose from "top", "middle", "bottom", "left", "center", or "right".
403 <literal_block xml:space="preserve">
404 .. image:: picture.png
405 :align: \xe4
406 """ % repr(reprunicode(u'\xe4'))],
407 ["""
408 .. image:: test.png
409 :target: Uppercase_
411 .. _Uppercase: http://docutils.sourceforge.net/
412 """,
413 """\
414 <document source="test data">
415 <reference name="Uppercase" refname="uppercase">
416 <image uri="test.png">
417 <target ids="uppercase" names="uppercase" refuri="http://docutils.sourceforge.net/">
418 """],
422 if __name__ == '__main__':
423 import unittest
424 unittest.main(defaultTest='suite')