diff options
| author | Georg Brandl <georg@python.org> | 2010-01-02 14:59:27 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2010-01-02 14:59:27 +0100 |
| commit | 7e8cbbe18b8ef054ecab9b6a0c35dfa52c5ea338 (patch) | |
| tree | b855e2b0dba66cf314b473bc82234a2819f8327d /tests | |
| parent | 1a051a1d59f8d71c756ffd1c726825e4c5346882 (diff) | |
| download | sphinx-7e8cbbe18b8ef054ecab9b6a0c35dfa52c5ea338.tar.gz | |
#310: support exception messages in the ``testoutput`` blocks of the ``doctest`` extension.
Also add minimal test cases for the doctest extension.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/root/conf.py | 2 | ||||
| -rw-r--r-- | tests/root/contents.txt | 1 | ||||
| -rw-r--r-- | tests/root/doctest.txt | 120 | ||||
| -rw-r--r-- | tests/test_doctest.py | 24 |
4 files changed, 146 insertions, 1 deletions
diff --git a/tests/root/conf.py b/tests/root/conf.py index 192a1883..6657714d 100644 --- a/tests/root/conf.py +++ b/tests/root/conf.py @@ -6,7 +6,7 @@ sys.path.append(os.path.abspath('.')) extensions = ['ext', 'sphinx.ext.autodoc', 'sphinx.ext.jsmath', 'sphinx.ext.coverage', 'sphinx.ext.todo', - 'sphinx.ext.autosummary'] + 'sphinx.ext.autosummary', 'sphinx.ext.doctest'] jsmath_path = 'dummy.js' diff --git a/tests/root/contents.txt b/tests/root/contents.txt index 9891c64e..aeca6a58 100644 --- a/tests/root/contents.txt +++ b/tests/root/contents.txt @@ -21,6 +21,7 @@ Contents: math autodoc autosummary + doctest Python <http://python.org/> diff --git a/tests/root/doctest.txt b/tests/root/doctest.txt new file mode 100644 index 00000000..35cdd589 --- /dev/null +++ b/tests/root/doctest.txt @@ -0,0 +1,120 @@ +Testing the doctest extension +============================= + +Simple doctest blocks +--------------------- + +>>> 1+1 +2 +>>> 1/0 +Traceback (most recent call last): + ... +ZeroDivisionError: integer division or modulo by zero + + +Special directives +------------------ + +* doctest + + .. doctest:: + + >>> 1+1 + 2 + >>> 1/0 + Traceback (most recent call last): + ... + ZeroDivisionError: integer division or modulo by zero + +* testcode/testoutput + + .. testcode:: + + print 1+1 + + .. testoutput:: + + 2 + + .. testcode:: + + 1/0 + + .. testoutput:: + + Traceback (most recent call last): + ... + ZeroDivisionError: integer division or modulo by zero + +* testsetup + + .. testsetup:: * + + from math import floor + + .. doctest:: + + >>> floor(1.2) + 1.0 + + .. testcode:: + + print floor(1.2) + + .. testoutput:: + + 1.0 + + >>> floor(1.2) + 1.0 + +* options for testcode/testoutput blocks + + .. testcode:: + :hide: + + print 'Output text.' + + .. testoutput:: + :hide: + :options: +NORMALIZE_WHITESPACE + + Output text. + +* grouping + + .. testsetup:: group1 + + from math import ceil + + ``ceil`` is now known in "group1", but not in others. + + .. doctest:: group1 + + >>> ceil(0.8) + 1.0 + + .. doctest:: group2 + + >>> ceil(0.8) + Traceback (most recent call last): + ... + NameError: name 'ceil' is not defined + + Interleaving testcode/testoutput: + + .. testcode:: group1 + + print ceil(0.8) + + .. testcode:: group2 + + print floor(0.8) + + .. testoutput:: group1 + + 1.0 + + .. testoutput:: group2 + + 0.0 diff --git a/tests/test_doctest.py b/tests/test_doctest.py new file mode 100644 index 00000000..b4b6bbe2 --- /dev/null +++ b/tests/test_doctest.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +""" + test_doctest + ~~~~~~~~~~~~ + + Test the doctest extension. + + :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import sys +import StringIO + +from util import * + +status = StringIO.StringIO() + +@with_app(buildername='doctest', status=status) +def test_build(app): + app.builder.build_all() + if app.statuscode != 0: + print >>sys.stderr, status.getvalue() + assert False, 'failures in doctests' |
