On Fri, Jun 5, 2009 at 9:59 AM, Ondrej Certik<ond...@certik.cz> wrote: > Hi Toon! > > On Fri, Jun 5, 2009 at 8:09 AM, Toon > Verstraelen<toon.verstrae...@ugent.be> wrote: >> Hello, >> >> I'm writing a very initial version of a code generator. I would like to add >> proper tests for the generated c code. The test will involve a compilation >> with >> gcc and linking against a small c program that tests the output of the >> function >> for several inputs. If some outputs are wrong, the negative return code can >> be >> captured with a proper assert statement. > > Excellent, thanks for looking into this, this is needed. > >> >> I could not find existing tests that generate output files. What is the >> recommended directory to write these files? I was thinking of >> tempfile.mkdtemp, >> but that makes it annoying to check the generated code manually. A temporary >> test_output directory at the root level of the source tree with >> subdirectories >> created by the tests seems convenient to me, but this involves changes in >> setup.py, which runs the tests. './setup.py test' should create this >> directory >> and './setup.py clean' should remove it enterily. Is this OK? > > I think we should test it using statements like: > > assert code_generate(<whatever>) == """\n > int some_function(...) > { > return a*b-23; > } > """ > > That way you don't need a compiler and it will run even if gcc is not > installed or not working properly, or if you are not allowed to create > any files. Remember, that all tests need to run even if you install > sympy and then do: > > import sympy > sympy.test() > > > Besides that, it's a good idea to also have tests, that actually > compile things using gcc, as you suggested. For that, I suggest to > create a new test sympy/test_external, for example > "test_code_generation.py", that will work something like this: > > try: > <try to write a file (if it works) and find a gcc executable (I am > not sure if we should also test if gcc works here)> > except <anything from above fails>: > disabled = True > > def test_code1(): > <generate C file> > <compile it> > <run it?> > assert <all is fine> > > ... > > > That way, if gcc is not installed, or you can't generate output files, > the test will be skipped. It's the same philosophy as we use for > test_numpy and test_sage.
And to answer your question, I would just create a temporary files using tempfile.mkdtemp (and you can always leave it there if the test fails -- suggest there is some variable to control that (maybe env variable, see sympy/core/cache.py:315 for usage)). That's because the sympy root directory can be in /usr/lib/python...., which might be read only, and the current directory can also be read only. Ondrej --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---