Anonymous avatar Anonymous committed 624359c

Also remove # doctest: directives in presentation output.

Comments (0)

Files changed (3)

   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.

doc/ext/doctest.rst

    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]
 
    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.

sphinx/ext/doctest.py

 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
 
     # 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.