Dag Sverre Seljebotn wrote:
> Sébastien Barthélemy wrote:
>> Hello,
>>
>> I'm converting some python modules to cython ones. The original
>> function have doctests which I would obviously like to keep. However,
>> if I just let them in the pyx file (in def-ed and cpdef-ed functions
>> docstrings), doctest does not find them.
>>
>> However, each function doctstring (myfunction.__doc__) seems fine.
>>
>> Does-it mean that doctest parses the source file instead of using the
>> docstring from the python runtime? Or am I mistaken?
>>
> This is a problem with doctest, which uses inspect.is_function to
> check whether something is a function, which fails for Cython
> functions (which instead answer to inspect.is_builtin). It would be
> nice if someone would take this to the doctest list with a patch at
> some point...
>
> There are various hackaround we could do in Cython, including wrapping
> every function in a dummy Python-interpreted function (speed loss
> though?) or have a directive to generate a __test__ dictionary. Best
> thing is probably to fix doctest but it takes ages before a patch
> there gets to our users even if it is accepted (Python 3.2?).
>
> To get a solution right away, this is what I do to invoke testing on a
> module "cmbutils":
>
> import cmbutils
> import doctest
> import inspect
> cmbutils.__test__ = {}
> for name in dir(cmbutils):
> value = getattr(cmbutils, name)
> if inspect.isbuiltin(value) and isinstance(value.__doc__, str):
> cmbutils.__test__[name] = value.__doc__
> doctest.testmod(cmbutils)
>
> You could also just set __test__ manually in the module, write a
> decorator which adds to __test__ for functions it decorates, etc.
BTW if you get that last solution to work, it would be nice if you could
take the time to add it to the FAQ :-)
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev