On Thursday, November 17, 2016 at 2:04:10 PM UTC, Franco Saliola wrote: > > > Hello David! > > On Wednesday, November 16, 2016 at 5:19:18 PM UTC-5, David Roe wrote: >> >> It's certainly doable, though an initial attempt needs a bit more work (I >> have to go teach now, so taking a break). >> >> What scope do we want to support? Running doctests on an object that has >> a __doc__ attribute is certainly possible, though getting line numbers to >> match what's expected will take some work. Supporting testing a single >> function or class through the command line should also be possible, but >> would go through a different code path. The key files to look at are >> sage.doctest.sources, especially the classes StringDocTestSource and >> FileDocTestSource, and sage.doctest.control, especially >> DocTestController.expand_files_into_sources and run_doctests. >> > > Thanks for this information. > > As for the scope: > > - As a first step, it would be great to be able to have run_doctests(obj) run > all the doctests in obj.__doc__. I agree that matching line numbers would > be really tricky; in fact, I'm not even sure what I would expect for the > line numbers (relative to the docstring, or relative to the file containing > the function). > > - Then we need a decision about what happens when one executes > run_doctests(cls): either just run the doctests in cls.__doc__; or run all > those doctests as well as the doctests from the class's methods. I think > the second option would be a best, since one can run the doctests of a > specific method with run_doctests(cls.method). > > One can have an optional parameter doing this choice for the user.
> - Thinking about doctests, it would also be great to be able to run all > the doctests in a Sage notebook. And maybe add a "Run Doctests" button to > the notebook interface. This functionality can be built on top of the > previous functions, and should be saved for a different patch. > It does not look we have manpower to maintain sagenb properly, leave alone adding new features. On the other hand perhaps jupyter notebook is sufficiently flexible for this purpose, I don't know. This looks like a reasonable feature, be it Sage or plain Python. > > Hope you had a good class. > > Franco > > > >> On Wed, Nov 16, 2016 at 2:18 PM, Franco Saliola <sal...@gmail.com> wrote: >> >>> >>> >>> 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> >>>> wrote: >>>> > Hi >>>> > >>>> > On 16 November 2016 at 14:35, Simon King <simon...@uni-jena.de> >>>> wrote: >>>> >> >>>> >> Hi Franco, >>>> >> >>>> >> On 2016-11-15, Franco Saliola <sal...@gmail.com> 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+...@googlegroups.com. >>> To post to this group, send email to sage-...@googlegroups.com. >>> Visit this group at https://groups.google.com/group/sage-devel. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- 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.