[pypy-svn] r73538 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

jandem at codespeak.net jandem at codespeak.net
Thu Apr 8 11:38:24 CEST 2010


Author: jandem
Date: Thu Apr  8 11:38:23 2010
New Revision: 73538

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/api.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py
Log:
Add test for PyString_FromFormat and fix FormatV test


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py	Thu Apr  8 11:38:23 2010
@@ -226,8 +226,8 @@
 FUNCTIONS_C = [
     'Py_FatalError', 'PyOS_snprintf', 'PyOS_vsnprintf', 'PyArg_Parse',
     'PyArg_ParseTuple', 'PyArg_UnpackTuple', 'PyArg_ParseTupleAndKeywords',
-    'PyString_FromFormatV', 'PyModule_AddObject', 'Py_BuildValue',
-    'PyTuple_Pack', 'PyErr_Format',
+    'PyString_FromFormat', 'PyString_FromFormatV', 'PyModule_AddObject', 
+    'Py_BuildValue', 'PyTuple_Pack', 'PyErr_Format',
 ]
 TYPES = {}
 GLOBALS = { # this needs to include all prebuilt pto, otherwise segfaults occur

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py	Thu Apr  8 11:38:23 2010
@@ -125,7 +125,20 @@
             }
             ''')
         res = module.test_string_format_v(1, "xyz")
-        print res
+        assert res == "bla 1 ble xyz\n"
+        
+    def test_format(self):
+        module = self.import_extension('foo', [
+            ("test_string_format", "METH_VARARGS",
+             '''
+                 return PyString_FromFormat("bla %d ble %s\\n",
+                        PyInt_AsLong(PyTuple_GetItem(args, 0)),
+                        PyString_AsString(PyTuple_GetItem(args, 1)));
+             '''
+             )
+            ])
+        res = module.test_string_format(1, "xyz")
+        assert res == "bla 1 ble xyz\n"
 
 class TestString(BaseApiTest):
     def test_string_resize(self, space, api):



More information about the Pypy-commit mailing list