Author: Maciej Fijalkowski <[email protected]>
Branch: 
Changeset: r55085:59878bfec099
Date: 2012-05-14 19:31 +0200
http://bitbucket.org/pypy/pypy/changeset/59878bfec099/

Log:    some more support for fakeobjspace - mro of types

diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -55,6 +55,9 @@
         from pypy.rlib.rbigint import rbigint
         return rbigint.fromint(NonConstant(42))
 
+class W_MyType(W_MyObject):
+    def __init__(self):
+        self.mro_w = [w_some_obj(), w_some_obj()]
 
 def w_some_obj():
     if NonConstant(False):
@@ -66,6 +69,9 @@
         return None
     return w_some_obj()
 
+def w_some_type():
+    return W_MyType()
+
 def is_root(w_obj):
     assert isinstance(w_obj, W_Root)
 is_root.expecting = W_Root
@@ -220,6 +226,9 @@
         assert typedef is not None
         return self.fromcache(TypeCache).getorbuild(typedef)
 
+    def type(self, w_obj):
+        return w_some_type()
+
     def unpackiterable(self, w_iterable, expected_length=-1):
         is_root(w_iterable)
         if expected_length < 0:
@@ -287,10 +296,13 @@
                  ObjSpace.ExceptionTable +
                  ['int', 'str', 'float', 'long', 'tuple', 'list',
                   'dict', 'unicode', 'complex', 'slice', 'bool',
-                  'type', 'basestring', 'object']):
+                  'basestring', 'object']):
         setattr(FakeObjSpace, 'w_' + name, w_some_obj())
+    FakeObjSpace.w_type = w_some_type()
     #
     for (name, _, arity, _) in ObjSpace.MethodTable:
+        if name == 'type':
+            continue
         args = ['w_%d' % i for i in range(arity)]
         params = args[:]
         d = {'is_root': is_root,
diff --git a/pypy/objspace/fake/test/test_checkmodule.py 
b/pypy/objspace/fake/test/test_checkmodule.py
--- a/pypy/objspace/fake/test/test_checkmodule.py
+++ b/pypy/objspace/fake/test/test_checkmodule.py
@@ -1,9 +1,9 @@
-import py
+
 from pypy.objspace.fake.objspace import FakeObjSpace, is_root
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.interpreter.gateway import interp2app, W_Root, ObjSpace
-
+from pypy.rpython.test.test_llinterp import interpret
 
 def make_checker():
     check = []
@@ -61,3 +61,18 @@
     assert not check
     space.translates()
     assert check
+
+def test_gettype_mro_untranslated():
+    space = FakeObjSpace()
+    w_type = space.type(space.wrap(1))
+    assert len(w_type.mro_w) == 2
+
+def test_gettype_mro():
+    space = FakeObjSpace()
+
+    def f(i):
+        w_x = space.wrap(i)
+        w_type = space.type(w_x)
+        return len(w_type.mro_w)
+
+    assert interpret(f, [1]) == 2
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to