[Python-checkins] r61764 - in doctools/trunk: CHANGES doc/ext/doctest.rst sphinx/ext/doctest.py

georg.brandl python-checkins at python.org
Sat Mar 22 22:21:28 CET 2008


Author: georg.brandl
Date: Sat Mar 22 22:21:28 2008
New Revision: 61764

Modified:
   doctools/trunk/CHANGES
   doctools/trunk/doc/ext/doctest.rst
   doctools/trunk/sphinx/ext/doctest.py
Log:
Also remove # doctest: directives in presentation output.


Modified: doctools/trunk/CHANGES
==============================================================================
--- doctools/trunk/CHANGES	(original)
+++ doctools/trunk/CHANGES	Sat Mar 22 22:21:28 2008
@@ -5,7 +5,8 @@
   placed selectable, and default to ``'default'``.
 
 * sphinx.ext.doctest: Replace <BLANKLINE> in doctest blocks by
-  real blank lines for presentation output.
+  real blank lines for presentation output, and remove doctest
+  options given inline.
 
 * sphinx.environment: Move doctest_blocks out of block_quotes to
   support indented doctest blocks.

Modified: doctools/trunk/doc/ext/doctest.rst
==============================================================================
--- doctools/trunk/doc/ext/doctest.rst	(original)
+++ doctools/trunk/doc/ext/doctest.rst	Sat Mar 22 22:21:28 2008
@@ -69,6 +69,14 @@
    signal a blank line in the expected output.  The ``<BLANKLINE>`` is removed
    when building presentation output (HTML, LaTeX etc.).
 
+   Also, you can give inline doctest options, like in doctest::
+
+      >>> datetime.date.now()   # doctest: +SKIP
+      datetime.date(2008, 1, 1)
+
+   They will be respected when the test is run, but stripped from presentation
+   output.
+
 
 .. directive:: .. testcode:: [group]
 
@@ -178,4 +186,6 @@
    special directive.
 
    Note though that you can't have blank lines in reST doctest blocks.  They
-   will be interpreted as one block ending and another one starting.
+   will be interpreted as one block ending and another one starting.  Also,
+   removal of ``<BLANKLINE>`` and ``# doctest:`` options only works in
+   :dir:`doctest` blocks.

Modified: doctools/trunk/sphinx/ext/doctest.py
==============================================================================
--- doctools/trunk/sphinx/ext/doctest.py	(original)
+++ doctools/trunk/sphinx/ext/doctest.py	Sat Mar 22 22:21:28 2008
@@ -25,7 +25,7 @@
 from sphinx.util.console import bold
 
 blankline_re = re.compile(r'^\s*<BLANKLINE>', re.MULTILINE)
-
+doctestopt_re = re.compile(r'#\s*doctest:.+$', re.MULTILINE)
 
 # set up the necessary directives
 
@@ -35,10 +35,15 @@
     # so that our builder recognizes them, and the other builders are happy.
     code = '\n'.join(content)
     test = None
-    if name == 'doctest' and '<BLANKLINE>' in code:
-        # convert <BLANKLINE>s to ordinary blank lines for presentation
-        test = code
-        code = blankline_re.sub('', code)
+    if name == 'doctest':
+        if '<BLANKLINE>' in code:
+            # convert <BLANKLINE>s to ordinary blank lines for presentation
+            test = code
+            code = blankline_re.sub('', code)
+        if doctestopt_re.search(code):
+            if not test:
+                test = code
+            code = doctestopt_re.sub('', code)
     nodetype = nodes.literal_block
     if name == 'testsetup' or 'hide' in options:
         nodetype = nodes.comment


More information about the Python-checkins mailing list