Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#14290 closed defect (fixed)

Running doctests from within Sage doesn't work

Reported by: David Roe Owned by: Minh Van Nguyen
Priority: major Milestone: sage-5.9
Component: doctest framework Keywords:
Cc: Merged in: sage-5.9.beta2
Authors: David Roe Reviewers: Volker Braun
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #12415, #14331, #13278 Stopgaps:

Status badges

Description (last modified by Jeroen Demeyer)

Running doctests from within Sage results in any test that has output failing. For example:

sage: run_doctests(sage.algebras.algebra)
Doctesting /Users/roed/sage/sage-5.9.beta0/devel/sage/sage/algebras/algebra.py
Running doctests with ID 2013-03-17-01-02-17-09f21e8e.
Doctesting 1 file.
sage -t /Users/roed/sage/sage-5.9.beta0/devel/sage/sage/algebras/algebra.py
**********************************************************************
File "/Users/roed/sage/sage-5.9.beta0/devel/sage/sage/algebras/algebra.py", line 29, in sage.algebras.algebra.is_Algebra
Failed example:
    is_Algebra(R)
Expected:
    True
Got:
    True
**********************************************************************
File "/Users/roed/sage/sage-5.9.beta0/devel/sage/sage/algebras/algebra.py", line 31, in sage.algebras.algebra.is_Algebra
Failed example:
    sig_on_count()
Expected:
    0
Got:
    0
**********************************************************************
1 item had failures:
   2 of   4 in sage.algebras.algebra.is_Algebra
    [3 tests, 2 failures, 0.1 s]
----------------------------------------------------------------------
sage -t /Users/roed/sage/sage-5.9.beta0/devel/sage/sage/algebras/algebra.py  # 2 doctests failed
----------------------------------------------------------------------
Total time for all tests: 0.1 seconds
    cpu time: 0.1 seconds
    cumulative wall time: 0.1 seconds

This is the result of IPython coloring the output.

Apply

Attachments (2)

14290.patch (1.1 KB) - added by David Roe 10 years ago.
trac_14290_ansi_escapes_indication.patch (2.6 KB) - added by Volker Braun 10 years ago.
Updated patch

Download all attachments as: .zip

Change History (15)

Changed 10 years ago by David Roe

Attachment: 14290.patch added

comment:1 Changed 10 years ago by David Roe

Authors: David Roe
Status: newneeds_review

I couldn't figure out a way to doctest this fix (since the problem only occurred when running doctests from IPython), but it's ready for review.

comment:2 Changed 10 years ago by David Roe

Dependencies: #12415

comment:3 Changed 10 years ago by Volker Braun

Reviewers: Volker Braun

Positive review to your patch.

I still think that it would be nice to have a note added to the diff that there were ansi escape sequences, since they don't get printed and you are otherwise just left with two identical strings which makes it non-obvious why the doctest failed. So I rescued that piece of the patch from #14359.

comment:4 Changed 10 years ago by David Roe

Description: modified (diff)
Status: needs_reviewpositive_review

Your patch looks good too.

comment:5 Changed 10 years ago by Jeroen Demeyer

Dependencies: #12415#12415, #14331, #13278
Status: positive_reviewneeds_work

This should be rebased to #14331 + #13278.

comment:6 Changed 10 years ago by Volker Braun

Patch applies cleanly here on top of sage-5.9.beta1 + #14331 + #13278.

comment:7 Changed 10 years ago by Jeroen Demeyer

Status: needs_workpositive_review

Agreed, I must have done something wrong.

comment:8 Changed 10 years ago by Jeroen Demeyer

Status: positive_reviewneeds_work

Concerning escapes: on OS X 10.8 I am seeing

\e[?1034h

(where \e stands for the escape character). Could you also check for this code (no idea what it does).

comment:9 Changed 10 years ago by Volker Braun

That is not a color code but smm = "turn meta on". Most likely coming from readline if you have the wrong TERM set.

I'll update the patch to generate better diagnostic for escape sequences.

Changed 10 years ago by Volker Braun

Updated patch

comment:10 Changed 10 years ago by Volker Braun

Status: needs_workneeds_review

The updated patch now makes all escape sequences visible (and doctestable):

EXAMPLES::

    sage: print 'This ist \x1b[1mbold\x1b[0m text'
    This ist <CSI-1m>bold<CSI-0m> text

comment:11 Changed 10 years ago by Jeroen Demeyer

What does CSI mean? I prefer to use ESC always.

Also, are you sure want to mess with \x9b? I think that won't go well with UTF-8.

comment:12 Changed 10 years ago by Jeroen Demeyer

Description: modified (diff)
Merged in: sage-5.9.beta2
Resolution: fixed
Status: needs_reviewclosed

For the escape codes, see #14375.

comment:13 Changed 10 years ago by David Roe

Component: doctestdoctest framework
Note: See TracTickets for help on using tickets.