[pypy-svn] r16650 - pypy/release/0.7.x/pypy/doc

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Aug 26 17:49:46 CEST 2005


Author: cfbolz
Date: Fri Aug 26 17:49:45 2005
New Revision: 16650

Modified:
   pypy/release/0.7.x/pypy/doc/translation.txt
Log:
some small hints how to test external functions + example.


Modified: pypy/release/0.7.x/pypy/doc/translation.txt
==============================================================================
--- pypy/release/0.7.x/pypy/doc/translation.txt	(original)
+++ pypy/release/0.7.x/pypy/doc/translation.txt	Fri Aug 26 17:49:45 2005
@@ -1266,6 +1266,23 @@
 .. _`pypy/translator/c/extfunc.py`: ../translator/c/extfunc.py
 .. _`pypy/translator/c/src/`: ../translator/c/src/
 
+Testing
+-------
+
+It's not always trivial to properly test that all the information that is
+needed for a given external function is correct. Usually for a given function
+you test at least two different things: Once the dummy low level function by
+calling it directly. This is usually done in `pypy/rpython/module/test`_ by
+just calling the low level function with appropriately constructed arguments
+directly. In addition there should be test that actually tries to translate
+a function calling the external function to backend code, compile and run
+it. This makes sure that the annotator gets the annotation right and that the
+backend code is correct. For the C backend this is done in
+`pypy/translator/c/test/test_extfunc.py`_. 
+
+.. _`pypy/rpython/module/test`: ../rpython/module/test/
+.. _`pypy/translator/c/test/test_extfunc.py`: ../translator/c/test/test_extfunc.py
+
 
 Example
 -------
@@ -1329,6 +1346,20 @@
             }
     }
 
+One test for all this can be found in
+`pypy/translator/c/test/test_extfunc.py`_::
+
+    def test_os_open():
+        tmpfile = str(udir.join('test_os_open.txt'))
+        def does_stuff():
+            fd = os.open(tmpfile, os.O_WRONLY | os.O_CREAT, 0777)
+            return fd
+        f1 = compile(does_stuff, [])
+        fd = f1()
+        os.close(fd)
+        assert os.path.exists(tmpfile)
+
+
 .. _`mixed posix module`: ../module/posix/
 .. _`pypy/rpython/module/ll_os.py`: ../rpython/module/ll_os.py
 .. _`pypy/translator/c/src/ll_os.h`: ../translator/c/src/ll_os.h
\ No newline at end of file



More information about the Pypy-commit mailing list