#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:               |  
---------------------------+------------------------------------------------
Changes (by newvalueoldvalue):

  * author:  kini => Keshav Kini


Old description:

> See this [https://groups.google.com/group/sage-
> devel/browse_thread/thread/d61251f4ee1429d3 sage-devel] thread for some
> discussion about the changes proposed by this ticket.
>
> After some confusion trying to get a docstring to pass doctesting, I
> think input line continuations are "not working", in that lines directly
> pasted from the sage interpreter prompt do not pass doctests when single
> inputs span multiple lines. Pasted below is some terminal output
> (analysis continued afterwards):
>
> {{{
> kes...@esterhazy /opt/sage/devel $ cat test.rst
> EXAMPLE::
>
>     sage: [1,2,3]
>     [1, 2, 3]
>     sage: [1,
>     ....: 2,3
>     ....: ]
>     [1, 2, 3]
>     sage: x=3;\
>     ....: x
>     3
>
> kes...@esterhazy /opt/sage/devel $ sage -t -verbose test.rst
> sage -t -verbose "4.6/devel/test.rst"
> Traceback (most recent call last):
>   File "/home/keshav/.sage//tmp/.doctest_test.py", line 60, in <module>
>     runner=runner)
>   File "/opt/sage/local/bin/sagedoctest.py", line 54, in
> testmod_returning_runner
>     runner=runner)
>   File "/opt/sage/local/bin/ncadoctest.py", line 1819, in
> testmod_returning_runner
>     for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
>   File "/opt/sage/local/bin/ncadoctest.py", line 839, in find
>     self._find(tests, obj, name, module, source_lines, globs, {})
>   File "/opt/sage/local/bin/ncadoctest.py", line 893, in _find
>     globs, seen)
>   File "/opt/sage/local/bin/ncadoctest.py", line 881, in _find
>     test = self._get_test(obj, name, module, globs, source_lines)
>   File "/opt/sage/local/bin/ncadoctest.py", line 965, in _get_test
>     filename, lineno)
>   File "/opt/sage/local/bin/ncadoctest.py", line 594, in get_doctest
>     return DocTest(self.get_examples(string, name), globs,
>   File "/opt/sage/local/bin/ncadoctest.py", line 608, in get_examples
>     return [x for x in self.parse(string, name)
>   File "/opt/sage/local/bin/ncadoctest.py", line 570, in parse
>     self._parse_example(m, name, lineno)
>   File "/opt/sage/local/bin/ncadoctest.py", line 628, in _parse_example
>     self._check_prompt_blank(source_lines, indent, name, lineno)
>   File "/opt/sage/local/bin/ncadoctest.py", line 715, in
> _check_prompt_blank
>     line[indent:indent+3], line))
> ValueError: line 10 of the docstring for __main__.example_0 lacks blank
> after ...: '    ....: Integer(2),Integer(3)'
>          [3.1 s]
>
> ----------------------------------------------------------------------
> The following tests failed:
>

>         sage -t -verbose "4.6/devel/test.rst" # Exception from doctest
> framework
> Total time for all tests: 3.1 seconds
> kes...@esterhazy /opt/sage/devel $ sed "s/\.\.\.:/\.\./" test.rst >
> test2.rst
> kes...@esterhazy /opt/sage/devel $ sage -t -verbose test2.rst
> sage -t -verbose "4.6/devel/test2.rst"
> Trying:
>     set_random_seed(0L)
> Expecting nothing
> ok
> Trying:
>     change_warning_output(sys.stdout)
> Expecting nothing
> ok
> Trying:
>     [Integer(1),Integer(2),Integer(3)]###line 3:_sage_    >>> [1,2,3]
> Expecting:
>     [1, 2, 3]
> ok
> Trying:
>     [Integer(1),###line 5:_sage_    >>> [1,
>     Integer(2),Integer(3)
>     ]
> Expecting:
>     [1, 2, 3]
> ok
> Trying:
>     x=Integer(3); x###line 10:_sage_    >>> x=3; x
> Expecting:
>     3
> ok
> 3 items had no tests:
>     __main__
>     __main__.change_warning_output
>     __main__.warning_function
> 1 items passed all tests:
>    5 tests in __main__.example_0
> 5 tests in 4 items.
> 5 passed and 0 failed.
> Test passed.
>          [3.0 s]
>
> ----------------------------------------------------------------------
> All tests passed!
> Total time for all tests: 3.0 seconds
> kes...@esterhazy /opt/sage/devel $
> }}}
>

> After I replace all "....: " with "... " using `sed`, everything seems to
> work fine.
>
> It seems to me that the problem is that sage is not converting "....: "
> to "... ", which is what the standard python interactive prompt uses as a
> prefix for continued input lines. However, the sage prompt uses "....: ",
> so IMHO the doctesting framework should allow for this, so that lines
> from sage sessions can really be just dumped into a docstring without any
> further editing.

