4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
8 Tests for images.py image directives.
11 from __init__
import DocutilsTestSupport
13 from docutils
.nodes
import reprunicode
16 s
= DocutilsTestSupport
.ParserTestSuite()
17 s
.generateTests(totest
)
24 .. image:: picture.png
27 <document source="test data">
28 <image uri="picture.png">
34 <document source="test data">
35 <system_message level="3" line="1" source="test data" type="ERROR">
37 Error in "image" directive:
38 1 argument(s) required, 0 supplied.
39 <literal_block xml:space="preserve">
43 .. image:: one two three.png
46 <document source="test data">
47 <image uri="onetwothree.png">
50 .. image:: picture.png
56 <document source="test data">
57 <image height="100" scale="50" uri="picture.png" width="200">
67 <document source="test data">
68 <image height="100" scale="50" uri="picture.png" width="200">
77 <document source="test data">
78 <system_message level="3" line="1" source="test data" type="ERROR">
80 Error in "image" directive:
81 1 argument(s) required, 0 supplied.
82 <literal_block xml:space="preserve">
88 # If there are multiple lines in the link block, they are stripped of
89 # leading and trailing whitespace and joined together:
91 .. image:: a/very/long/path/to/
98 <document source="test data">
99 <image height="100" scale="50" uri="a/very/long/path/to/picture.png" width="200">
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):
105 .. image:: picture.png
109 <document source="test data">
110 <image uri="picture.png:scale50">
113 .. image:: picture.png
117 <document source="test data">
118 <image uri="picture.png::50">
120 # a missing leading colon went undetected also in Docutils <= 0.8:
122 .. image:: picture.png
126 <document source="test data">
127 <image uri="picture.pngscale:50">
130 .. image:: picture.png
135 <document source="test data">
136 <image height="100em" uri="picture.png" width="200px">
139 .. image:: picture.png
144 <document source="test data">
145 <image height="10mm" uri="picture.png" width="50%">
148 .. image:: picture.png
153 <document source="test data">
154 <system_message level="3" line="1" source="test data" type="ERROR">
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
166 .. image:: picture.png
170 :alt: Alternate text for the picture
173 <document source="test data">
174 <image alt="Alternate text for the picture" height="100" scale="50" uri="picture.png" width="200">
177 .. image:: picture.png
181 <document source="test data">
182 <system_message level="3" line="1" source="test data" type="ERROR">
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
192 .. image:: picture.png
196 <document source="test data">
197 <system_message level="3" line="1" source="test data" type="ERROR">
199 Error in "image" directive:
200 invalid option value: (option: "scale"; value: None)
202 <literal_block xml:space="preserve">
203 .. image:: picture.png
205 """ % DocutilsTestSupport
.exception_data(int, None)[1][0]],
207 .. image:: picture.png
212 <document source="test data">
213 <system_message level="3" line="1" source="test data" type="ERROR">
215 Error in "image" directive:
216 invalid option block.
217 <literal_block xml:space="preserve">
218 .. image:: picture.png
223 .. image:: picture.png
227 <document source="test data">
228 <system_message level="3" line="1" source="test data" type="ERROR">
230 Error in "image" directive:
231 unknown option: "sale".
232 <literal_block xml:space="preserve">
233 .. image:: picture.png
237 .. image:: picture.png
241 <document source="test data">
242 <system_message level="3" line="1" source="test data" type="ERROR">
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
251 .. image:: picture.png
255 <document source="test data">
256 <system_message level="3" line="1" source="test data" type="ERROR">
258 Error in "image" directive:
259 invalid option value: (option: "scale"; value: 'fifty')
261 <literal_block xml:space="preserve">
262 .. image:: picture.png
264 """ % DocutilsTestSupport
.exception_data(int, "fifty")[1][0]],
266 .. image:: picture.png
271 <document source="test data">
272 <system_message level="3" line="1" source="test data" type="ERROR">
274 Error in "image" directive:
275 invalid option data: duplicate option "scale".
276 <literal_block xml:space="preserve">
277 .. image:: picture.png
282 .. image:: picture.png
285 (Empty "alt" option.)
288 <document source="test data">
289 <image alt="" uri="picture.png">
291 (Empty "alt" option.)
294 .. image:: picture.png
295 :target: bigpicture.png
299 <document source="test data">
300 <reference refuri="bigpicture.png">
301 <image ids="fig-pix" names="fig:pix" uri="picture.png">
304 .. image:: picture.png
308 <document source="test data">
309 <reference name="indirect" refname="indirect">
310 <image uri="picture.png">
313 .. image:: picture.png
317 .. image:: picture.png
318 :target: `a multi line
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">
329 .. image:: picture.png
333 <document source="test data">
334 <system_message level="3" line="1" source="test data" type="ERROR">
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
344 .. image:: picture.png
348 <document source="test data">
349 <image align="left" uri="picture.png">
352 .. image:: picture.png
356 <document source="test data">
357 <system_message level="3" line="1" source="test data" type="ERROR">
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
365 .. |img| image:: picture.png
369 <document source="test data">
370 <substitution_definition names="img">
371 <image align="top" alt="img" uri="picture.png">
374 .. |img| image:: picture.png
378 <document source="test data">
379 <system_message level="3" line="1" source="test data" type="ERROR">
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">
385 <system_message level="2" line="1" source="test data" type="WARNING">
387 Substitution definition "img" empty or invalid.
388 <literal_block xml:space="preserve">
389 .. |img| image:: picture.png
393 .. image:: picture.png
397 <document source="test data">
398 <system_message level="3" line="1" source="test data" type="ERROR">
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
406 """ % repr(reprunicode(u
'\xe4'))],
411 .. _Uppercase: http://docutils.sourceforge.net/
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/">
422 if __name__
== '__main__':
424 unittest
.main(defaultTest
='suite')