Line continuations in doctests, changing files in sage/tests

55 views
Skip to first unread message

David Roe

unread,
Oct 24, 2012, 3:23:47 AM10/24/12
to sage-devel
Hi everyone,
I'm working on #12415 and am revising the methods for continuing lines.  Currently you can continue a line with the standard python ..., which looks good in standard Python doctests since it has the same length as >>>, but doesn't look at nice in Sage.  After #12415 the doctesting code will replace "....: " with "..." before passing it on to Python's doctest module.

Sage currently treats a backslash at the end of the line as a continuation character which is nonstandard but allows us to write large integers that span multiple lines.  For example:

sage: n = 7403756347956171282804679609742957314259318888\
....: 9231289084936232638972765034028266276891996419625117\
....: 8439958943305021275853701189680982867331732731089309\
....: 0055250511687706329907239638078671008609696253793465\
....: 0563796359

1.  Are there any objections to continuing to allow this backslash notation?
2.  Are there any opinions on whether we should change the format some files in sage/tests to use "....: " rather than "..." for line continuations?  The "..." continuations will continue to work so doctests pass even without this change, but it would make the formatting of the tests more readable.  On the other hand I know that many of the tests come from published books and there's value in staying exactly the same as the book.

The new doctesting code at #12415 is almost done.  Over the past week I fixed a bunch of issues and there's only one remaining that I'm aware of: a segfault that occurs if test/interrupt.pyx is tested, but only if it's not the first file being tested.  Help debugging from someone who's more versed in Sage's signal handling would be welcome.
David
http://trac.sagemath.org/sage_trac/ticket/12415

Simon King

unread,
Oct 24, 2012, 5:45:58 AM10/24/12
to sage-...@googlegroups.com
Hi David,

On 2012-10-24, David Roe <roed...@gmail.com> wrote:
> 1. Are there any objections to continuing to allow this backslash notation?

At least not from me.

> 2. Are there any opinions on whether we should change the format some
> files in sage/tests to use "....: " rather than "..." for line
> continuations?

Since "....: " is shown in interactive sessions if you define something
that spans over several lines, I'd actually appreciate to use "....: "
rather than "...". In that way, one could simply copy-and-paste when
creating a doc test.

However, it would also be nice if doc tests could simply be pasted into
an interactive session.

best regards,
Simon

David Roe

unread,
Oct 24, 2012, 6:29:55 AM10/24/12
to sage-...@googlegroups.com

I agree that this would be nice.  I recall a discussion from Sage Days 40.5 where Volker was working on upgrading IPython and there was a choice to be made between being able to paste in doctests and something else, but I don't recall the details.
David

Jason Grout

unread,
Oct 24, 2012, 10:04:12 AM10/24/12
to sage-...@googlegroups.com
On 10/24/12 5:29 AM, David Roe wrote:
>
>
> On Wed, Oct 24, 2012 at 3:45 AM, Simon King <simon...@uni-jena.de
> <mailto:simon...@uni-jena.de>> wrote:
>
> Hi David,
>
> On 2012-10-24, David Roe <roed...@gmail.com
> <mailto:roed...@gmail.com>> wrote:
> > 1. Are there any objections to continuing to allow this
> backslash notation?
>
> At least not from me.
>
> > 2. Are there any opinions on whether we should change the format
> some
> > files in sage/tests to use "....: " rather than "..." for line
> > continuations?
>
> Since "....: " is shown in interactive sessions if you define something
> that spans over several lines, I'd actually appreciate to use ".....: "
> rather than "...". In that way, one could simply copy-and-paste when
> creating a doc test.
>
> However, it would also be nice if doc tests could simply be pasted into
> an interactive session.
>
>
> I agree that this would be nice. I recall a discussion from Sage Days
> 40.5 where Volker was working on upgrading IPython and there was a
> choice to be made between being able to paste in doctests and something
> else, but I don't recall the details.

It was probably the tradeoff between automatic indentation and pasting
in lines. If you have auto indent, then pasting in lines that end in a
: mess up the indentation. IPython says that you should use %cpaste to
go into a "paste" mode, which turns off autoindentation, among other things.

By the way, I think we're about finishing up the IPython upgrade at
#12719. People are welcome to review it and test it out! I'm
particularly curious how it and this ticket interact, since both are
changing the doctest framework a bit.

Thanks,

Jason



Keshav Kini

unread,
Nov 18, 2012, 9:48:17 PM11/18/12
to sage-...@googlegroups.com
David Roe <roed...@gmail.com> writes:

> Hi everyone,
> I'm working on #12415 and am revising the methods for continuing
> lines.  Currently you can continue a line with the standard python
> ..., which looks good in standard Python doctests since it has the
> same length as >>>, but doesn't look at nice in Sage.  After #12415
> the doctesting code will replace "....: " with "..." before passing
> it on to Python's doctest module.
>
> Sage currently treats a backslash at the end of the line as a
> continuation character which is nonstandard but allows us to write
> large integers that span multiple lines.  For example:
>
> sage: n = 7403756347956171282804679609742957314259318888\
> ....: 9231289084936232638972765034028266276891996419625117\
> ....: 8439958943305021275853701189680982867331732731089309\
> ....: 0055250511687706329907239638078671008609696253793465\
> ....: 0563796359
>
> 1.  Are there any objections to continuing to allow this backslash
> notation?

No objection.

> 2.  Are there any opinions on whether we should change the format
> some files in sage/tests to use "....: " rather than "..." for line
> continuations?  The "..." continuations will continue to work so
> doctests pass even without this change, but it would make the
> formatting of the tests more readable.  On the other hand I know that
> many of the tests come from published books and there's value in
> staying exactly the same as the book.

Yes, please change this! The first trac ticket I opened, #10458, was
about changing this :)

> The new doctesting code at #12415 is almost done.  Over the past week
> I fixed a bunch of issues and there's only one remaining that I'm
> aware of: a segfault that occurs if test/interrupt.pyx is tested, but
> only if it's not the first file being tested.  Help debugging from
> someone who's more versed in Sage's signal handling would be welcome.
> David
> http://trac.sagemath.org/sage_trac/ticket/12415

Bravo! Here's hoping it gets in soon.

-Keshav

Reply all
Reply to author
Forward
0 new messages