[pypy-svn] r63226 - pypy/trunk/pypy/objspace/std/test
afa at codespeak.net
afa at codespeak.net
Mon Mar 23 13:52:39 CET 2009
Author: afa
Date: Mon Mar 23 13:52:36 2009
New Revision: 63226
Modified:
pypy/trunk/pypy/objspace/std/test/test_typeobject.py
Log:
Feature request: metaclass for types defined at interp-level.
This will be needed if we want to translate (part of) the _ctypes module.
Modified: pypy/trunk/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_typeobject.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_typeobject.py Mon Mar 23 13:52:36 2009
@@ -2,6 +2,10 @@
from pypy.objspace.std.stdtypedef import *
from pypy.conftest import gettestobjspace
+from pypy.objspace.std.typeobject import W_TypeObject
+from pypy.interpreter.gateway import interp2app
+import py
+
class TestTypeObject:
def test_not_acceptable_as_base_class(self):
@@ -57,6 +61,45 @@
space.warn = prev_warn
assert len(warnings) == 2
+ def test_metaclass_typedef(self):
+ py.test.skip("Not implemented yet")
+
+ # Define a metaclass
+ class W_MyMetaclass(W_TypeObject):
+ def f(w_self, space):
+ return space.wrap(42)
+
+ W_MyMetaclass.typedef = StdTypeDef(
+ "MyMeta",
+ W_TypeObject.typedef,
+ f=interp2app(W_MyMetaclass.f, unwrap_spec=["self", ObjSpace]),
+ )
+
+ # Define a type, instance of the above metaclass
+ class W_MyType(Wrappable):
+ pass
+
+ def MyType_descr_new(space, w_cls):
+ return space.wrap(W_MyType())
+
+ W_MyType.typedef = StdTypeDef(
+ "MyType",
+ __new__ = interp2app(MyType_descr_new),
+ )
+ W_MyType.typedef.meta = W_MyMetaclass
+
+ # Test it
+ w_mytype = self.space.gettypeobject(W_MyType.typedef)
+ self.space.appexec([w_mytype], """(MyType):
+ x = MyType()
+ assert type(x).f() == 42
+
+ class MyDerived(MyType):
+ pass
+ y = MyDerived()
+ assert type(y).f() == 42
+ """)
+
class AppTestTypeObject:
More information about the Pypy-commit
mailing list