Dear all,
at
http://groups.google.com/group/sage-support/browse_thread/thread/534306c87e7fac7a
I was asking about the apparently changed behaviour of "sage -t".
Georg suggested to move the discussion to sage-devel, so, here it
is...
On 20 Jun., 22:10, gsw <
GeorgSWe...@googlemail.com> wrote:
> On 20 Jun., 08:15, Simon King <
simon.k...@uni-jena.de> wrote:
> > Apparently the difference lies in Sage and not in my tests. I just
> > tried again the exact setting in which testing my extension modules
> > used to work -- now it fails, since "sage -t mtx.pyx" tries to compile
> > mtx.pyx for whatever reason.
> ...
> If I understand it correctly, the doctesting mechanism was changed, to
> be part of (or to make use of) the "load/attach" mechanism of Sage ---
> so if you can successfully "load" foobar.pyx into Sage, you also
> should be able to doctest it, with current Sage versions. But for most
> stuff which is greater than one file, the current behaviour is worse
> than it was before and is a regression IMHO.
I agree. Source code is one thing, an importable module is a
completely different thing.
Moreover: *Why* would one like to use load/attach for doc testing? I
mean, imaging a big chunk of code (in my case some 10,000 lines of
code); why should one compile it just for doing doc tests? In
particular, why *re-*compile it if the compilation of the code has
been done before?
> I could make doctesting my code (extension modules) work again in two
> hours or so mainly by inserting some of these infamous "#clib ..."
> "#cinclude ..." poor-man's pragmas I heartily dislike.
This does not look like a convenient solution.
> > Couldn't "sage -t" just take any text file, search for "sage:" prompts
> > etc, and verify the output?
... as it used to do, IIRC !
> I didn't check it, but if you move all your doctests out of a *.pyx
> file into another file --- say a *.py file with the necessary
> "import"s --- then doctesting this new file should work fine.
Sure, but it's clumsy.
> > Another idea.
>
> > Let "knight" be a (python) package or module. Is there a function
> > (say, recursive_doc_test) in Sage that does the doc tests for "knight"
> > and, recursively, for its contents (functions; classes; methods of
> > these classes; other modules, if knight is a package; ...) and returns
> > the results of the test as a string? I mean
> > sage: import knight
> > sage: recursive_doc_test(knight)
> > 'The following items had faiilures:
> > In knight.Ni.Shrubbery, l. 12:
> > expected:
> > "herring"
> > got:
> > nothing
> > ...'
>
> > The line number would refer to the 12th line in the doc string of the
> > class knight.Ni.Shrubbery, say.
I did something like that in sort of a quick hack. Also rather
clumsy:
- Recursively determine everything that is in some package/module/
class/type and retrieve the respective doc strings, so that in the end
you have a dictionary of doc strings indexed by the fully qualified
names of the things (classes, instances, functions, methods,...) they
belong to.
- For each single doc string, create a temporary file F.py. This file
contains the doc string and no code, so that it can certainly be
attached/loaded, and thus doc testing works for F.py.
- Get the results of the doc test via os.popen('sage -t F.py').read()
Advantage: I get the results of the doc tests sorted by the name of
the method/function/..., hence, if something goes wrong I can easily
locate the error.
Disadvantage: It takes a long time -- much longer than testing a
single file, since "sage -t" is called over and over again, and:
> > The disadvantage would be that "recursive_doc_test" probably couldn't
> > test cdef-methods.
>
> If inside Sage something "polished" existed as you describe it, most
> probably one *could* doctest cdef-methods with it. At least it should
> be written this way IMHO.
How could it be?
Cheers,
Simon