[Python-checkins] python/dist/src/Lib doctest.py,1.36.2.3,1.36.2.4
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Tue Aug 3 17:55:47 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12755/Lib
Modified Files:
Tag: tim-doctest-branch
doctest.py
Log Message:
Repair failure of test_difflib. difflib has a nasty one:
>>> for line in results: print repr(line)
...
[results go here]
That managed to break the intent (of doctest's parsing) that an
example would end with a newline iff it was a multi-line example.
That example really isn't multiline, but ended up with a trailing
newline anyway. Edward's new code asserted this invariant, which
the old difflib code did not do. So fixed the parsing to get rid
of the trailing newline in this case.
But then it turned out that compile(... "single") doesn't accept
a "block opener: body" statement *without* a trailing newline,
raising SyntaxError if you try. So changed compilation to always
append a newline.
test_difflib passes now.
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.36.2.3
retrieving revision 1.36.2.4
diff -C2 -d -r1.36.2.3 -r1.36.2.4
*** doctest.py 3 Aug 2004 04:08:52 -0000 1.36.2.3
--- doctest.py 3 Aug 2004 15:55:29 -0000 1.36.2.4
***************
*** 510,513 ****
--- 510,514 ----
i, n = 0, len(lines)
while i < n:
+ # Search for an example (a PS1 line).
line = lines[i]
i = i + 1
***************
*** 515,526 ****
if m is None:
continue
j = m.end(0) # beyond the prompt
if isEmpty(line, j) or isComment(line, j):
# a bare prompt or comment -- not interesting
continue
lineno = i - 1
if line[j] != " ":
raise ValueError('line %r of the docstring for %s lacks '
! 'blanks after %s: %r' %
(lineno, self.name, self._PS1, line))
--- 516,529 ----
if m is None:
continue
+ # line is a PS1 line.
j = m.end(0) # beyond the prompt
if isEmpty(line, j) or isComment(line, j):
# a bare prompt or comment -- not interesting
continue
+ # line is a non-trivial PS1 line.
lineno = i - 1
if line[j] != " ":
raise ValueError('line %r of the docstring for %s lacks '
! 'blank after %s: %r' %
(lineno, self.name, self._PS1, line))
***************
*** 542,551 ****
else:
break
if len(source) == 1:
source = source[0]
else:
- # get rid of useless null line from trailing empty "..."
- if source[-1] == "":
- del source[-1]
source = "\n".join(source) + "\n"
# suck up response
--- 545,555 ----
else:
break
+ # get rid of useless null line from trailing empty "..."
+ if source[-1] == "":
+ assert len(source) > 1
+ del source[-1]
if len(source) == 1:
source = source[0]
else:
source = "\n".join(source) + "\n"
# suck up response
***************
*** 1161,1165 ****
# keyboard interrupts.)
try:
! exec compile(example.source, "<string>", "single",
compileflags, 1) in globs
exception = None
--- 1165,1173 ----
# keyboard interrupts.)
try:
! # If the example is a compound statement on one line,
! # like "if 1: print 2", then compile() requires a
! # trailing newline. Rather than analyze that, always
! # append one (it never hurts).
! exec compile(example.source + '\n', "<string>", "single",
compileflags, 1) in globs
exception = None
***************
*** 1967,1971 ****
Traceback (most recent call last):
[...]
! ValueError:
foo
--- 1975,1979 ----
Traceback (most recent call last):
[...]
! ValueError:
foo
More information about the Python-checkins
mailing list