#! /usr/bin/env python # $Id: test_images.py 7348 2012-02-08 19:46:11Z milde $ # Author: David Goodger # Copyright: This module has been placed in the public domain. """ Tests for images.py image directives. """ from .__init__ import DocutilsTestSupport from docutils.nodes import reprunicode def suite(): s = DocutilsTestSupport.ParserTestSuite() s.generateTests(totest) return s totest = {} totest['images'] = [ ["""\ .. image:: picture.png """, """\ """], ["""\ .. image:: """, """\ Error in "image" directive: 1 argument(s) required, 0 supplied. .. image:: """], ["""\ .. image:: one two three.png """, """\ """], ["""\ .. image:: picture.png :height: 100 :width: 200 :scale: 50 """, """\ """], ["""\ .. image:: picture.png :height: 100 :width: 200 :scale: 50 """, """\ """], ["""\ .. image:: :height: 100 :width: 200 :scale: 50 """, """\ Error in "image" directive: 1 argument(s) required, 0 supplied. .. image:: :height: 100 :width: 200 :scale: 50 """], # If there are multiple lines in the link block, they are stripped of # leading and trailing whitespace and joined together: ["""\ .. image:: a/very/long/path/to/ picture.png :height: 100 :width: 200 :scale: 50 """, """\ """], # The following two misspellings were detected in Docutils <= 0.8 # (the option block was started by any line starting with a colon # which led to problems with named roles in other directives): ["""\ .. image:: picture.png :scale 50 """, """\ """], ["""\ .. image:: picture.png :: 50 """, """\ """], # a missing leading colon went undetected also in Docutils <= 0.8: ["""\ .. image:: picture.png scale: 50 """, """\ """], ["""\ .. image:: picture.png :width: 200px :height: 100 em """, """\ """], ["""\ .. image:: picture.png :width: 50% :height: 10mm """, """\ """], ["""\ .. image:: picture.png :width: 50% :height: 40% """, """\ Error in "image" directive: invalid option value: (option: "height"; value: \'40%\') not a positive measure of one of the following units: "em" "ex" "px" "in" "cm" "mm" "pt" "pc" "". .. image:: picture.png :width: 50% :height: 40% """], ["""\ .. image:: picture.png :height: 100 :width: 200 :scale: 50 :alt: Alternate text for the picture """, """\ Alternate text for the picture """], ["""\ .. image:: picture.png :scale: -50 """, """\ Error in "image" directive: invalid option value: (option: "scale"; value: '-50') negative value; must be positive or zero. .. image:: picture.png :scale: -50 """], ["""\ .. image:: picture.png :scale: """, """\ Error in "image" directive: invalid option value: (option: "scale"; value: None) %s. .. image:: picture.png :scale: """ % DocutilsTestSupport.exception_data(int, None)[1][0]], ["""\ .. image:: picture.png :height: 100 :scale 50 """, """\ Error in "image" directive: invalid option block. .. image:: picture.png :height: 100 :scale 50 """], ["""\ .. image:: picture.png :sale: 50 """, """\ Error in "image" directive: unknown option: "sale". .. image:: picture.png :sale: 50 """], ["""\ .. image:: picture.png :scale is: 50 """, """\ Error in "image" directive: invalid option data: extension option field name may not contain multiple words. .. image:: picture.png :scale is: 50 """], ["""\ .. image:: picture.png :scale: fifty """, """\ Error in "image" directive: invalid option value: (option: "scale"; value: 'fifty') %s. .. image:: picture.png :scale: fifty """ % DocutilsTestSupport.exception_data(int, "fifty")[1][0]], ["""\ .. image:: picture.png :scale: 50 :scale: 50 """, """\ Error in "image" directive: invalid option data: duplicate option "scale". .. image:: picture.png :scale: 50 :scale: 50 """], ["""\ .. image:: picture.png :alt: (Empty "alt" option.) """, """\ (Empty "alt" option.) """], ["""\ .. image:: picture.png :target: bigpicture.png :name: fig:pix """, """\ """], ["""\ .. image:: picture.png :target: indirect_ """, """\ """], ["""\ .. image:: picture.png :target: a/multi/ line/uri .. image:: picture.png :target: `a multi line internal reference`_ """, """\ """], ["""\ .. image:: picture.png :target: """, """\ Error in "image" directive: invalid option value: (option: "target"; value: None) argument required but none supplied. .. image:: picture.png :target: """], ["""\ .. image:: picture.png :align: left """, """\ """], ["""\ .. image:: picture.png :align: top """, """\ Error in "image" directive: "top" is not a valid value for the "align" option. Valid values for "align" are: "left", "center", "right". .. image:: picture.png :align: top """], ["""\ .. |img| image:: picture.png :align: top """, """\ img """], ["""\ .. |img| image:: picture.png :align: left """, """\ 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". image:: picture.png :align: left Substitution definition "img" empty or invalid. .. |img| image:: picture.png :align: left """], ["""\ .. image:: picture.png :align: \xe4 """, """\ Error in "image" directive: invalid option value: (option: "align"; value: %s) "\xe4" unknown; choose from "top", "middle", "bottom", "left", "center", or "right". .. image:: picture.png :align: \xe4 """ % repr(reprunicode('\xe4'))], [""" .. image:: test.png :target: Uppercase_ .. _Uppercase: http://docutils.sourceforge.net/ """, """\ """], ] if __name__ == '__main__': import unittest unittest.main(defaultTest='suite')