Issue 932933: doctest: add an option to end examples w/ dedent (original) (raw)

Created on 2004-04-10 19:56 by edloper, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
doctest_end_with_dedent.diff edloper,2004-04-10 19:56 Diff against doctest.py
Messages (4)
msg45734 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-04-10 19:56
A current limitation of doctest is that it can't handle output containing blank lines, since it uses blank lines to detect the end of the example. This patch adds a new option, END_WITH_DEDENT, that gets around that problem by using a dedent to detect the end of examples instead. In particular, when END_WITH_DEDENT is specified, the end of each indented doctest example is marked by a dedent past its original prompt (>>>). Thus, blank lines may appear within the output. However, trailing blank lines are still disallowed. Unindented docstring examples continue to be termined by a blank line (since dedenting past the prompt is impossible). Here's an example use: def f(): r""" A doctest example with a blank line: >>> print 'One\n\nTwo' One Two Note that ending with dedents also means that we can skip the blank lines around doctest examples if we want: >>> print 1 1 This dedent signifies the end of the example; there's no need for a blank line. """ The END_WITH_DEDENT uses the same optionflags system that is already used by DONT_ACCEPT_TRUE_FOR_1. The patch was made avainst revision 1.33 of doctest.py.
msg45735 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-04-10 20:00
Logged In: YES user_id=195958 If this patch looks good, I'd be happy to write a patch for the docs & test cases.
msg45736 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-04-11 15:15
Logged In: YES user_id=195958 This patch is probably mutually exclusive with patch #933238 [1], since they both have the same goal: to allow blank lines in doctest output. I thought of this solution first, but I think I prefer the other patch. Here's a comparison of pros and cons of this patch vs #933238. [-] it needs a special option to turn it on [-] it doesn't handles trailing blank lines [-] it will break external tools like epytext and restructuredtext that look for doctest blocks. [+] the user doesn't have to manually add blank line markers.
msg45737 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-06-01 00:23
Logged In: YES user_id=31435 Rejecting this one; let's focus on your other patch instead.
History
Date User Action Args
2022-04-11 14:56:03 admin set github: 40137
2004-04-10 19:56:43 edloper create