Dag Sverre Seljebotn wrote:
> Is it ok to put doctests in Cython sources? I haven't seen anything so
> I'm wondering whether you have a policy on it or not.
I wouldn't object if you come up with meaningful doctests, but I see
little interest in running things in an interactive session, so a doctest
doesn't seem the appropriate measure to me.
> The tests I have are kind of "unit-test" based, more isolated than the
> tests going in the tests directory (in particular, they abort
> compilation right after the transform I'm testing, i.e. long before C
> serialization).
The tests in "tests/compile/" only compile, the tests in "tests/run/"
compile and run doctests. Why not add a directory "tests/transforms/" ?
> - Have a Cython/Testing directory for the test utils...
Are the test utilities so large that you really need a new source file or
even an entire package? And, since you have a Python serialiser in place -
do you really think that belongs into a test package?
> - Have a Transforms directory in Cython/Compiler containing transforms
Sounds like the right place to me.
> Basically, I now have the following running in my ForInOptimizations.py
> [1]:
>
> if __name__ == "__main__":
> from Cython.Testing.PipelineTesting import test_transform
> t = ForInOptimizations()
> test_transform("parsed", t, code = u"""
> for idx, value in enumerate(iterable):
> print idx, value
> """, expected = u"""
> idx = 0
> for value in iterable:
> print idx, value
> idx += 1
> """)
>
> This test-case is now running successfully, but placing the tests in a
> main section like that is perhaps not ideal?
No, not a good idea. Add a test class to the runtests.py that only
transforms the code, and then provide each test file with the expected
result in a string, just like the error tester does. That way, you can
still add a doctest to the source file and run the unchanged code and the
transformed code through the normal test runner to see if both work as
expected.
Something like this might work as a test layout:
------ tests/transforms/somefile.pyx -----
__doc__ = """
>>> print CODE['func']
idx = 0
for value in iterable:
print idx, value
idx += 1
>>> func()
0 0
1 1
2 2
3 3
"""
def func():
iterable = range(4)
for idx, value in enumerate(iterable):
print idx, value
------ tests/transforms/somefile.pyx -----
And then you parse the source file (see the error test class for this) and
append a serialisation of a dictionary that maps the names of all Python
functions found in the file to their transformed body, before you compile
and run the file in the test runner. Do you think that would work?
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev