mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Also remove # doctest: directives in presentation output.
This commit is contained in:
parent
b82b162729
commit
7111855bab
3
CHANGES
3
CHANGES
@ -5,7 +5,8 @@ Changes in trunk
|
||||
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.
|
||||
|
@ -69,6 +69,14 @@ names.
|
||||
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 @@ There are also these config values for customizing the doctest extension:
|
||||
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.
|
||||
|
@ -25,7 +25,7 @@ from sphinx.builder import Builder
|
||||
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 @@ def test_directive(name, arguments, options, content, lineno,
|
||||
# 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
|
||||
|
Loading…
Reference in New Issue
Block a user