#10458: Doctest framework fails to parse multiline input pasted from sage
interactive prompt
---------------------------+------------------------------------------------
Reporter: kini | Owner: mvngu
Type: defect | Status: new
Priority: major | Milestone:
Component: doctest | Keywords: doctest, continuation, multiline
input, interactive prompt
Author: Keshav Kini | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
---------------------------+------------------------------------------------
Comment(by leif):
Replying to [comment:11 leif]:
> Replying to [comment:10 kini]:
> > Replying to [comment:8 leif]:
> > > I mean add the space to ''all'' prompt patterns to match (and of
course their substitutes), e.g. line 485 (it's in the comment, but not the
code) and line 613 (also in the comment on line 251).
> > >
> >
> > Ah, I see. Yes, I left those alone because changing them would change
the behavior of the doctesting framework for docstrings containing lines
like "sage:dostuff()" or "...dostuff()". Arguably the doctest framework
''shouldn't'' be allowing lines like that anyway, but at the moment it
does...
>
> Well, that's just another bug (we should fix here, too).
I've applied the following patch to (the vanilla) `sage-doctest` and all
tests passed (Sage 4.6.1.alpha3, `ptestlong`), so these changes are not
only reasonable or desirable, but also safe: ;-)
{{{
#!diff
diff --git a/sage-doctest b/sage-doctest
--- a/sage-doctest
+++ b/sage-doctest
@@ -248,7 +248,7 @@
"""
Run the preparser on the documentation string s.
This *only* preparses the input lines, i.e., those
- that begin with "sage:".or with "..."
+ that begin with "sage: ".or with "... "
"""
sl = s.lower()
@@ -260,16 +260,16 @@
last_prompt_comment = ''
for L in s.splitlines():
- begin = L.lstrip()[:5]
+ begin = L.lstrip()[:6]
comment = ''
- if begin == 'sage:':
+ if begin == 'sage: ':
c, comment = comment_modifier(L)
last_prompt_comment = comment
line = ''
if LONG_TIME in c and not long_time:
L = '\n' # extra line so output ignored
if RANDOM in c:
- L = L.replace('sage:', 'sage: print "ignore this"; ')
+ L = L.replace('sage: ', 'sage: print "ignore this"; ')
if NOT_TESTED in c:
L = '\n' # not tested
if NOT_IMPLEMENTED in c:
@@ -287,10 +287,10 @@
line += '\n' + ' '*i + 'ignore ...\n'
t.append(line)
- elif begin.startswith('...'):
+ elif begin.startswith('... '):
comment = last_prompt_comment
i = L.find('.')
- t.append(L[:i+3] + sage.misc.preparser.preparse(L[i+3:]))
+ t.append(L[:i+4] + sage.misc.preparser.preparse(L[i+4:]))
else:
comment = last_prompt_comment
@@ -380,11 +380,11 @@
j = 0
while j < len(F):
L = F[j].rstrip()
- if L.lstrip()[:5] == 'sage:':
+ if L.lstrip()[:6] == 'sage: ':
while j < len(F) and L.endswith('\\') and not
L.endswith('\\\\'):
j += 1
i += 1
- L = L[:-1] + F[j].lstrip().lstrip('...').rstrip()
+ L = L[:-1] + F[j].lstrip().lstrip('... ').rstrip()
L += '###_sage"line %s:_sage_ %s_sage"'%(i, L.strip())
j += 1
i += 1
@@ -478,8 +478,8 @@
return ''
s += test_code(os.path.abspath(file_name))
- # Allow for "sage:" instead of the traditional Python ">>>".
- s = s.replace("sage:",">>>").replace('_sage"','')
+ # Allow for "sage: " instead of the traditional Python ">>> ".
+ s = s.replace("sage: ",">>> ").replace('_sage"','')
return s
@@ -607,8 +607,8 @@
cnt += 1
if cnt > 1000:
break
- s = s.replace(':_sage_',':\n').replace('>>>','sage:')
- c = '###line [0-9]*\n'
+ s = s.replace(':_sage_',':\n').replace('>>> ','sage: ')
+ c = '###line [0-9]+\n'
r = re.compile(c)
s = r.sub('\n',s)
if cnt > 0:
}}}
(Note that there are more occurrences than I had found in your patch /
mentioned above.)
So I would suggest to [re]base your enhancement (accepting "`....: `" line
continuations) on these changes, in which case I would attach a proper
Mercurial patch for my changes.
After that we could address the "lost original source code of continuation
lines" issue, with another patch, perhaps on a follow-up ticket if you
like.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10458#comment:12>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.