[pypy-svn] r34035 - in pypy/dist/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Wed Nov 1 15:58:11 CET 2006


Author: arigo
Date: Wed Nov  1 15:58:10 2006
New Revision: 34035

Modified:
   pypy/dist/pypy/objspace/std/stdtypedef.py
   pypy/dist/pypy/objspace/std/test/test_stdobjspace.py
Log:
(pedronis, arigo)

A hack to enumerate the multimethods that a given W_XxxObject class implements.


Modified: pypy/dist/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stdtypedef.py	(original)
+++ pypy/dist/pypy/objspace/std/stdtypedef.py	Wed Nov  1 15:58:10 2006
@@ -309,3 +309,16 @@
     for multimethod in typedef.local_multimethods:
         slicemultimethod(space, multimethod, typedef, result, local=True)
     return result
+
+def multimethods_defined_on(cls):
+    """NOT_RPYTHON: enumerate the (multimethod, local_flag) for all the
+    multimethods that have an implementation whose first typed argument
+    is 'cls'.
+    """
+    from pypy.objspace.std.objspace import StdObjSpace   # XXX for now
+    typedef = cls.typedef
+    for multimethod in hack_out_multimethods(StdObjSpace.MM.__dict__):
+        if cls in multimethod.dispatch_tree:
+            yield multimethod, False
+    for multimethod in typedef.local_multimethods:
+        yield multimethod, True

Modified: pypy/dist/pypy/objspace/std/test/test_stdobjspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_stdobjspace.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_stdobjspace.py	Wed Nov  1 15:58:10 2006
@@ -22,7 +22,15 @@
         raises(OperationError,self.space.uint_w,self.space.wrap(None))
         raises(OperationError,self.space.uint_w,self.space.wrap(""))        
 
-
-    def hopeful_test_exceptions(self):
-        self.apptest("self.failUnless(issubclass(ArithmeticError, Exception))")
-        self.apptest("self.failIf(issubclass(ArithmeticError, KeyError))")
+    def test_multimethods_defined_on(self):
+        from pypy.objspace.std.stdtypedef import multimethods_defined_on
+        from pypy.objspace.std.listobject import W_ListObject
+        res = multimethods_defined_on(W_ListObject)
+        res = [(m.name, local) for (m, local) in res]
+        assert ('add', False) in res
+        assert ('lt', False) in res
+        assert ('setitem', False) in res
+        assert ('mod', False) not in res
+        assert ('pop', True) in res
+        assert ('reverse', True) in res
+        assert ('popitem', True) not in res


More information about the pypy-svn mailing list