Commits

Maciej Fijalkowski committed 59878bf

some more support for fakeobjspace - mro of types

  • Participants
  • Parent commits b45dc15

Comments (0)

Files changed (2)

pypy/objspace/fake/objspace.py

         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):
         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
         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:
                  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,

pypy/objspace/fake/test/test_checkmodule.py

-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 = []
     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