How to doc test a show method?

0 views
Skip to first unread message

Simon King

unread,
Oct 7, 2009, 4:32:16 PM10/7/09
to sage-devel
Hi!

I have a class with a show() method. How can this be doc tested?

If there is no reasonable way to doc test a show() method: What can
one do that it does not count negatively for the doc test coverage?

Best regards,
Simon

Robert Bradshaw

unread,
Oct 7, 2009, 4:46:18 PM10/7/09
to sage-...@googlegroups.com

You can still doctest it. In doctest mode, show() should just produce
a png (or something like that) but not pop it up. We don't have a way
of telling now if it produces the correct image(s), but at least we
can make sure it doesn't raise an exception.

- Robert


Simon King

unread,
Oct 7, 2009, 4:58:53 PM10/7/09
to sage-devel
Hi Robert!

On 7 Okt., 22:46, Robert Bradshaw <rober...@math.washington.edu>
wrote:
> You can still doctest it. In doctest mode, show() should just produce  
> a png (or something like that) but not pop it up.

Very good. So I just copy-and-past the output of the Sage command line
and don't worry about the picture, then.

Thank you!
Simon

John H Palmieri

unread,
Oct 7, 2009, 7:01:33 PM10/7/09
to sage-devel
But please make sure that if you save a png, it gets saved to a
temporary directory. See #7059 for a related issue.

John

Simon King

unread,
Oct 7, 2009, 7:32:26 PM10/7/09
to sage-devel
Dear John,

On 8 Okt., 01:01, John H Palmieri <jhpalmier...@gmail.com> wrote:
> > Very good. So I just copy-and-past the output of the Sage command line
> > and don't worry about the picture, then.
>
> But please make sure that if you save a png, it gets saved to a
> temporary directory.  See #7059 for a related issue.

If I save something in a doc test then I am indeed using a temporary
file. This is ubiquitous in our cohomology spkg.

However, back to the question on pictures: I understood Robert's hint
such that I do not need to explicitly produce (and save) a png. So, do
I understand correctly that
sage: show(B)
will be a valuable doc test for an instance B of a class with a show()
method?

Cheers,
Simon

Mike Hansen

unread,
Oct 8, 2009, 12:11:40 AM10/8/09
to sage-...@googlegroups.com
Hello,

On Thu, Oct 8, 2009 at 6:32 AM, Simon King <simon...@nuigalway.ie> wrote:
> However, back to the question on pictures: I understood Robert's hint
> such that I do not need to explicitly produce (and save) a png. So, do
> I understand correctly that
>   sage: show(B)
> will be a valuable doc test for an instance B of a class with a show()
> method?

It depends on how your show is implemented. There is a variable
sage.plot.plot.DOCTEST_MODE which is set to True if things are running
in a doctest. The show method on Graphics objects knows about this
and will produce a PNG. If your show implementation calls
Graphics.show, then you don't need to do anything; otherwise, you'll
probably want to save a temporary PNG of DOCTEST_MODE is set to True.

--Mike

Simon King

unread,
Oct 8, 2009, 3:24:14 AM10/8/09
to sage-devel
Hi Mike!

On Oct 8, 5:11 am, Mike Hansen <mhan...@gmail.com> wrote:
> It depends on how your show is implemented.  There is a variable
> sage.plot.plot.DOCTEST_MODE which is set to True if things are running
> in a doctest.  The show method on Graphics objects knows about this
> and will produce a PNG.  If your show implementation calls
> Graphics.show, then you don't need to do anything; otherwise, you'll
> probably want to save a temporary PNG of DOCTEST_MODE is set to True.

Good that you mention this. In fact, my show() method returns a
graphic object. So, if I say "show(G)" or "G.show()" then a picture
pops up.

But I understand your statement that the show() method is supposed to
return None and invoke Graphics.show() internally.

So, is it bad if my show() returns a graphic object?

Cheers,
Simon

Simon King

unread,
Oct 8, 2009, 6:19:58 AM10/8/09
to sage-devel
Hi!

On Oct 8, 8:24 am, Simon King <simon.k...@nuigalway.ie> wrote:
[...]
> So, is it bad if my show() returns a graphic object?

I meanwhile changed to returning None and invoking the show() method
of the internally created graphic object, rather than returning the
graphic object.

However, as Mike pointed out on
http://groups.google.com/group/sage-devel/browse_thread/thread/be49dc0fdd27f138
plotting is a known issue on Intel Mac (e.g., bsd.math). So, how to
deal with it? Simply mentioning in SPKG.txt that the failing doc test
is a known issue?

Cheers,
Simon
Reply all
Reply to author
Forward
0 new messages