Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#14290 closed defect (fixed)

Running doctests from within Sage doesn't work

Reported by: roed Owned by: mvngu
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:

Description (last modified by jdemeyer)

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 roed 7 years ago.
trac_14290_ansi_escapes_indication.patch (2.6 KB) - added by vbraun 7 years ago.
Updated patch

Download all attachments as: .zip

Change History (15)

Changed 7 years ago by roed

comment:1 Changed 7 years ago by roed

  • Authors set to David Roe
  • Status changed from new to needs_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 7 years ago by roed

  • Dependencies set to #12415

comment:3 Changed 7 years ago by vbraun

  • Reviewers set to 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 7 years ago by roed

  • Description modified (diff)
  • Status changed from needs_review to positive_review

Your patch looks good too.

comment:5 Changed 7 years ago by jdemeyer

  • Dependencies changed from #12415 to #12415, #14331, #13278
  • Status changed from positive_review to needs_work

This should be rebased to #14331 + #13278.

comment:6 Changed 7 years ago by vbraun

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

comment:7 Changed 7 years ago by jdemeyer

  • Status changed from needs_work to positive_review

Agreed, I must have done something wrong.

comment:8 Changed 7 years ago by jdemeyer

  • Status changed from positive_review to needs_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 7 years ago by vbraun

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 7 years ago by vbraun

Updated patch

comment:10 Changed 7 years ago by vbraun

  • Status changed from needs_work to needs_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 7 years ago by jdemeyer

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 7 years ago by jdemeyer

  • Description modified (diff)
  • Merged in set to sage-5.9.beta2
  • Resolution set to fixed
  • Status changed from needs_review to closed

For the escape codes, see #14375.

comment:13 Changed 7 years ago by roed

  • Component changed from doctest to doctest framework
Note: See TracTickets for help on using tickets.