[pypy-svn] r74311 - in pypy/trunk/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Sat May 1 22:59:49 CEST 2010


Author: afa
Date: Sat May  1 22:59:48 2010
New Revision: 74311

Modified:
   pypy/trunk/pypy/module/cpyext/api.py
   pypy/trunk/pypy/module/cpyext/methodobject.py
   pypy/trunk/pypy/module/cpyext/test/test_methodobject.py
Log:
Fix W_PyCMethodObject.__repr__, and write a considerable test to run it.


Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py	(original)
+++ pypy/trunk/pypy/module/cpyext/api.py	Sat May  1 22:59:48 2010
@@ -104,7 +104,8 @@
 #
 
 class ApiFunction:
-    def __init__(self, argtypes, restype, callable, borrowed, error):
+    def __init__(self, argtypes, restype, callable,
+                 borrowed=False, error=_NOT_SPECIFIED):
         self.argtypes = argtypes
         self.restype = restype
         self.functype = lltype.Ptr(lltype.FuncType(argtypes, restype))

Modified: pypy/trunk/pypy/module/cpyext/methodobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/methodobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/methodobject.py	Sat May  1 22:59:48 2010
@@ -112,7 +112,7 @@
         self.w_objclass = from_ref(space, pyo)
 
     def __repr__(self):
-        self.space.unwrap(self.descr_method_repr())
+        return self.space.unwrap(self.descr_method_repr())
 
     def descr_method_repr(self):
         return self.getrepr(self.space, "built-in method '%s' of '%s' object" % (self.name, self.w_objclass.getname(self.space, '?')))

Modified: pypy/trunk/pypy/module/cpyext/test/test_methodobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_methodobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_methodobject.py	Sat May  1 22:59:48 2010
@@ -1,5 +1,10 @@
 from pypy.module.cpyext.test.test_api import BaseApiTest
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
+from pypy.module.cpyext.methodobject import PyMethodDef
+from pypy.module.cpyext.api import ApiFunction
+from pypy.module.cpyext.pyobject import PyObject, make_ref, Py_DecRef
+from pypy.module.cpyext.methodobject import PyDescr_NewMethod
+from pypy.rpython.lltypesystem import rffi, lltype
 
 class AppTestMethodObject(AppTestCpythonExtensionBase):
     def test_call_METH(self):
@@ -59,3 +64,28 @@
         assert mod.getarg_OLD(1, 2) == (1, 2)
 
         assert mod.isCFunction(mod.getarg_O) == "getarg_O"
+
+class TestPyCMethodObject(BaseApiTest):
+    def test_repr(self, space):
+        """
+        W_PyCMethodObject has a repr string which describes it as a method
+        and gives its name and the name of its class.
+        """
+        def func(space, w_self, w_args):
+            return space.w_None
+        c_func = ApiFunction([PyObject, PyObject], PyObject, func)
+        func.api_func = c_func
+        ml = lltype.malloc(PyMethodDef, flavor='raw', zero=True)
+        namebuf = rffi.str2charp('func')
+        ml.c_ml_name = namebuf
+        ml.c_ml_meth = c_func.get_llhelper(space)
+
+        pto = make_ref(space, space.w_str)
+        method = PyDescr_NewMethod(space, pto, ml)
+
+        assert repr(method).startswith(
+            "<built-in method 'func' of 'str' object ")
+
+        Py_DecRef(space, pto)
+        rffi.free_charp(namebuf)
+        lltype.free(ml, flavor='raw')



More information about the Pypy-commit mailing list