New description:

 See [http://groups.google.com/group/sage-
 devel/browse_thread/thread/d61251f4ee1429d3 this sage-devel thread] for
 some discussion about the changes proposed by this ticket.

 After some confusion trying to get a docstring to pass doctesting, I think
 input line continuations are "not working", in that lines directly pasted
 from the sage interpreter prompt do not pass doctests when single inputs
 span multiple lines. Pasted below is some terminal output (analysis
 continued afterwards):

 {{{
 kes...@esterhazy /opt/sage/devel $ cat test.rst
 EXAMPLE::

     sage: [1,2,3]
     [1, 2, 3]
     sage: [1,
     ....: 2,3
     ....: ]
     [1, 2, 3]
     sage: x=3;\
     ....: x
     3

 kes...@esterhazy /opt/sage/devel $ sage -t -verbose test.rst
 sage -t -verbose "4.6/devel/test.rst"
 Traceback (most recent call last):
   File "/home/keshav/.sage//tmp/.doctest_test.py", line 60, in <module>
     runner=runner)
   File "/opt/sage/local/bin/sagedoctest.py", line 54, in
 testmod_returning_runner
     runner=runner)
   File "/opt/sage/local/bin/ncadoctest.py", line 1819, in
 testmod_returning_runner
     for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
   File "/opt/sage/local/bin/ncadoctest.py", line 839, in find
     self._find(tests, obj, name, module, source_lines, globs, {})
   File "/opt/sage/local/bin/ncadoctest.py", line 893, in _find
     globs, seen)
   File "/opt/sage/local/bin/ncadoctest.py", line 881, in _find
     test = self._get_test(obj, name, module, globs, source_lines)
   File "/opt/sage/local/bin/ncadoctest.py", line 965, in _get_test
     filename, lineno)
   File "/opt/sage/local/bin/ncadoctest.py", line 594, in get_doctest
     return DocTest(self.get_examples(string, name), globs,
   File "/opt/sage/local/bin/ncadoctest.py", line 608, in get_examples
     return [x for x in self.parse(string, name)
   File "/opt/sage/local/bin/ncadoctest.py", line 570, in parse
     self._parse_example(m, name, lineno)
   File "/opt/sage/local/bin/ncadoctest.py", line 628, in _parse_example
     self._check_prompt_blank(source_lines, indent, name, lineno)
   File "/opt/sage/local/bin/ncadoctest.py", line 715, in
 _check_prompt_blank
     line[indent:indent+3], line))
 ValueError: line 10 of the docstring for __main__.example_0 lacks blank
 after ...: '    ....: Integer(2),Integer(3)'
          [3.1 s]

 ----------------------------------------------------------------------
 The following tests failed:


         sage -t -verbose "4.6/devel/test.rst" # Exception from doctest
 framework
 Total time for all tests: 3.1 seconds
 kes...@esterhazy /opt/sage/devel $ sed "s/\.\.\.:/\.\./" test.rst >
 test2.rst
 kes...@esterhazy /opt/sage/devel $ sage -t -verbose test2.rst
 sage -t -verbose "4.6/devel/test2.rst"
 Trying:
     set_random_seed(0L)
 Expecting nothing
 ok
 Trying:
     change_warning_output(sys.stdout)
 Expecting nothing
 ok
 Trying:
     [Integer(1),Integer(2),Integer(3)]###line 3:_sage_    >>> [1,2,3]
 Expecting:
     [1, 2, 3]
 ok
 Trying:
     [Integer(1),###line 5:_sage_    >>> [1,
     Integer(2),Integer(3)
     ]
 Expecting:
     [1, 2, 3]
 ok
 Trying:
     x=Integer(3); x###line 10:_sage_    >>> x=3; x
 Expecting:
     3
 ok
 3 items had no tests:
     __main__
     __main__.change_warning_output
     __main__.warning_function
 1 items passed all tests:
    5 tests in __main__.example_0
 5 tests in 4 items.
 5 passed and 0 failed.
 Test passed.
          [3.0 s]

 ----------------------------------------------------------------------
 All tests passed!
 Total time for all tests: 3.0 seconds
 kes...@esterhazy /opt/sage/devel $
 }}}


 After I replace all "....: " with "... " using `sed`, everything seems to
 work fine.

 It seems to me that the problem is that sage is not converting "....: " to
 "... ", which is what the standard python interactive prompt uses as a
 prefix for continued input lines. However, the sage prompt uses "....: ",
 so IMHO the doctesting framework should allow for this, so that lines from
 sage sessions can really be just dumped into a docstring without any
 further editing.

--

Comment:

 Just fixed the `https://`.

 And the ''Author(s)'' field. (This should contain the real name(s).)

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10458#comment:5>
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.

Reply via email to