On Wednesday, November 16, 2016 at 8:47:04 AM UTC-5, Erik Bray wrote: > > On Wed, Nov 16, 2016 at 1:47 PM, Jan Groenewald <j...@aims.ac.za > <javascript:>> wrote: > > Hi > > > > On 16 November 2016 at 14:35, Simon King <simon...@uni-jena.de > <javascript:>> wrote: > >> > >> Hi Franco, > >> > >> On 2016-11-15, Franco Saliola <sal...@gmail.com <javascript:>> wrote: > >> > I'm wondering whether there is a way to run the doctests of a single > >> > function. > >> > >> Would indeed be nice to have. And thank you for pointing out > >> run_doctests() --- I haven't been aware of it. > > > > > > Looks like you could manually do this > > > > > https://stackoverflow.com/questions/10080157/python-is-it-possible-to-only-test-specific-functions-with-doctest-in-a-module > > > > Yes, it's certainly doable in principle. I'm surprised (though I > never tried it) that Sage's doctest runner doesn't provide a > straightforward way to do this. > I would suggest a syntax like ./sage -t <filename>:<function>, where > <function> could also be something like <classname.method>, etc. >
I agree with Erik, it certainly is doable in principle: Python's doctest module can do this for Python doctests. But it does not recognize Sage doctests. Continuing with my previous example, the obvious thing does nothing because it does not recognize the Sage doctests: sage: import doctest sage: doctest.run_docstring_examples(f.__doc__, globals()) However, if we replace "sage:" to ">>>", then it recognizes the tests and executes them: sage: x = f.__doc__.replace("sage:", ">>>") sage: doctest.run_docstring_examples(x, globals()) ********************************************************************** Line 2, in NoName Failed example: f() Expected: 42 Got: 41 This is almost reasonable for simple examples, but it is far from sufficient since the Sage doctest framework is fancier than the default doctest module (for example, there is preparsing and much more). I was hoping that someone familiar with the Sage doctest runner and the run_doctestss() function would know how to do this quickly and painlessly. Franco -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.