diff options
Diffstat (limited to 'test/test_parsers/test_rst/test_directives')
37 files changed, 4731 insertions, 0 deletions
diff --git a/test/test_parsers/test_rst/test_directives/__init__.py b/test/test_parsers/test_rst/test_directives/__init__.py new file mode 100644 index 000000000..46fc50e06 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/__init__.py @@ -0,0 +1,14 @@ +import os +import os.path +import sys + +sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) +prev = '' +while sys.path[0] != prev: + try: + import DocutilsTestSupport + break + except ImportError: + prev = sys.path[0] + sys.path[0] = os.path.dirname(prev) +sys.path.pop(0) diff --git a/test/test_parsers/test_rst/test_directives/empty.txt b/test/test_parsers/test_rst/test_directives/empty.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/empty.txt diff --git a/test/test_parsers/test_rst/test_directives/include 11.txt b/test/test_parsers/test_rst/test_directives/include 11.txt new file mode 100644 index 000000000..7b57bd29e --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/include 11.txt @@ -0,0 +1 @@ +some text diff --git a/test/test_parsers/test_rst/test_directives/include1.txt b/test/test_parsers/test_rst/test_directives/include1.txt new file mode 100644 index 000000000..82f605320 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/include1.txt @@ -0,0 +1,4 @@ +Inclusion 1 +----------- + +This file is used by ``test_include.py``. diff --git a/test/test_parsers/test_rst/test_directives/include10.txt b/test/test_parsers/test_rst/test_directives/include10.txt new file mode 100644 index 000000000..8eb5b1720 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/include10.txt @@ -0,0 +1,7 @@ +.. |bad| unicode:: 0xFFFFFFFFF + +hi +----- + +hi +----- diff --git a/test/test_parsers/test_rst/test_directives/include2.txt b/test/test_parsers/test_rst/test_directives/include2.txt new file mode 100644 index 000000000..3149a7bf6 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/include2.txt @@ -0,0 +1,5 @@ +Here are some paragraphs +that can appear at any level. + +This file (include2.txt) is used by +``test_include.py``. diff --git a/test/test_parsers/test_rst/test_directives/include3.txt b/test/test_parsers/test_rst/test_directives/include3.txt new file mode 100644 index 000000000..9996a4452 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/include3.txt @@ -0,0 +1,3 @@ +In include3.txt + +.. include:: includes/include4.txt diff --git a/test/test_parsers/test_rst/test_directives/include8.txt b/test/test_parsers/test_rst/test_directives/include8.txt new file mode 100644 index 000000000..e7fc57a3d --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/include8.txt @@ -0,0 +1,3 @@ +In include8.txt + +.. include:: ../includes/include9.txt diff --git a/test/test_parsers/test_rst/test_directives/includes/include4.txt b/test/test_parsers/test_rst/test_directives/includes/include4.txt new file mode 100644 index 000000000..384772a77 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/includes/include4.txt @@ -0,0 +1,3 @@ +In includes/include4.txt + +.. include:: include5.txt diff --git a/test/test_parsers/test_rst/test_directives/includes/include5.txt b/test/test_parsers/test_rst/test_directives/includes/include5.txt new file mode 100644 index 000000000..64b3e3aa2 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/includes/include5.txt @@ -0,0 +1,3 @@ +In includes/include5.txt + +.. include:: more/include6.txt diff --git a/test/test_parsers/test_rst/test_directives/includes/more/include6.txt b/test/test_parsers/test_rst/test_directives/includes/more/include6.txt new file mode 100644 index 000000000..8ac403b01 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/includes/more/include6.txt @@ -0,0 +1,3 @@ +In includes/more/include6.txt + +.. include:: ../sibling/include7.txt diff --git a/test/test_parsers/test_rst/test_directives/includes/sibling/include7.txt b/test/test_parsers/test_rst/test_directives/includes/sibling/include7.txt new file mode 100644 index 000000000..fe85aa963 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/includes/sibling/include7.txt @@ -0,0 +1 @@ +In includes/sibling/include7.txt diff --git a/test/test_parsers/test_rst/test_directives/raw1.txt b/test/test_parsers/test_rst/test_directives/raw1.txt new file mode 100644 index 000000000..7ea03651b --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/raw1.txt @@ -0,0 +1 @@ +<p>This file is used by <tt>test_raw.py</tt>.</p> diff --git a/test/test_parsers/test_rst/test_directives/test_admonitions.py b/test/test_parsers/test_rst/test_directives/test_admonitions.py new file mode 100755 index 000000000..aaa5aa8d3 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_admonitions.py @@ -0,0 +1,184 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for admonitions.py directives. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['admonitions'] = [ +["""\ +.. Attention:: Directives at large. + +.. Note:: This is a note. + +.. Tip:: 15% if the + service is good. + +.. Hint:: It's bigger than a bread box. + +- .. WARNING:: Strong prose may provoke extreme mental exertion. + Reader discretion is strongly advised. +- .. Error:: Does not compute. + +.. Caution:: + + Don't take any wooden nickels. + +.. DANGER:: Mad scientist at work! + +.. Important:: + - Wash behind your ears. + - Clean up your room. + - Call your mother. + - Back up your data. +""", +"""\ +<document source="test data"> + <attention> + <paragraph> + Directives at large. + <note> + <paragraph> + This is a note. + <tip> + <paragraph> + 15% if the + service is good. + <hint> + <paragraph> + It's bigger than a bread box. + <bullet_list bullet="-"> + <list_item> + <warning> + <paragraph> + Strong prose may provoke extreme mental exertion. + Reader discretion is strongly advised. + <list_item> + <error> + <paragraph> + Does not compute. + <caution> + <paragraph> + Don't take any wooden nickels. + <danger> + <paragraph> + Mad scientist at work! + <important> + <bullet_list bullet="-"> + <list_item> + <paragraph> + Wash behind your ears. + <list_item> + <paragraph> + Clean up your room. + <list_item> + <paragraph> + Call your mother. + <list_item> + <paragraph> + Back up your data. +"""], +["""\ +.. note:: One-line notes. +.. note:: One after the other. +.. note:: No blank lines in-between. +""", +"""\ +<document source="test data"> + <note> + <paragraph> + One-line notes. + <note> + <paragraph> + One after the other. + <note> + <paragraph> + No blank lines in-between. +"""], +["""\ +.. note:: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + The "note" admonition is empty; content required. + <literal_block xml:space="preserve"> + .. note:: +"""], +["""\ +.. admonition:: Admonition + + This is a generic admonition. +""", +"""\ +<document source="test data"> + <admonition classes="admonition-admonition"> + <title> + Admonition + <paragraph> + This is a generic admonition. +"""], +["""\ +.. admonition:: And, by the way... + + You can make up your own admonition too. +""", +"""\ +<document source="test data"> + <admonition classes="admonition-and-by-the-way"> + <title> + And, by the way... + <paragraph> + You can make up your own admonition too. +"""], +["""\ +.. admonition:: Admonition + :class: emergency + + Test the "class" override. +""", +"""\ +<document source="test data"> + <admonition classes="emergency"> + <title> + Admonition + <paragraph> + Test the "class" override. +"""], +["""\ +.. admonition:: + + Generic admonitions require a title. +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "admonition" directive: + 1 argument(s) required, 0 supplied. + <literal_block xml:space="preserve"> + .. admonition:: + + Generic admonitions require a title. +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_compound.py b/test/test_parsers/test_rst/test_directives/test_compound.py new file mode 100755 index 000000000..eea4dd53b --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_compound.py @@ -0,0 +1,106 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the 'compound' directive from body.py. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['compound'] = [ +["""\ +.. compound:: + + Compound paragraphs are single logical paragraphs + which contain embedded + + * lists + * tables + * literal blocks + * and other body elements + + and are split into multiple physical paragraphs. +""", +"""\ +<document source="test data"> + <compound> + <paragraph> + Compound paragraphs are single logical paragraphs + which contain embedded + <bullet_list bullet="*"> + <list_item> + <paragraph> + lists + <list_item> + <paragraph> + tables + <list_item> + <paragraph> + literal blocks + <list_item> + <paragraph> + and other body elements + <paragraph> + and are split into multiple physical paragraphs. +"""], +["""\ +.. compound:: + + This is an extremely interesting compound paragraph containing a + simple paragraph, a literal block with some useless log messages:: + + Connecting... OK + Transmitting data... OK + Disconnecting... OK + + and another simple paragraph which is actually just a continuation + of the first simple paragraph, with the literal block in between. +""", +"""\ +<document source="test data"> + <compound> + <paragraph> + This is an extremely interesting compound paragraph containing a + simple paragraph, a literal block with some useless log messages: + <literal_block xml:space="preserve"> + Connecting... OK + Transmitting data... OK + Disconnecting... OK + <paragraph> + and another simple paragraph which is actually just a continuation + of the first simple paragraph, with the literal block in between. +"""], +["""\ +.. compound:: arg1 arg2 + + text +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "compound" directive: + no arguments permitted; blank line required before content block. + <literal_block xml:space="preserve"> + .. compound:: arg1 arg2 + \n\ + text +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_container.py b/test/test_parsers/test_rst/test_directives/test_container.py new file mode 100755 index 000000000..3c740611a --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_container.py @@ -0,0 +1,76 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the 'container' directive from body.py. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['container'] = [ +["""\ +.. container:: + + "container" is a generic element, an extension mechanism for + users & applications. + + Containers may contain arbitrary body elements. +""", +"""\ +<document source="test data"> + <container> + <paragraph> + "container" is a generic element, an extension mechanism for + users & applications. + <paragraph> + Containers may contain arbitrary body elements. +"""], +["""\ +.. container:: custom + + Some text. +""", +"""\ +<document source="test data"> + <container classes="custom"> + <paragraph> + Some text. +"""], +["""\ +.. container:: one two three + four + + Multiple classes. + + Multi-line argument. + + Multiple paragraphs in the container. +""", +"""\ +<document source="test data"> + <container classes="one two three four"> + <paragraph> + Multiple classes. + <paragraph> + Multi-line argument. + <paragraph> + Multiple paragraphs in the container. +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_contents.py b/test/test_parsers/test_rst/test_directives/test_contents.py new file mode 100755 index 000000000..cb7bbec0f --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_contents.py @@ -0,0 +1,241 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for parts.py contents directive. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['contents'] = [ +["""\ +.. contents:: +""", +"""\ +<document source="test data"> + <topic classes="contents" ids="contents" names="contents"> + <title> + Contents + <pending> + .. internal attributes: + .transform: docutils.transforms.parts.Contents + .details: +"""], +["""\ +.. contents:: Table of Contents +""", +"""\ +<document source="test data"> + <topic classes="contents" ids="table-of-contents" names="table\ of\ contents"> + <title> + Table of Contents + <pending> + .. internal attributes: + .transform: docutils.transforms.parts.Contents + .details: +"""], +["""\ +.. contents:: + Table of Contents +""", +"""\ +<document source="test data"> + <topic classes="contents" ids="table-of-contents" names="table\ of\ contents"> + <title> + Table of Contents + <pending> + .. internal attributes: + .transform: docutils.transforms.parts.Contents + .details: +"""], +["""\ +.. contents:: Table + of + Contents +""", +"""\ +<document source="test data"> + <topic classes="contents" ids="table-of-contents" names="table\ of\ contents"> + <title> + Table + of + Contents + <pending> + .. internal attributes: + .transform: docutils.transforms.parts.Contents + .details: +"""], +["""\ +.. contents:: *Table* of ``Contents`` +""", +"""\ +<document source="test data"> + <topic classes="contents" ids="table-of-contents" names="table\ of\ contents"> + <title> + <emphasis> + Table + of + <literal> + Contents + <pending> + .. internal attributes: + .transform: docutils.transforms.parts.Contents + .details: +"""], +["""\ +.. contents:: + :depth: 2 + :local: +""", +"""\ +<document source="test data"> + <topic classes="contents local" ids="contents" names="contents"> + <pending> + .. internal attributes: + .transform: docutils.transforms.parts.Contents + .details: + depth: 2 + local: None +"""], +["""\ +.. contents:: + :local: arg +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "contents" directive: + invalid option value: (option: "local"; value: 'arg') + no argument is allowed; "arg" supplied. + <literal_block xml:space="preserve"> + .. contents:: + :local: arg +"""], +["""\ +.. contents:: Table of Contents + :local: + :depth: 2 + :backlinks: none +""", +"""\ +<document source="test data"> + <topic classes="contents local" ids="table-of-contents" names="table\ of\ contents"> + <title> + Table of Contents + <pending> + .. internal attributes: + .transform: docutils.transforms.parts.Contents + .details: + backlinks: None + depth: 2 + local: None +"""], +["""\ +.. contents:: + :depth: two +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "contents" directive: + invalid option value: (option: "depth"; value: 'two') + invalid literal for int(): two. + <literal_block xml:space="preserve"> + .. contents:: + :depth: two +"""], +["""\ +.. contents:: + :width: 2 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "contents" directive: + unknown option: "width". + <literal_block xml:space="preserve"> + .. contents:: + :width: 2 +"""], +["""\ +.. contents:: + :backlinks: no way! +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "contents" directive: + invalid option value: (option: "backlinks"; value: 'no way!') + "no way!" unknown; choose from "top", "entry", or "none". + <literal_block xml:space="preserve"> + .. contents:: + :backlinks: no way! +"""], +["""\ +.. contents:: + :backlinks: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "contents" directive: + invalid option value: (option: "backlinks"; value: None) + must supply an argument; choose from "top", "entry", or "none". + <literal_block xml:space="preserve"> + .. contents:: + :backlinks: +"""], +["""\ +* .. contents:: +""", +"""\ +<document source="test data"> + <bullet_list bullet="*"> + <list_item> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + The "contents" directive may not be used within topics or body elements. + <literal_block xml:space="preserve"> + .. contents:: +"""], +["""\ +.. sidebar:: containing contents + + .. contents:: +""", +"""\ +<document source="test data"> + <sidebar> + <title> + containing contents + <topic classes="contents" ids="contents" names="contents"> + <title> + Contents + <pending> + .. internal attributes: + .transform: docutils.transforms.parts.Contents + .details: +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_date.py b/test/test_parsers/test_rst/test_directives/test_date.py new file mode 100755 index 000000000..0364331b1 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_date.py @@ -0,0 +1,53 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the misc.py "date" directive. +""" + +from __init__ import DocutilsTestSupport +import time + + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['date'] = [ +["""\ +.. |date| date:: + +Today's date is |date|. +""", +"""\ +<document source="test data"> + <substitution_definition names="date"> + %s + <paragraph> + Today's date is \n\ + <substitution_reference refname="date"> + date + . +""" % time.strftime('%Y-%m-%d')], +["""\ +.. |date| date:: %a, %d %b %Y +""", +"""\ +<document source="test data"> + <substitution_definition names="date"> + %s +""" % time.strftime('%a, %d %b %Y')], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_decorations.py b/test/test_parsers/test_rst/test_directives/test_decorations.py new file mode 100755 index 000000000..c770c6a49 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_decorations.py @@ -0,0 +1,93 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the "header" & "footer" directives. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['headers'] = [ +["""\ +.. header:: a paragraph for the header +""", +"""\ +<document source="test data"> + <decoration> + <header> + <paragraph> + a paragraph for the header +"""], +["""\ +.. header:: +""", +"""\ +<document source="test data"> + <decoration> + <header> + <paragraph> + Problem with the "header" directive: no content supplied. + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Content block expected for the "header" directive; none found. + <literal_block xml:space="preserve"> + .. header:: +"""], +["""\ +.. header:: first part of the header +.. header:: second part of the header +""", +"""\ +<document source="test data"> + <decoration> + <header> + <paragraph> + first part of the header + <paragraph> + second part of the header +"""], +] + +totest['footers'] = [ +["""\ +.. footer:: a paragraph for the footer +""", +"""\ +<document source="test data"> + <decoration> + <footer> + <paragraph> + a paragraph for the footer +"""], +["""\ +.. footer:: even if a footer is declared first +.. header:: the header appears first +""", +"""\ +<document source="test data"> + <decoration> + <header> + <paragraph> + the header appears first + <footer> + <paragraph> + even if a footer is declared first +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_default_role.py b/test/test_parsers/test_rst/test_directives/test_default_role.py new file mode 100755 index 000000000..fc9343247 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_default_role.py @@ -0,0 +1,84 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for misc.py "default-role" directive. +""" + +from __init__ import DocutilsTestSupport + + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['default-role'] = [ +["""\ +.. default-role:: subscript + +This is a `subscript`. +""", +"""\ +<document source="test data"> + <paragraph> + This is a \n\ + <subscript> + subscript + . +"""], +["""\ +Must define a custom role before using it. + +.. default-role:: custom +""", +"""\ +<document source="test data"> + <paragraph> + Must define a custom role before using it. + <system_message level="1" line="3" source="test data" type="INFO"> + <paragraph> + No role entry for "custom" in module "docutils.parsers.rst.languages.en". + Trying "custom" as canonical role name. + <system_message level="3" line="3" source="test data" type="ERROR"> + <paragraph> + Unknown interpreted text role "custom". + <literal_block xml:space="preserve"> + .. default-role:: custom +"""], +["""\ +.. role:: custom +.. default-role:: custom + +This text uses the `default role`. + +.. default-role:: + +Returned the `default role` to its standard default. +""", +"""\ +<document source="test data"> + <paragraph> + This text uses the \n\ + <inline classes="custom"> + default role + . + <paragraph> + Returned the \n\ + <title_reference> + default role + to its standard default. +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_figures.py b/test/test_parsers/test_rst/test_directives/test_figures.py new file mode 100755 index 000000000..91fd91596 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_figures.py @@ -0,0 +1,294 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for images.py figure directives. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['figures'] = [ +["""\ +.. figure:: picture.png +""", +"""\ +<document source="test data"> + <figure> + <image uri="picture.png"> +"""], +["""\ +.. figure:: picture.png + + A picture with a caption. +""", +"""\ +<document source="test data"> + <figure> + <image uri="picture.png"> + <caption> + A picture with a caption. +"""], +["""\ +.. figure:: picture.png + + - A picture with an invalid caption. +""", +"""\ +<document source="test data"> + <figure> + <image uri="picture.png"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Figure caption must be a paragraph or empty comment. + <literal_block xml:space="preserve"> + .. figure:: picture.png + \n\ + - A picture with an invalid caption. +"""], +["""\ +.. figure:: picture.png + + .. + + A picture with a legend but no caption. +""", +"""\ +<document source="test data"> + <figure> + <image uri="picture.png"> + <legend> + <paragraph> + A picture with a legend but no caption. +"""], +["""\ +.. Figure:: picture.png + :height: 100 + :width: 200 + :scale: 50 + + A picture with image options and a caption. +""", +"""\ +<document source="test data"> + <figure> + <image height="100" scale="50" uri="picture.png" width="200"> + <caption> + A picture with image options and a caption. +"""], +["""\ +.. Figure:: picture.png + :height: 100 + :alt: alternate text + :width: 200 + :scale: 50 + :figwidth: 300 + :figclass: class1 class2 + + A picture with image options on individual lines, and this caption. +""", +"""\ +<document source="test data"> + <figure classes="class1 class2" width="300"> + <image alt="alternate text" height="100" scale="50" uri="picture.png" width="200"> + <caption> + A picture with image options on individual lines, and this caption. +"""], +["""\ +.. figure:: picture.png + :align: center + + A figure with explicit alignment. +""", +"""\ +<document source="test data"> + <figure align="center"> + <image uri="picture.png"> + <caption> + A figure with explicit alignment. +"""], +["""\ +.. figure:: picture.png + :align: top + + A figure with wrong alignment. +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "figure" directive: + invalid option value: (option: "align"; value: 'top') + "top" unknown; choose from "left", "center", or "right". + <literal_block xml:space="preserve"> + .. figure:: picture.png + :align: top + + A figure with wrong alignment. +"""], +["""\ +This figure lacks a caption. It may still have a +"Figure 1."-style caption appended in the output. + +.. figure:: picture.png +""", +"""\ +<document source="test data"> + <paragraph> + This figure lacks a caption. It may still have a + "Figure 1."-style caption appended in the output. + <figure> + <image uri="picture.png"> +"""], +["""\ +.. figure:: picture.png + + A picture with a caption and a legend. + + +-----------------------+-----------------------+ + | Symbol | Meaning | + +=======================+=======================+ + | .. image:: tent.png | Campground | + +-----------------------+-----------------------+ + | .. image:: waves.png | Lake | + +-----------------------+-----------------------+ + | .. image:: peak.png | Mountain | + +-----------------------+-----------------------+ +""", +"""\ +<document source="test data"> + <figure> + <image uri="picture.png"> + <caption> + A picture with a caption and a legend. + <legend> + <table> + <tgroup cols="2"> + <colspec colwidth="23"> + <colspec colwidth="23"> + <thead> + <row> + <entry> + <paragraph> + Symbol + <entry> + <paragraph> + Meaning + <tbody> + <row> + <entry> + <image uri="tent.png"> + <entry> + <paragraph> + Campground + <row> + <entry> + <image uri="waves.png"> + <entry> + <paragraph> + Lake + <row> + <entry> + <image uri="peak.png"> + <entry> + <paragraph> + Mountain +"""], +["""\ +.. figure:: picture.png + + .. + + A picture with a legend but no caption. + (The empty comment replaces the caption, which must + be a single paragraph.) +""", +"""\ +<document source="test data"> + <figure> + <image uri="picture.png"> + <legend> + <paragraph> + A picture with a legend but no caption. + (The empty comment replaces the caption, which must + be a single paragraph.) +"""], +["""\ +Testing for line-leaks: + +.. figure:: picture.png + + A picture with a caption. +.. figure:: picture.png + + A picture with a caption. +.. figure:: picture.png + + A picture with a caption. +.. figure:: picture.png +.. figure:: picture.png +.. figure:: picture.png +.. figure:: picture.png + + A picture with a caption. + +.. figure:: picture.png + +.. figure:: picture.png + + A picture with a caption. + +.. figure:: picture.png +""", +"""\ +<document source="test data"> + <paragraph> + Testing for line-leaks: + <figure> + <image uri="picture.png"> + <caption> + A picture with a caption. + <figure> + <image uri="picture.png"> + <caption> + A picture with a caption. + <figure> + <image uri="picture.png"> + <caption> + A picture with a caption. + <figure> + <image uri="picture.png"> + <figure> + <image uri="picture.png"> + <figure> + <image uri="picture.png"> + <figure> + <image uri="picture.png"> + <caption> + A picture with a caption. + <figure> + <image uri="picture.png"> + <figure> + <image uri="picture.png"> + <caption> + A picture with a caption. + <figure> + <image uri="picture.png"> +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_images.py b/test/test_parsers/test_rst/test_directives/test_images.py new file mode 100755 index 000000000..50f555ba1 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_images.py @@ -0,0 +1,413 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for images.py image directives. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['images'] = [ +["""\ +.. image:: picture.png +""", +"""\ +<document source="test data"> + <image uri="picture.png"> +"""], +["""\ +.. image:: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + 1 argument(s) required, 0 supplied. + <literal_block xml:space="preserve"> + .. image:: +"""], +["""\ +.. image:: one two three.png +""", +"""\ +<document source="test data"> + <image uri="onetwothree.png"> +"""], +["""\ +.. image:: picture.png + :height: 100 + :width: 200 + :scale: 50 +""", +"""\ +<document source="test data"> + <image height="100" scale="50" uri="picture.png" width="200"> +"""], +["""\ +.. image:: + picture.png + :height: 100 + :width: 200 + :scale: 50 +""", +"""\ +<document source="test data"> + <image height="100" scale="50" uri="picture.png" width="200"> +"""], +["""\ +.. image:: + :height: 100 + :width: 200 + :scale: 50 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + 1 argument(s) required, 0 supplied. + <literal_block xml:space="preserve"> + .. image:: + :height: 100 + :width: 200 + :scale: 50 +"""], +["""\ +.. image:: a/very/long/path/to/ + picture.png + :height: 100 + :width: 200 + :scale: 50 +""", +"""\ +<document source="test data"> + <image height="100" scale="50" uri="a/very/long/path/to/picture.png" width="200"> +"""], +["""\ +.. image:: picture.png + :width: 200px + :height: 100 em +""", +"""\ +<document source="test data"> + <image height="100em" uri="picture.png" width="200px"> +"""], +["""\ +.. image:: picture.png + :width: 50% + :height: 10mm +""", +"""\ +<document source="test data"> + <image height="10mm" uri="picture.png" width="50%"> +"""], +["""\ +.. image:: picture.png + :width: 50% + :height: 40% +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + 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" "". + <literal_block xml:space="preserve"> + .. image:: picture.png + :width: 50% + :height: 40% +"""], +["""\ +.. image:: picture.png + :height: 100 + :width: 200 + :scale: 50 + :alt: Alternate text for the picture +""", +"""\ +<document source="test data"> + <image alt="Alternate text for the picture" height="100" scale="50" uri="picture.png" width="200"> +"""], +["""\ +.. image:: picture.png + :scale: - 50 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option value: (option: "scale"; value: '- 50') + negative value; must be positive or zero. + <literal_block xml:space="preserve"> + .. image:: picture.png + :scale: - 50 +"""], +["""\ +.. image:: picture.png + :scale: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option value: (option: "scale"; value: None) + %s. + <literal_block xml:space="preserve"> + .. image:: picture.png + :scale: +""" % DocutilsTestSupport.exception_data('int(None)')[1][0]], +["""\ +.. image:: picture.png + :scale 50 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option block. + <literal_block xml:space="preserve"> + .. image:: picture.png + :scale 50 +"""], +["""\ +.. image:: picture.png + scale: 50 +""", +"""\ +<document source="test data"> + <image uri="picture.pngscale:50"> +"""], +["""\ +.. image:: picture.png + :: 50 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option block. + <literal_block xml:space="preserve"> + .. image:: picture.png + :: 50 +"""], +["""\ +.. image:: picture.png + :sale: 50 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + unknown option: "sale". + <literal_block xml:space="preserve"> + .. image:: picture.png + :sale: 50 +"""], +["""\ +.. image:: picture.png + :scale is: 50 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option data: extension option field name may not contain multiple words. + <literal_block xml:space="preserve"> + .. image:: picture.png + :scale is: 50 +"""], +["""\ +.. image:: picture.png + :scale: fifty +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option value: (option: "scale"; value: 'fifty') + invalid literal for int(): fifty. + <literal_block xml:space="preserve"> + .. image:: picture.png + :scale: fifty +"""], +["""\ +.. image:: picture.png + :scale: 50 + :scale: 50 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option data: duplicate option "scale". + <literal_block xml:space="preserve"> + .. image:: picture.png + :scale: 50 + :scale: 50 +"""], +["""\ +.. image:: picture.png + :alt: + +(Empty "alt" option.) +""", +"""\ +<document source="test data"> + <image alt="" uri="picture.png"> + <paragraph> + (Empty "alt" option.) +"""], +["""\ +.. image:: picture.png + :target: bigpicture.png +""", +"""\ +<document source="test data"> + <reference refuri="bigpicture.png"> + <image uri="picture.png"> +"""], +["""\ +.. image:: picture.png + :target: indirect_ +""", +"""\ +<document source="test data"> + <reference name="indirect" refname="indirect"> + <image uri="picture.png"> +"""], +["""\ +.. image:: picture.png + :target: a/multi/ + line/uri + +.. image:: picture.png + :target: `a multi line + internal reference`_ +""", +"""\ +<document source="test data"> + <reference refuri="a/multi/line/uri"> + <image uri="picture.png"> + <reference name="a multi line internal reference" refname="a multi line internal reference"> + <image uri="picture.png"> +"""], +["""\ +.. image:: picture.png + :target: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option value: (option: "target"; value: None) + argument required but none supplied. + <literal_block xml:space="preserve"> + .. image:: picture.png + :target: +"""], +["""\ +.. image:: picture.png + :align: left +""", +"""\ +<document source="test data"> + <image align="left" uri="picture.png"> +"""], +["""\ +.. image:: picture.png + :align: top +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: "top" is not a valid value for the "align" option. Valid values for "align" are: "left", "center", "right". + <literal_block xml:space="preserve"> + .. image:: picture.png + :align: top +"""], +["""\ +.. |img| image:: picture.png + :align: top +""", +"""\ +<document source="test data"> + <substitution_definition names="img"> + <image align="top" alt="img" uri="picture.png"> +"""], +["""\ +.. |img| image:: picture.png + :align: left +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + 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". + <literal_block xml:space="preserve"> + image:: picture.png + :align: left + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Substitution definition "img" empty or invalid. + <literal_block xml:space="preserve"> + .. |img| image:: picture.png + :align: left +"""], +[u"""\ +.. image:: picture.png + :align: \xe4 +""", +u"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "image" directive: + invalid option value: (option: "align"; value: u\'\\xe4\') + "\xe4" unknown; choose from "top", "middle", "bottom", "left", "center", or "right". + <literal_block xml:space="preserve"> + .. image:: picture.png + :align: \xe4 +"""], +[""" +.. image:: test.png + :target: Uppercase_ + +.. _Uppercase: http://docutils.sourceforge.net/ +""", +"""\ +<document source="test data"> + <reference name="Uppercase" refname="uppercase"> + <image uri="test.png"> + <target ids="uppercase" names="uppercase" refuri="http://docutils.sourceforge.net/"> +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_include.py b/test/test_parsers/test_rst/test_directives/test_include.py new file mode 100755 index 000000000..c9b5f7378 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_include.py @@ -0,0 +1,412 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for misc.py "include" directive. +""" + +import os.path +import sys +from __init__ import DocutilsTestSupport +from docutils.parsers.rst import states + + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +mydir = 'test_parsers/test_rst/test_directives/' +include1 = os.path.join(mydir, 'include1.txt') +include1rel = DocutilsTestSupport.utils.relative_path(None, include1) +include2 = os.path.join(mydir, 'include2.txt') +include3 = os.path.join(mydir, 'include3.txt') +include8 = os.path.join(mydir, 'include8.txt') +include10 = os.path.join(mydir, 'include10.txt') +include10rel = DocutilsTestSupport.utils.relative_path(None, include10) +include11 = os.path.join(mydir, 'include 11.txt') +include11rel = DocutilsTestSupport.utils.relative_path(None, include11) +utf_16_file = os.path.join(mydir, 'utf-16.csv') +utf_16_file_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_file) +nonexistent = os.path.join(os.path.dirname(states.__file__), + 'include', 'nonexistent') +nonexistent_rel = DocutilsTestSupport.utils.relative_path( + os.path.join(DocutilsTestSupport.testroot, 'dummy'), nonexistent) + +totest = {} + +totest['include'] = [ +["""\ +Include Test +============ + +.. include:: %s + +A paragraph. +""" % include1, +"""\ +<document source="test data"> + <section ids="include-test" names="include\ test"> + <title> + Include Test + <section ids="inclusion-1" names="inclusion\ 1"> + <title> + Inclusion 1 + <paragraph> + This file is used by \n\ + <literal> + test_include.py + . + <paragraph> + A paragraph. +"""], +["""\ +Include Test +============ + +.. include:: %s + :literal: + +A paragraph. +""" % include1, +"""\ +<document source="test data"> + <section ids="include-test" names="include\ test"> + <title> + Include Test + <literal_block source="%s" xml:space="preserve"> + Inclusion 1 + ----------- + \n\ + This file is used by ``test_include.py``. + <paragraph> + A paragraph. +""" % include1rel], +["""\ +Let's test the parse context. + + This paragraph is in a block quote. + + .. include:: %s + +The included paragraphs should also be in the block quote. +""" % include2, +"""\ +<document source="test data"> + <paragraph> + Let's test the parse context. + <block_quote> + <paragraph> + This paragraph is in a block quote. + <paragraph> + Here are some paragraphs + that can appear at any level. + <paragraph> + This file (include2.txt) is used by + <literal> + test_include.py + . + <paragraph> + The included paragraphs should also be in the block quote. +"""], +["""\ +Include Test +============ + +.. include:: nonexistent.txt + +A paragraph. +""", +"""\ +<document source="test data"> + <section ids="include-test" names="include\ test"> + <title> + Include Test + <system_message level="4" line="4" source="test data" type="SEVERE"> + <paragraph> + Problems with "include" directive path: + IOError: [Errno 2] No such file or directory: 'nonexistent.txt'. + <literal_block xml:space="preserve"> + .. include:: nonexistent.txt + <paragraph> + A paragraph. +"""], +["""\ +Include Test +============ + +.. include:: %s + +.. include:: %s + +A paragraph. +""" % (include1, include1), +"""\ +<document source="test data"> + <section ids="include-test" names="include\ test"> + <title> + Include Test + <section dupnames="inclusion\ 1" ids="inclusion-1"> + <title> + Inclusion 1 + <paragraph> + This file is used by + <literal> + test_include.py + . + <section dupnames="inclusion\ 1" ids="id1"> + <title> + Inclusion 1 + <system_message backrefs="id1" level="1" line="2" source="%s" type="INFO"> + <paragraph> + Duplicate implicit target name: "inclusion 1". + <paragraph> + This file is used by + <literal> + test_include.py + . + <paragraph> + A paragraph. +""" % include1rel], +["""\ +Include Test +============ + +.. include:: %s + +---------- + +.. include:: %s + +A paragraph. +""" % (include1, include1), +"""\ +<document source="test data"> + <section ids="include-test" names="include\ test"> + <title> + Include Test + <section dupnames="inclusion\ 1" ids="inclusion-1"> + <title> + Inclusion 1 + <paragraph> + This file is used by \n\ + <literal> + test_include.py + . + <transition> + <section dupnames="inclusion\ 1" ids="id1"> + <title> + Inclusion 1 + <system_message backrefs="id1" level="1" line="2" source="%s" type="INFO"> + <paragraph> + Duplicate implicit target name: "inclusion 1". + <paragraph> + This file is used by \n\ + <literal> + test_include.py + . + <paragraph> + A paragraph. +""" % include1rel], +["""\ +In test data + +.. include:: %s +""" % include3, +"""\ +<document source="test data"> + <paragraph> + In test data + <paragraph> + In include3.txt + <paragraph> + In includes/include4.txt + <paragraph> + In includes/include5.txt + <paragraph> + In includes/more/include6.txt + <paragraph> + In includes/sibling/include7.txt +"""], +["""\ +In test data + +Section +======= + +(Section contents in nested parse; slice of input_lines ViewList.) + +.. include:: %s +""" % include3, +"""\ +<document source="test data"> + <paragraph> + In test data + <section ids="section" names="section"> + <title> + Section + <paragraph> + (Section contents in nested parse; slice of input_lines ViewList.) + <paragraph> + In include3.txt + <paragraph> + In includes/include4.txt + <paragraph> + In includes/include5.txt + <paragraph> + In includes/more/include6.txt + <paragraph> + In includes/sibling/include7.txt +"""], +["""\ +Testing relative includes: + +.. include:: %s +""" % include8, +"""\ +<document source="test data"> + <paragraph> + Testing relative includes: + <paragraph> + In include8.txt + <paragraph> + In ../includes/include9.txt. + <paragraph> + Here are some paragraphs + that can appear at any level. + <paragraph> + This file (include2.txt) is used by + <literal> + test_include.py + . +"""], +["""\ +Encoding: + +.. include:: %s + :encoding: utf-16 +""" % utf_16_file_rel, +u"""\ +<document source="test data"> + <paragraph> + Encoding: + <paragraph> + "Treat", "Quantity", "Description" + "Albatr\xb0\xdf", 2.99, "\xa1On a \\u03c3\\u03c4\\u03b9\\u03ba!" + "Crunchy Frog", 1.49, "If we took the b\xf6nes out, it wouldn\\u2019t be + crunchy, now would it?" + "Gannet Ripple", 1.99, "\xbfOn a \\u03c3\\u03c4\\u03b9\\u03ba?" +"""], +["""\ +Include file is UTF-16-encoded, and is not valid ASCII. + +.. include:: %s + :encoding: ascii +""" % utf_16_file_rel, +"""\ +<document source="test data"> + <paragraph> + Include file is UTF-16-encoded, and is not valid ASCII. + <system_message level="4" line="3" source="test data" type="SEVERE"> + <paragraph> + Problem with "include" directive: + UnicodeError: Unable to decode input data. Tried the following encodings: 'ascii'. + (UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 0: ordinal not in range(128)) + <literal_block xml:space="preserve"> + .. include:: %s + :encoding: ascii +""" % utf_16_file_rel], +# @@@ BUG with errors reported with incorrect "source" & "line": +# ["""\ +# Testing bad charent includes: +# +# .. include:: %s +# """ % include10, +# """\ +# <document source="test data"> +# <paragraph> +# Testing bad charent includes: +# <system_message level="3" line="1" source="%s" type="ERROR"> +# <paragraph> +# Invalid character code: 0xFFFFFFFFF +# int() literal too large: FFFFFFFFF +# <literal_block xml:space="preserve"> +# unicode:: 0xFFFFFFFFF +# <system_message level="2" line="1" source="%s" type="WARNING"> +# <paragraph> +# Substitution definition "bad" empty or invalid. +# <literal_block xml:space="preserve"> +# .. |bad| unicode:: 0xFFFFFFFFF +# """ % (include10rel, include10rel)], +["""\ +Include file with whitespace in the path: + +.. include:: %s +""" % include11rel, +"""\ +<document source="test data"> + <paragraph> + Include file with whitespace in the path: + <paragraph> + some text +"""], +["""\ +Standard include data file: + +.. include:: <isogrk4.txt> +""", +"""\ +<document source="test data"> + <paragraph> + Standard include data file: + <comment xml:space="preserve"> + This data file has been placed in the public domain. + <comment xml:space="preserve"> + Derived from the Unicode character mappings available from + <http://www.w3.org/2003/entities/xml/>. + Processed by unicode2rstsubs.py, part of Docutils: + <http://docutils.sourceforge.net>. + <substitution_definition names="b.Gammad"> + \\u03dc + <substitution_definition names="b.gammad"> + \\u03dd +"""], +["""\ +Nonexistent standard include data file: + +.. include:: <nonexistent> +""", +"""\ +<document source="test data"> + <paragraph> + Nonexistent standard include data file: + <system_message level="4" line="3" source="test data" type="SEVERE"> + <paragraph> + Problems with "include" directive path: + IOError: [Errno 2] No such file or directory: '%s'. + <literal_block xml:space="preserve"> + .. include:: <nonexistent> +""" % nonexistent_rel], +] + + +# Skip tests whose output contains "UnicodeDecodeError" if we are not +# using Python 2.3 or higher. +if sys.version_info < (2, 3): + for i in range(len(totest['include'])): + if totest['include'][i][1].find('UnicodeDecodeError') != -1: + del totest['include'][i] + print ("Test totest['include'][%s] skipped; " + "Python 2.3+ required for expected output." % i) + # Assume we have only one of these tests. + break + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_line_blocks.py b/test/test_parsers/test_rst/test_directives/test_line_blocks.py new file mode 100755 index 000000000..131ceaa05 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_line_blocks.py @@ -0,0 +1,81 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the body.py 'line-block' directive. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['line_blocks'] = [ +["""\ +.. line-block:: + + This is a line block. + Newlines are *preserved*. + As is initial whitespace. +""", +"""\ +<document source="test data"> + <line_block> + <line> + This is a line block. + <line> + Newlines are \n\ + <emphasis> + preserved + . + <line_block> + <line> + As is initial whitespace. +"""], +["""\ +.. line-block:: + + Inline markup *may not span + multiple lines* of a line block. +""", +"""\ +<document source="test data"> + <line_block> + <line> + Inline markup \n\ + <problematic ids="id2" refid="id1"> + * + may not span + <line_block> + <line> + multiple lines* of a line block. + <system_message backrefs="id2" ids="id1" level="2" line="3" source="test data" type="WARNING"> + <paragraph> + Inline emphasis start-string without end-string. +"""], +["""\ +.. line-block:: +""", +"""\ +<document source="test data"> + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Content block expected for the "line-block" directive; none found. + <literal_block xml:space="preserve"> + .. line-block:: +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_meta.py b/test/test_parsers/test_rst/test_directives/test_meta.py new file mode 100755 index 000000000..7c8b34002 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_meta.py @@ -0,0 +1,232 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for html meta directives. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['meta'] = [ +["""\ +.. meta:: + :description: The reStructuredText plaintext markup language + :keywords: plaintext,markup language +""", +"""\ +<document source="test data"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="The reStructuredText plaintext markup language" name="description"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="plaintext,markup language" name="keywords"> +"""], +["""\ +.. meta:: + :description lang=en: An amusing story + :description lang=fr: Un histoire amusant +""", +"""\ +<document source="test data"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="An amusing story" lang="en" name="description"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="Un histoire amusant" lang="fr" name="description"> +"""], +["""\ +.. meta:: + :http-equiv=Content-Type: text/html; charset=ISO-8859-1 +""", +"""\ +<document source="test data"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> +"""], +["""\ +.. meta:: + :name: content + over multiple lines +""", +"""\ +<document source="test data"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="content over multiple lines" name="name"> +"""], +["""\ +Paragraph + +.. meta:: + :name: content +""", +"""\ +<document source="test data"> + <paragraph> + Paragraph + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="content" name="name"> +"""], +["""\ +.. meta:: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Empty meta directive. + <literal_block xml:space="preserve"> + .. meta:: +"""], +["""\ +.. meta:: + :empty: +""", +"""\ +<document source="test data"> + <system_message level="1" line="2" source="test data" type="INFO"> + <paragraph> + No content for meta tag "empty". + <literal_block xml:space="preserve"> + :empty: +"""], +["""\ +.. meta:: + not a field list +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Invalid meta directive. + <literal_block xml:space="preserve"> + .. meta:: + not a field list +"""], +["""\ +.. meta:: + :name: content + not a field + :name: content +""", +"""\ +<document source="test data"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="content" name="name"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Invalid meta directive. + <literal_block xml:space="preserve"> + .. meta:: + :name: content + not a field + :name: content +"""], +["""\ +.. meta:: + :name: content + :name: content + not a field +""", +"""\ +<document source="test data"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="content" name="name"> + <pending> + .. internal attributes: + .transform: docutils.transforms.components.Filter + .details: + component: 'writer' + format: 'html' + nodes: + <meta content="content" name="name"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Invalid meta directive. + <literal_block xml:space="preserve"> + .. meta:: + :name: content + :name: content + not a field +"""], +["""\ +.. meta:: + :name notattval: content +""", +"""\ +<document source="test data"> + <system_message level="3" line="2" source="test data" type="ERROR"> + <paragraph> + Error parsing meta tag attribute "notattval": missing "=". + <literal_block xml:space="preserve"> + :name notattval: content +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_raw.py b/test/test_parsers/test_rst/test_directives/test_raw.py new file mode 100755 index 000000000..9e1a17974 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_raw.py @@ -0,0 +1,154 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for misc.py "raw" directive. +""" + +import os.path +import sys +from __init__ import DocutilsTestSupport + + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +mydir = 'test_parsers/test_rst/test_directives/' +raw1 = os.path.join(mydir, 'raw1.txt') +utf_16_file = os.path.join(mydir, 'utf-16.csv') +utf_16_file_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_file) + +totest = {} + +totest['raw'] = [ +["""\ +.. raw:: html + + <span>This is some plain old raw text.</span> +""", +"""\ +<document source="test data"> + <raw format="html" xml:space="preserve"> + <span>This is some plain old raw text.</span> +"""], +["""\ +.. raw:: html + :file: %s +""" % raw1, +"""\ +<document source="test data"> + <raw format="html" source="%s" xml:space="preserve"> + <p>This file is used by <tt>test_raw.py</tt>.</p> +""" % DocutilsTestSupport.utils.relative_path(None, raw1)], +["""\ +.. raw:: html + :file: rawfile.html + :url: http://example.org/ +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + The "file" and "url" options may not be simultaneously specified for the "raw" directive. + <literal_block xml:space="preserve"> + .. raw:: html + :file: rawfile.html + :url: http://example.org/ +"""], +["""\ +.. raw:: html + :file: rawfile.html + + <p>Can't have both content and file attribute.</p> +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + "raw" directive may not both specify an external file and have content. + <literal_block xml:space="preserve"> + .. raw:: html + :file: rawfile.html + + <p>Can't have both content and file attribute.</p> +"""], +[r""" +.. raw:: latex html + + \[ \sum_{n=1}^\infty \frac{1}{n} \text{ etc.} \] +""", +"""\ +<document source="test data"> + <raw format="latex html" xml:space="preserve"> + \\[ \\sum_{n=1}^\\infty \\frac{1}{n} \\text{ etc.} \\] +"""], +["""\ +.. raw:: html + :file: %s + :encoding: utf-16 +""" % utf_16_file_rel, +"""\ +<document source="test data"> + <raw format="html" source="%s" xml:space="preserve"> + "Treat", "Quantity", "Description" + "Albatr\xb0\xdf", 2.99, "\xa1On a \\u03c3\\u03c4\\u03b9\\u03ba!" + "Crunchy Frog", 1.49, "If we took the b\xf6nes out, it wouldn\\u2019t be + crunchy, now would it?" + "Gannet Ripple", 1.99, "\xbfOn a \\u03c3\\u03c4\\u03b9\\u03ba?" +""" % utf_16_file_rel], +["""\ +Raw input file is UTF-16-encoded, and is not valid ASCII. + +.. raw:: html + :file: %s + :encoding: ascii +""" % utf_16_file_rel, +"""\ +<document source="test data"> + <paragraph> + Raw input file is UTF-16-encoded, and is not valid ASCII. + <system_message level="4" line="3" source="test data" type="SEVERE"> + <paragraph> + Problem with "raw" directive: + UnicodeError: Unable to decode input data. Tried the following encodings: \'ascii\'. + (UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 0: ordinal not in range(128)) + <literal_block xml:space="preserve"> + .. raw:: html + :file: %s + :encoding: ascii +""" % utf_16_file_rel], +["""\ +.. raw:: html + :encoding: utf-8 + + Should the parser complain becau\xdfe there is no :file:? BUG? +""", +"""\ +<document source="test data"> + <raw format="html" xml:space="preserve"> + Should the parser complain becau\xdfe there is no :file:? BUG? +"""], +] + +# Skip tests whose output contains "UnicodeDecodeError" if we are not +# using Python 2.3 or higher. +if sys.version_info < (2, 3): + for i in range(len(totest['raw'])): + if totest['raw'][i][1].find('UnicodeDecodeError') != -1: + del totest['raw'][i] + print ("Test totest['raw'][%s] skipped; " + "Python 2.3+ required for expected output." % i) + # Assume we have only one of these tests. + break + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_replace.py b/test/test_parsers/test_rst/test_directives/test_replace.py new file mode 100755 index 000000000..f5fd2495b --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_replace.py @@ -0,0 +1,135 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for misc.py "replace" directive. +""" + +from __init__ import DocutilsTestSupport + + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['replace'] = [ +["""\ +Test the |name| directive. + +.. |name| replace:: "**replace**" +""", +"""\ +<document source="test data"> + <paragraph> + Test the \n\ + <substitution_reference refname="name"> + name + directive. + <substitution_definition names="name"> + " + <strong> + replace + " +"""], +["""\ +.. |name| replace:: paragraph 1 + + paragraph 2 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "replace" directive: may contain a single paragraph only. + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Substitution definition "name" empty or invalid. + <literal_block xml:space="preserve"> + .. |name| replace:: paragraph 1 + + paragraph 2 +"""], +["""\ +.. |name| replace:: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + The "replace" directive is empty; content required. + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Substitution definition "name" empty or invalid. + <literal_block xml:space="preserve"> + .. |name| replace:: +"""], +["""\ +.. |Python| replace:: Python, *the* best language around + +.. _Python: http://www.python.org/ + +I recommend you try |Python|_. +""", +"""\ +<document source="test data"> + <substitution_definition names="Python"> + Python, + <emphasis> + the + best language around + <target ids="python" names="python" refuri="http://www.python.org/"> + <paragraph> + I recommend you try + <reference refname="python"> + <substitution_reference refname="Python"> + Python + . +"""], +["""\ +.. |name| replace:: *error in **inline ``markup +""", +"""\ +<document source="test data"> + <system_message ids="id1" level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Inline emphasis start-string without end-string. + <system_message ids="id3" level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Inline strong start-string without end-string. + <system_message ids="id5" level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Inline literal start-string without end-string. + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "replace" directive: may contain a single paragraph only. + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Substitution definition "name" empty or invalid. + <literal_block xml:space="preserve"> + .. |name| replace:: *error in **inline ``markup +"""], +["""\ +.. replace:: not valid outside of a substitution definition +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Invalid context: the "replace" directive can only be used within a substitution definition. + <literal_block xml:space="preserve"> + .. replace:: not valid outside of a substitution definition +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_role.py b/test/test_parsers/test_rst/test_directives/test_role.py new file mode 100755 index 000000000..0cd10c967 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_role.py @@ -0,0 +1,230 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for misc.py "role" directive. +""" + +from __init__ import DocutilsTestSupport + + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['role'] = [ +["""\ +.. role:: custom +.. role:: special + +:custom:`interpreted` and :special:`interpreted` +""", +"""\ +<document source="test data"> + <paragraph> + <inline classes="custom"> + interpreted + and \n\ + <inline classes="special"> + interpreted +"""], +["""\ +.. role:: custom + :class: custom-class +.. role:: special + :class: special-class + +:custom:`interpreted` and :special:`interpreted` +""", +"""\ +<document source="test data"> + <paragraph> + <inline classes="custom-class"> + interpreted + and \n\ + <inline classes="special-class"> + interpreted +"""], +["""\ +Must define :custom:`interpreted` before using it. + +.. role:: custom + +Now that it's defined, :custom:`interpreted` works. +""", +"""\ +<document source="test data"> + <paragraph> + Must define + <problematic ids="id2" refid="id1"> + :custom:`interpreted` + before using it. + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + No role entry for "custom" in module "docutils.parsers.rst.languages.en". + Trying "custom" as canonical role name. + <system_message backrefs="id2" ids="id1" level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Unknown interpreted text role "custom". + <paragraph> + Now that it's defined, \n\ + <inline classes="custom"> + interpreted + works. +"""], +["""\ +.. role:: custom(emphasis) + +:custom:`text` +""", +"""\ +<document source="test data"> + <paragraph> + <emphasis classes="custom"> + text +"""], +["""\ +.. role:: custom ( emphasis ) + +:custom:`text` +""", +"""\ +<document source="test data"> + <paragraph> + <emphasis classes="custom"> + text +"""], +["""\ +.. role:: custom(emphasis) + :class: special + +:custom:`text` +""", +"""\ +<document source="test data"> + <paragraph> + <emphasis classes="special"> + text +"""], +["""\ +.. role:: custom(unknown-role) +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + No role entry for "unknown-role" in module "docutils.parsers.rst.languages.en". + Trying "unknown-role" as canonical role name. + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Unknown interpreted text role "unknown-role". + <literal_block xml:space="preserve"> + .. role:: custom(unknown-role) +"""], +["""\ +.. role:: custom + :class: 1 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "role" directive: + invalid option value: (option: "class"; value: '1') + cannot make "1" into a class name. + <literal_block xml:space="preserve"> + .. role:: custom + :class: 1 +"""], +["""\ +.. role:: 1 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Invalid argument for "role" directive: + cannot make "1" into a class name. + <literal_block xml:space="preserve"> + .. role:: 1 +"""], +["""\ +Test +---- + +.. role:: fileref(emphasis) + +Testing a :fileref:`role` in a nested parse. +""", +"""\ +<document source="test data"> + <section ids="test" names="test"> + <title> + Test + <paragraph> + Testing a \n\ + <emphasis classes="fileref"> + role + in a nested parse. +"""], +] + +totest['raw_role'] = [ +["""\ +.. role:: html(raw) + :format: html + +Here's some :html:`<i>raw HTML data</i>`. +""", +"""\ +<document source="test data"> + <paragraph> + Here's some \n\ + <raw classes="html" format="html" xml:space="preserve"> + <i>raw HTML data</i> + . +"""], +["""\ +.. role:: itex(raw) + :format: latex html + +Here's some itex markup: :itex:`$x^\\infty$`. +""", +"""\ +<document source="test data"> + <paragraph> + Here's some itex markup: \n\ + <raw classes="itex" format="latex html" xml:space="preserve"> + $x^\\infty$ + . +"""], +["""\ +Can't use the :raw:`role` directly. +""", +"""\ +<document source="test data"> + <paragraph> + Can't use the \n\ + <problematic ids="id2" refid="id1"> + :raw:`role` + directly. + <system_message backrefs="id2" ids="id1" level="3" line="1" source="test data" type="ERROR"> + <paragraph> + No format (Writer name) is associated with this role: "raw". + The "raw" role cannot be used directly. + Instead, use the "role" directive to create a new role with an associated format. +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_rubrics.py b/test/test_parsers/test_rst/test_directives/test_rubrics.py new file mode 100755 index 000000000..271802736 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_rubrics.py @@ -0,0 +1,74 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the "rubric" directive. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['rubrics'] = [ +["""\ +.. rubric:: This is a rubric +""", +"""\ +<document source="test data"> + <rubric> + This is a rubric +"""], +["""\ +.. rubric:: +.. rubric:: A rubric has no content + + Invalid content +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "rubric" directive: + 1 argument(s) required, 0 supplied. + <literal_block xml:space="preserve"> + .. rubric:: + <system_message level="3" line="2" source="test data" type="ERROR"> + <paragraph> + Error in "rubric" directive: + no content permitted. + <literal_block xml:space="preserve"> + .. rubric:: A rubric has no content + \n\ + Invalid content +"""], +["""\ +.. rubric:: A rubric followed by a block quote +.. + + Block quote +""", +"""\ +<document source="test data"> + <rubric> + A rubric followed by a block quote + <comment xml:space="preserve"> + <block_quote> + <paragraph> + Block quote +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_sidebars.py b/test/test_parsers/test_rst/test_directives/test_sidebars.py new file mode 100755 index 000000000..a84fc248d --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_sidebars.py @@ -0,0 +1,73 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the "sidebar" directive. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['sidebars'] = [ +["""\ +.. sidebar:: Outer + + .. sidebar:: Nested + + Body. +""", +"""\ +<document source="test data"> + <sidebar> + <title> + Outer + <system_message level="3" line="3" source="test data" type="ERROR"> + <paragraph> + The "sidebar" directive may not be used within a sidebar element. + <literal_block xml:space="preserve"> + .. sidebar:: Nested + \n\ + Body. +"""], +["""\ +.. sidebar:: Outer + + .. topic:: Topic + + .. sidebar:: Inner + + text +""", +"""\ +<document source="test data"> + <sidebar> + <title> + Outer + <topic> + <title> + Topic + <system_message level="3" line="5" source="test data" type="ERROR"> + <paragraph> + The "sidebar" directive may not be used within topics or body elements. + <literal_block xml:space="preserve"> + .. sidebar:: Inner + \n\ + text +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_tables.py b/test/test_parsers/test_rst/test_directives/test_tables.py new file mode 100755 index 000000000..da88510e7 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_tables.py @@ -0,0 +1,997 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for tables.py directives. +""" + +from __init__ import DocutilsTestSupport + +import os +try: + import csv +except ImportError: + csv = None + + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +mydir = 'test_parsers/test_rst/test_directives/' +utf_16_csv = os.path.join(mydir, 'utf-16.csv') +utf_16_csv_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_csv) +empty_txt = os.path.join(mydir, 'empty.txt') + +totest = {} + +totest['table'] = [ +["""\ +.. table:: Truth table for "not" + :class: custom + + ===== ===== + A not A + ===== ===== + False True + True False + ===== ===== +""", +"""\ +<document source="test data"> + <table classes="custom"> + <title> + Truth table for "not" + <tgroup cols="2"> + <colspec colwidth="5"> + <colspec colwidth="5"> + <thead> + <row> + <entry> + <paragraph> + A + <entry> + <paragraph> + not A + <tbody> + <row> + <entry> + <paragraph> + False + <entry> + <paragraph> + True + <row> + <entry> + <paragraph> + True + <entry> + <paragraph> + False +"""], +["""\ +.. table:: title with an *error + + ====== ===== + Simple table + ====== ===== +""", +"""\ +<document source="test data"> + <table> + <title> + title with an \n\ + <problematic ids="id2" refid="id1"> + * + error + <tgroup cols="2"> + <colspec colwidth="6"> + <colspec colwidth="5"> + <tbody> + <row> + <entry> + <paragraph> + Simple + <entry> + <paragraph> + table + <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Inline emphasis start-string without end-string. +"""], +] + +if not csv: + print ('Tests of "csv-table" directive skipped; ' + 'Python 2.3 or higher required.') +else: + totest['csv-table'] = [ +["""\ +.. csv-table:: inline with integral header + :widths: 10, 20, 30 + :header-rows: 1 + :stub-columns: 1 + + "Treat", "Quantity", "Description" + "Albatross", 2.99, "On a stick!" + "Crunchy Frog", 1.49, "If we took the bones out, it wouldn\'t be + crunchy, now would it?" + "Gannet Ripple", 1.99, "On a stick!" +""", +"""\ +<document source="test data"> + <table> + <title> + inline with integral header + <tgroup cols="3"> + <colspec colwidth="10" stub="1"> + <colspec colwidth="20"> + <colspec colwidth="30"> + <thead> + <row> + <entry> + <paragraph> + Treat + <entry> + <paragraph> + Quantity + <entry> + <paragraph> + Description + <tbody> + <row> + <entry> + <paragraph> + Albatross + <entry> + <paragraph> + 2.99 + <entry> + <paragraph> + On a stick! + <row> + <entry> + <paragraph> + Crunchy Frog + <entry> + <paragraph> + 1.49 + <entry> + <paragraph> + If we took the bones out, it wouldn't be + crunchy, now would it? + <row> + <entry> + <paragraph> + Gannet Ripple + <entry> + <paragraph> + 1.99 + <entry> + <paragraph> + On a stick! +"""], +["""\ +.. csv-table:: inline with separate header + :header: "Treat", Quantity, "Description" + :widths: 10,20,30 + + "Albatross", 2.99, "On a stick!" +""", +"""\ +<document source="test data"> + <table> + <title> + inline with separate header + <tgroup cols="3"> + <colspec colwidth="10"> + <colspec colwidth="20"> + <colspec colwidth="30"> + <thead> + <row> + <entry> + <paragraph> + Treat + <entry> + <paragraph> + Quantity + <entry> + <paragraph> + Description + <tbody> + <row> + <entry> + <paragraph> + Albatross + <entry> + <paragraph> + 2.99 + <entry> + <paragraph> + On a stick! +"""], +["""\ +.. csv-table:: complex internal structure + :header: "Treat", Quantity, " + * Description, + * Definition, or + * Narrative" + + " + * Ice cream + * Sorbet + * Albatross", 2.99, "On a stick!" +""", +"""\ +<document source="test data"> + <table> + <title> + complex internal structure + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <thead> + <row> + <entry> + <paragraph> + Treat + <entry> + <paragraph> + Quantity + <entry> + <bullet_list bullet="*"> + <list_item> + <paragraph> + Description, + <list_item> + <paragraph> + Definition, or + <list_item> + <paragraph> + Narrative + <tbody> + <row> + <entry> + <bullet_list bullet="*"> + <list_item> + <paragraph> + Ice cream + <list_item> + <paragraph> + Sorbet + <list_item> + <paragraph> + Albatross + <entry> + <paragraph> + 2.99 + <entry> + <paragraph> + On a stick! +"""], +["""\ +.. csv-table:: short rows + + one, 2, three + 4, five +""", +"""\ +<document source="test data"> + <table> + <title> + short rows + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <tbody> + <row> + <entry> + <paragraph> + one + <entry> + <paragraph> + 2 + <entry> + <paragraph> + three + <row> + <entry> + <paragraph> + 4 + <entry> + <paragraph> + five + <entry> +"""], +["""\ +.. csv-table:: short rows + :header-rows: 1 + + header col 1, header col 2 + one, 2, three + 4 +""", +"""\ +<document source="test data"> + <table> + <title> + short rows + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <thead> + <row> + <entry> + <paragraph> + header col 1 + <entry> + <paragraph> + header col 2 + <entry> + <tbody> + <row> + <entry> + <paragraph> + one + <entry> + <paragraph> + 2 + <entry> + <paragraph> + three + <row> + <entry> + <paragraph> + 4 + <entry> + <entry> +"""], +[u"""\ +.. csv-table:: non-ASCII characters + + Heiz\xf6lr\xfccksto\xdfabd\xe4mpfung +""", +u"""\ +<document source="test data"> + <table> + <title> + non-ASCII characters + <tgroup cols="1"> + <colspec colwidth="100"> + <tbody> + <row> + <entry> + <paragraph> + Heiz\xf6lr\xfccksto\xdfabd\xe4mpfung +"""], +["""\ +.. csv-table:: empty +""", +"""\ +<document source="test data"> + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + The "csv-table" directive requires content; none supplied. + <literal_block xml:space="preserve"> + .. csv-table:: empty +"""], +["""\ +.. csv-table:: insufficient header row data + :header-rows: 2 + + some, csv, data +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + 2 header row(s) specified but only 1 row(s) of data supplied ("csv-table" directive). + <literal_block xml:space="preserve"> + .. csv-table:: insufficient header row data + :header-rows: 2 + \n\ + some, csv, data +"""], +["""\ +.. csv-table:: insufficient body data + :header-rows: 1 + + some, csv, data +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Insufficient data supplied (1 row(s)); no data remaining for table body, required by "csv-table" directive. + <literal_block xml:space="preserve"> + .. csv-table:: insufficient body data + :header-rows: 1 + \n\ + some, csv, data +"""], +["""\ +.. csv-table:: content and external + :file: bogus.csv + + some, csv, data +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + "csv-table" directive may not both specify an external file and have content. + <literal_block xml:space="preserve"> + .. csv-table:: content and external + :file: bogus.csv + \n\ + some, csv, data +"""], +["""\ +.. csv-table:: external file and url + :file: bogus.csv + :url: http://example.org/bogus.csv +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + The "file" and "url" options may not be simultaneously specified for the "csv-table" directive. + <literal_block xml:space="preserve"> + .. csv-table:: external file and url + :file: bogus.csv + :url: http://example.org/bogus.csv +"""], +["""\ +.. csv-table:: error in the *title + + some, csv, data +""", +"""\ +<document source="test data"> + <table> + <title> + error in the \n\ + <problematic ids="id2" refid="id1"> + * + title + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <tbody> + <row> + <entry> + <paragraph> + some + <entry> + <paragraph> + csv + <entry> + <paragraph> + data + <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Inline emphasis start-string without end-string. +"""], +["""\ +.. csv-table:: no such file + :file: bogus.csv +""", +"""\ +<document source="test data"> + <system_message level="4" line="1" source="test data" type="SEVERE"> + <paragraph> + Problems with "csv-table" directive path: + [Errno 2] No such file or directory: 'bogus.csv'. + <literal_block xml:space="preserve"> + .. csv-table:: no such file + :file: bogus.csv +"""], +["""\ +.. csv-table:: bad URL + :url: bogus.csv +""", +"""\ +<document source="test data"> + <system_message level="4" line="1" source="test data" type="SEVERE"> + <paragraph> + Problems with "csv-table" directive URL "bogus.csv": + unknown url type: bogus.csv. + <literal_block xml:space="preserve"> + .. csv-table:: bad URL + :url: bogus.csv +"""], +["""\ +.. csv-table:: column mismatch + :widths: 10,20 + + some, csv, data +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + "csv-table" widths do not match the number of columns in table (3). + <literal_block xml:space="preserve"> + .. csv-table:: column mismatch + :widths: 10,20 + \n\ + some, csv, data +"""], +["""\ +.. csv-table:: bad column widths + :widths: 10,y,z + + some, csv, data + +.. csv-table:: bad column widths + :widths: 0 0 0 + + some, csv, data +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "csv-table" directive: + invalid option value: (option: "widths"; value: '10,y,z') + invalid literal for int(): y. + <literal_block xml:space="preserve"> + .. csv-table:: bad column widths + :widths: 10,y,z + \n\ + some, csv, data + <system_message level="3" line="6" source="test data" type="ERROR"> + <paragraph> + Error in "csv-table" directive: + invalid option value: (option: "widths"; value: '0 0 0') + negative or zero value; must be positive. + <literal_block xml:space="preserve"> + .. csv-table:: bad column widths + :widths: 0 0 0 + \n\ + some, csv, data +"""], +["""\ +.. csv-table:: good delimiter + :delim: / + + some/csv/data + +.. csv-table:: good delimiter + :delim: \\ + + some\\csv\\data + +.. csv-table:: good delimiter + :delim: 0x5c + + some\\csv\\data + +.. csv-table:: good delimiter + :delim: space + + some csv data +""", +"""\ +<document source="test data"> + <table> + <title> + good delimiter + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <tbody> + <row> + <entry> + <paragraph> + some + <entry> + <paragraph> + csv + <entry> + <paragraph> + data + <table> + <title> + good delimiter + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <tbody> + <row> + <entry> + <paragraph> + some + <entry> + <paragraph> + csv + <entry> + <paragraph> + data + <table> + <title> + good delimiter + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <tbody> + <row> + <entry> + <paragraph> + some + <entry> + <paragraph> + csv + <entry> + <paragraph> + data + <table> + <title> + good delimiter + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <tbody> + <row> + <entry> + <paragraph> + some + <entry> + <paragraph> + csv + <entry> + <paragraph> + data +"""], +["""\ +.. csv-table:: bad delimiter + :delim: multiple + +.. csv-table:: bad delimiter + :delim: U+9999999999999 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "csv-table" directive: + invalid option value: (option: "delim"; value: 'multiple') + 'multiple' invalid; must be a single character or a Unicode code. + <literal_block xml:space="preserve"> + .. csv-table:: bad delimiter + :delim: multiple + <system_message level="3" line="4" source="test data" type="ERROR"> + <paragraph> + Error in "csv-table" directive: + invalid option value: (option: "delim"; value: 'U+9999999999999') + code too large (long int too large to convert to int). + <literal_block xml:space="preserve"> + .. csv-table:: bad delimiter + :delim: U+9999999999999 +"""], +["""\ +.. csv-table:: bad CSV data + + "bad", \"csv, data +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error with CSV data in "csv-table" directive: + newline inside string + <literal_block xml:space="preserve"> + .. csv-table:: bad CSV data + \n\ + "bad", \"csv, data +"""], +["""\ +.. csv-table:: bad CSV header data + :header: "bad", \"csv, data + + good, csv, data +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error with CSV data in "csv-table" directive: + newline inside string + <literal_block xml:space="preserve"> + .. csv-table:: bad CSV header data + :header: "bad", \"csv, data + \n\ + good, csv, data +"""], +["""\ +.. csv-table:: bad encoding + :file: %s + :encoding: latin-1 + +(7- and 8-bit text encoded as UTF-16 has lots of null/zero bytes.) +""" % utf_16_csv, +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error with CSV data in "csv-table" directive: + string with NUL bytes + <literal_block xml:space="preserve"> + .. csv-table:: bad encoding + :file: %s + :encoding: latin-1 + <paragraph> + (7- and 8-bit text encoded as UTF-16 has lots of null/zero bytes.) +""" % utf_16_csv], +["""\ +.. csv-table:: good encoding + :file: %s + :encoding: utf-16 + :header-rows: 1 +""" % utf_16_csv, +u"""\ +<document source="test data"> + <table> + <title> + good encoding + <tgroup cols="3"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <colspec colwidth="33"> + <thead> + <row> + <entry> + <paragraph> + Treat + <entry> + <paragraph> + Quantity + <entry> + <paragraph> + Description + <tbody> + <row> + <entry> + <paragraph> + Albatr\u00b0\u00df + <entry> + <paragraph> + 2.99 + <entry> + <paragraph> + \u00a1On a \u03c3\u03c4\u03b9\u03ba! + <row> + <entry> + <paragraph> + Crunchy Frog + <entry> + <paragraph> + 1.49 + <entry> + <paragraph> + If we took the b\u00f6nes out, it wouldn\u2019t be + crunchy, now would it? + <row> + <entry> + <paragraph> + Gannet Ripple + <entry> + <paragraph> + 1.99 + <entry> + <paragraph> + \u00bfOn a \u03c3\u03c4\u03b9\u03ba? +"""], +["""\ +.. csv-table:: no CSV data + :file: %s +""" % empty_txt, +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + No table data detected in CSV file. + <literal_block xml:space="preserve"> + .. csv-table:: no CSV data + :file: %s +""" % empty_txt], +] + +totest['list-table'] = [ +["""\ +.. list-table:: list table with integral header + :widths: 10 20 30 + :header-rows: 1 + :stub-columns: 1 + + * - Treat + - Quantity + - Description + * - Albatross + - 2.99 + - On a stick! + * - Crunchy Frog + - 1.49 + - If we took the bones out, it wouldn\'t be + crunchy, now would it? + * - Gannet Ripple + - 1.99 + - On a stick! +""", +"""\ +<document source="test data"> + <table> + <title> + list table with integral header + <tgroup cols="3"> + <colspec colwidth="10" stub="1"> + <colspec colwidth="20"> + <colspec colwidth="30"> + <thead> + <row> + <entry> + <paragraph> + Treat + <entry> + <paragraph> + Quantity + <entry> + <paragraph> + Description + <tbody> + <row> + <entry> + <paragraph> + Albatross + <entry> + <paragraph> + 2.99 + <entry> + <paragraph> + On a stick! + <row> + <entry> + <paragraph> + Crunchy Frog + <entry> + <paragraph> + 1.49 + <entry> + <paragraph> + If we took the bones out, it wouldn\'t be + crunchy, now would it? + <row> + <entry> + <paragraph> + Gannet Ripple + <entry> + <paragraph> + 1.99 + <entry> + <paragraph> + On a stick! +"""], +["""\ +.. list-table:: + + not a bullet list +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error parsing content block for the "list-table" directive: exactly one bullet list expected. + <literal_block xml:space="preserve"> + .. list-table:: + \n\ + not a bullet list +"""], +["""\ +.. list-table:: + + * not a second-level bullet list +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error parsing content block for the "list-table" directive: two-level bullet list expected, but row 1 does not contain a second-level bullet list. + <literal_block xml:space="preserve"> + .. list-table:: + \n\ + * not a second-level bullet list +"""], +["""\ +.. list-table:: + + * - columns not uniform + * - first row has one, + - second row has two +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error parsing content block for the "list-table" directive: uniform two-level bullet list expected, but row 2 does not contain the same number of items as row 1 (2 vs 1). + <literal_block xml:space="preserve"> + .. list-table:: + \n\ + * - columns not uniform + * - first row has one, + - second row has two +"""], +["""\ +.. list-table:: + :widths: 10 20 + + * - ":widths:" option doesn't match columns +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + "list-table" widths do not match the number of columns in table (1). + <literal_block xml:space="preserve"> + .. list-table:: + :widths: 10 20 + \n\ + * - ":widths:" option doesn\'t match columns +"""], +["""\ +.. list-table:: + :stub-columns: 3 + + * - column 1 + - column 2 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + 3 stub column(s) specified but only 2 columns(s) of data supplied ("list-table" directive). + <literal_block xml:space="preserve"> + .. list-table:: + :stub-columns: 3 + \n\ + * - column 1 + - column 2 +"""], +["""\ +.. list-table:: + :stub-columns: 2 + + * - column 1 + - column 2 +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Insufficient data supplied (2 columns(s)); no data remaining for table body, required by "list-table" directive. + <literal_block xml:space="preserve"> + .. list-table:: + :stub-columns: 2 + \n\ + * - column 1 + - column 2 +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_target_notes.py b/test/test_parsers/test_rst/test_directives/test_target_notes.py new file mode 100755 index 000000000..18dc1d207 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_target_notes.py @@ -0,0 +1,64 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the target-notes directives. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['target-notes'] = [ +["""\ +.. target-notes:: +""", +"""\ +<document source="test data"> + <pending> + .. internal attributes: + .transform: docutils.transforms.references.TargetNotes + .details: +"""], +["""\ +.. target-notes:: :class: custom +""", +"""\ +<document source="test data"> + <pending> + .. internal attributes: + .transform: docutils.transforms.references.TargetNotes + .details: + class: ['custom'] +"""], +["""\ +.. target-notes:: + :class: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "target-notes" directive: + invalid option value: (option: "class"; value: None) + argument required but none supplied. + <literal_block xml:space="preserve"> + .. target-notes:: + :class: +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_test_directives.py b/test/test_parsers/test_rst/test_directives/test_test_directives.py new file mode 100755 index 000000000..b90b26473 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_test_directives.py @@ -0,0 +1,208 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for misc.py test directives. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['test_directives'] = [ +["""\ +.. reStructuredText-test-directive:: + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=[], options={}, content: None + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive :: + +An optional space before the "::". +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=[], options={}, content: None + <paragraph> + An optional space before the "::". +"""], +["""\ +.. reStructuredText-test-directive:: argument + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=['argument'], options={}, content: None + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: argument + :option: value + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=['argument'], options={'option': 'value'}, content: None + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: :option: value + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=[], options={'option': 'value'}, content: None + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: :option: + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "reStructuredText-test-directive" directive: + invalid option value: (option: "option"; value: None) + argument required but none supplied. + <literal_block xml:space="preserve"> + .. reStructuredText-test-directive:: :option: + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: + + Directive block contains one paragraph, with a blank line before. + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=[], options={}, content: + <literal_block xml:space="preserve"> + Directive block contains one paragraph, with a blank line before. + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: + + + Directive block contains one paragraph, with two blank lines before. + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=[], options={}, content: + <literal_block xml:space="preserve"> + Directive block contains one paragraph, with two blank lines before. + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: + Directive block contains one paragraph, no blank line before. + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=['Directive block contains one paragraph, no blank line before.'], options={}, content: None + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: + block +no blank line. + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=['block'], options={}, content: None + <system_message level="2" line="3" source="test data" type="WARNING"> + <paragraph> + Explicit markup ends without a blank line; unexpected unindent. + <paragraph> + no blank line. + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: argument + :option: * value1 + * value2 + +Paragraph. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=['argument'], options={'option': '* value1\\n* value2'}, content: None + <paragraph> + Paragraph. +"""], +["""\ +.. reStructuredText-test-directive:: + + Directive \\block \\*contains* \\\\backslashes. +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + Directive processed. Type="reStructuredText-test-directive", arguments=[], options={}, content: + <literal_block xml:space="preserve"> + Directive \\block \\*contains* \\\\backslashes. +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_topics.py b/test/test_parsers/test_rst/test_directives/test_topics.py new file mode 100755 index 000000000..4d0fae27b --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_topics.py @@ -0,0 +1,240 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for the "topic" directive. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['topics'] = [ +["""\ +.. topic:: +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "topic" directive: + 1 argument(s) required, 0 supplied. + <literal_block xml:space="preserve"> + .. topic:: +"""], +["""\ +.. topic:: Title +""", +"""\ +<document source="test data"> + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Content block expected for the "topic" directive; none found. + <literal_block xml:space="preserve"> + .. topic:: Title +"""], +["""\ +.. topic:: Title + + Body. +""", +"""\ +<document source="test data"> + <topic> + <title> + Title + <paragraph> + Body. +"""], +["""\ +.. topic:: + + Title + + Body. +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "topic" directive: + 1 argument(s) required, 0 supplied. + <literal_block xml:space="preserve"> + .. topic:: + \n\ + Title + \n\ + Body. +"""], +["""\ +.. topic:: Title + Body. +""", +"""\ +<document source="test data"> + <system_message level="2" line="1" source="test data" type="WARNING"> + <paragraph> + Content block expected for the "topic" directive; none found. + <literal_block xml:space="preserve"> + .. topic:: Title + Body. +"""], +["""\ +.. topic:: + + Title + Body. +""", +"""\ +<document source="test data"> + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Error in "topic" directive: + 1 argument(s) required, 0 supplied. + <literal_block xml:space="preserve"> + .. topic:: + \n\ + Title + Body. +"""], +["""\ +.. topic:: Title + + .. topic:: Nested + + Body. +""", +"""\ +<document source="test data"> + <topic> + <title> + Title + <system_message level="3" line="3" source="test data" type="ERROR"> + <paragraph> + The "topic" directive may not be used within topics or body elements. + <literal_block xml:space="preserve"> + .. topic:: Nested + \n\ + Body. +"""], +["""\ +.. topic:: Title + + .. topic:: Nested + + Body. + More. +""", +"""\ +<document source="test data"> + <topic> + <title> + Title + <system_message level="3" line="3" source="test data" type="ERROR"> + <paragraph> + The "topic" directive may not be used within topics or body elements. + <literal_block xml:space="preserve"> + .. topic:: Nested + \n\ + Body. + <system_message level="2" line="6" source="test data" type="WARNING"> + <paragraph> + Explicit markup ends without a blank line; unexpected unindent. + <paragraph> + More. +"""], +["""\ +.. topic:: Title + + .. topic:: Nested + + Body. + + More. + +More. +""", +"""\ +<document source="test data"> + <topic> + <title> + Title + <system_message level="3" line="3" source="test data" type="ERROR"> + <paragraph> + The "topic" directive may not be used within topics or body elements. + <literal_block xml:space="preserve"> + .. topic:: Nested + \n\ + Body. + <paragraph> + More. + <paragraph> + More. +"""], +["""\ +.. topic:: First + + Body + +.. topic:: Second + + Body. +""", +"""\ +<document source="test data"> + <topic> + <title> + First + <paragraph> + Body + <topic> + <title> + Second + <paragraph> + Body. +"""], +["""\ +.. sidebar:: Title + :subtitle: Outer + + .. topic:: Nested + + Body. + + More. + +More. +""", +"""\ +<document source="test data"> + <sidebar> + <title> + Title + <subtitle> + Outer + <topic> + <title> + Nested + <paragraph> + Body. + <paragraph> + More. + <paragraph> + More. +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_unicode.py b/test/test_parsers/test_rst/test_directives/test_unicode.py new file mode 100755 index 000000000..bd028cf42 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_unicode.py @@ -0,0 +1,172 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for misc.py "unicode" directive. +""" + +from __init__ import DocutilsTestSupport + + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['unicode'] = [ +[""" +Insert an em-dash (|mdash|), a copyright symbol (|copy|), a non-breaking +space (|nbsp|), a backwards-not-equals (|bne|), and a captial omega (|Omega|). + +.. |mdash| unicode:: 0x02014 +.. |copy| unicode:: \\u00A9 +.. |nbsp| unicode::   +.. |bne| unicode:: U0003D U020E5 +.. |Omega| unicode:: U+003A9 +""", +u"""\ +<document source="test data"> + <paragraph> + Insert an em-dash ( + <substitution_reference refname="mdash"> + mdash + ), a copyright symbol ( + <substitution_reference refname="copy"> + copy + ), a non-breaking + space ( + <substitution_reference refname="nbsp"> + nbsp + ), a backwards-not-equals ( + <substitution_reference refname="bne"> + bne + ), and a captial omega ( + <substitution_reference refname="Omega"> + Omega + ). + <substitution_definition names="mdash"> + \u2014 + <substitution_definition names="copy"> + \u00A9 + <substitution_definition names="nbsp"> + \u00A0 + <substitution_definition names="bne"> + = + \u20e5 + <substitution_definition names="Omega"> + \u03a9 +"""], +[""" +Bad input: + +.. |empty| unicode:: +.. |empty too| unicode:: .. comment doesn't count as content +.. |not hex| unicode:: 0xHEX +.. |not all hex| unicode:: UABCX +.. unicode:: not in a substitution definition +""", +"""\ +<document source="test data"> + <paragraph> + Bad input: + <system_message level="3" line="4" source="test data" type="ERROR"> + <paragraph> + Error in "unicode" directive: + 1 argument(s) required, 0 supplied. + <literal_block xml:space="preserve"> + unicode:: + <system_message level="2" line="4" source="test data" type="WARNING"> + <paragraph> + Substitution definition "empty" empty or invalid. + <literal_block xml:space="preserve"> + .. |empty| unicode:: + <system_message level="2" line="5" source="test data" type="WARNING"> + <paragraph> + Substitution definition "empty too" empty or invalid. + <literal_block xml:space="preserve"> + .. |empty too| unicode:: .. comment doesn't count as content + <substitution_definition names="not\ hex"> + 0xHEX + <substitution_definition names="not\ all\ hex"> + UABCX + <system_message level="3" line="8" source="test data" type="ERROR"> + <paragraph> + Invalid context: the "unicode" directive can only be used within a substitution definition. + <literal_block xml:space="preserve"> + .. unicode:: not in a substitution definition +"""], +[""" +Testing comments and extra text. + +Copyright |copy| 2003, |BogusMegaCorp (TM)|. + +.. |copy| unicode:: 0xA9 .. copyright sign +.. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122 + .. with trademark sign +""", +u"""\ +<document source="test data"> + <paragraph> + Testing comments and extra text. + <paragraph> + Copyright + <substitution_reference refname="copy"> + copy + 2003, + <substitution_reference refname="BogusMegaCorp (TM)"> + BogusMegaCorp (TM) + . + <substitution_definition names="copy"> + \u00A9 + <substitution_definition names="BogusMegaCorp\ (TM)"> + BogusMegaCorp + \u2122 +"""], +[""" +.. |too big for int| unicode:: 0x111111111111111111 +.. |too big for unicode| unicode:: 0x11111111 +""", +"""\ +<document source="test data"> + <system_message level="3" line="2" source="test data" type="ERROR"> + <paragraph> + Invalid character code: 0x111111111111111111 + ValueError: %s + <literal_block xml:space="preserve"> + unicode:: 0x111111111111111111 + <system_message level="2" line="2" source="test data" type="WARNING"> + <paragraph> + Substitution definition "too big for int" empty or invalid. + <literal_block xml:space="preserve"> + .. |too big for int| unicode:: 0x111111111111111111 + <system_message level="3" line="3" source="test data" type="ERROR"> + <paragraph> + Invalid character code: 0x11111111 + %s + <literal_block xml:space="preserve"> + unicode:: 0x11111111 + <system_message level="2" line="3" source="test data" type="WARNING"> + <paragraph> + Substitution definition "too big for unicode" empty or invalid. + <literal_block xml:space="preserve"> + .. |too big for unicode| unicode:: 0x11111111 +""" % ([DocutilsTestSupport.exception_data( + 'unichr(int("111111111111111111", 16))')[0], + 'code too large (%s)' % DocutilsTestSupport.exception_data( + 'unichr(int("111111111111111111", 16))')[0]] + [isinstance(DocutilsTestSupport.exception_data( + 'unichr(int("111111111111111111", 16))')[0], OverflowError)], + DocutilsTestSupport.exception_data('unichr(int("11111111", 16))')[2])] +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/test_unknown.py b/test/test_parsers/test_rst/test_directives/test_unknown.py new file mode 100755 index 000000000..3c859faa3 --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/test_unknown.py @@ -0,0 +1,67 @@ +#! /usr/bin/env python + +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests for unknown directives. +""" + +from __init__ import DocutilsTestSupport + +def suite(): + s = DocutilsTestSupport.ParserTestSuite() + s.generateTests(totest) + return s + +totest = {} + +totest['unknown'] = [ +["""\ +.. reStructuredText-unknown-directive:: + +.. reStructuredText-unknown-directive:: argument + +.. reStructuredText-unknown-directive:: + block +""", +"""\ +<document source="test data"> + <system_message level="1" line="1" source="test data" type="INFO"> + <paragraph> + No directive entry for "reStructuredText-unknown-directive" in module "docutils.parsers.rst.languages.en". + Trying "reStructuredText-unknown-directive" as canonical directive name. + <system_message level="3" line="1" source="test data" type="ERROR"> + <paragraph> + Unknown directive type "reStructuredText-unknown-directive". + <literal_block xml:space="preserve"> + .. reStructuredText-unknown-directive:: + <system_message level="1" line="3" source="test data" type="INFO"> + <paragraph> + No directive entry for "reStructuredText-unknown-directive" in module "docutils.parsers.rst.languages.en". + Trying "reStructuredText-unknown-directive" as canonical directive name. + <system_message level="3" line="3" source="test data" type="ERROR"> + <paragraph> + Unknown directive type "reStructuredText-unknown-directive". + <literal_block xml:space="preserve"> + .. reStructuredText-unknown-directive:: argument + <system_message level="1" line="5" source="test data" type="INFO"> + <paragraph> + No directive entry for "reStructuredText-unknown-directive" in module "docutils.parsers.rst.languages.en". + Trying "reStructuredText-unknown-directive" as canonical directive name. + <system_message level="3" line="5" source="test data" type="ERROR"> + <paragraph> + Unknown directive type "reStructuredText-unknown-directive". + <literal_block xml:space="preserve"> + .. reStructuredText-unknown-directive:: + block +"""], +] + + +if __name__ == '__main__': + import unittest + unittest.main(defaultTest='suite') diff --git a/test/test_parsers/test_rst/test_directives/utf-16.csv b/test/test_parsers/test_rst/test_directives/utf-16.csv Binary files differnew file mode 100644 index 000000000..ba60d155e --- /dev/null +++ b/test/test_parsers/test_rst/test_directives/utf-16.csv |