[pypy-svn] r28256 - pypy/dist/pypy/rpython/test

antocuni at codespeak.net antocuni at codespeak.net
Sun Jun 4 15:07:03 CEST 2006


Author: antocuni
Date: Sun Jun  4 15:07:02 2006
New Revision: 28256

Modified:
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
   pypy/dist/pypy/rpython/test/tool.py
Log:
(antocuni, nik)

Some more test for ootypesystem. Three of those skips because
ootypesystem doesn't support isinstance and hasattr, yet.



Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py	Sun Jun  4 15:07:02 2006
@@ -239,9 +239,127 @@
         assert self.interpret(f, [self.string_to_ll(str(py.magic.autopath()))]) == False
         assert self.interpret(f, [self.string_to_ll("another/unlikely/directory/name")]) == False
 
+    def test_pbc_isTrue(self):
+        class C:
+            def f(self):
+                pass
+
+        def g(obj):
+            return bool(obj)
+        def fn(neg):    
+            c = C.f
+            return g(c)
+        assert self.interpret(fn, [True])
+        def fn(neg):    
+            c = None
+            return g(c)
+        assert not self.interpret(fn, [True]) 
+
+    def test_const_isinstance(self):
+        class B(object):
+            pass
+        def f():
+            b = B()
+            return isinstance(b, B)
+        res = self.interpret(f, [])
+        assert res is True
+
+    def test_isinstance(self):
+        self._skip_oo('isinstance')
+        class A(object):
+            pass
+        class B(A):
+            pass
+        class C(A):
+            pass
+        def f(x, y):
+            if x == 1:
+                a = A()
+            elif x == 2:
+                a = B()
+            else:
+                a = C()
+            if y == 1:
+                res = isinstance(a, A)
+                cls = A
+            elif y == 2:
+                res = isinstance(a, B)
+                cls = B
+            else:
+                res = isinstance(a, C)
+                cls = C
+            return int(res) + 2 * isinstance(a, cls)
+        for x in [1, 2, 3]:
+            for y in [1, 2, 3]:
+                res = self.interpret(f, [x, y])
+                assert res == isinstance([A(), B(), C()][x-1], [A, B, C][y-1]) * 3
+
+    def test_isinstance_list(self):
+        self._skip_oo('isinstance')
+        def f(i):
+            if i == 0:
+                l = []
+            else:
+                l = None
+            return isinstance(l, list)
+        res = self.interpret(f, [0])
+        assert res is True
+        res = self.interpret(f, [1])
+        assert res is False    
+
+    def test_hasattr(self):
+        self._skip_oo('hasattr')
+        class A(object):
+            def __init__(self):
+                self.x = 42
+        def f(i):
+            a = A()
+            if i==0: return int(hasattr(A, '__init__'))
+            if i==1: return int(hasattr(A, 'y'))
+            if i==2: return int(hasattr(42, 'x'))
+        for x, y in zip(range(3), (1, 0, 0)):
+            res = self.interpret(f, [x])
+            assert res._obj.value == y
+        # hmm, would like to test against PyObj, is this the wrong place/way?
+
 
 class TestLLtype(BaseTestExtfunc, LLRtypeMixin):
     from pypy.rpython.lltypesystem.module import ll_os
+
+    def test_instantiate(self):
+        class A:
+            pass
+        def f():
+            return instantiate(A)
+        res = self.interpret(f, [])
+        assert res.super.typeptr.name[0] == 'A'
+
+    def test_instantiate_multiple(self):
+        class A:
+            pass
+        class B(A):
+            pass
+        def f(i):
+            if i == 1:
+                cls = A
+            else:
+                cls = B
+            return instantiate(cls)
+        res = self.interpret(f, [1])
+        assert res.super.typeptr.name[0] == 'A'
+        res = self.interpret(f, [2])
+        assert res.super.typeptr.name[0] == 'B'
+
+    def test_isinstance_obj(self):
+        _1 = lltype.pyobjectptr(1)
+        def f(x):
+            return isinstance(x, int)
+        res = self.interpret(f, [_1], someobjects=True)
+        assert res is True
+        _1_0 = lltype.pyobjectptr(1.0)
+        res = self.interpret(f, [_1_0], someobjects=True)
+        assert res is False
+
     
 class TestOOtype(BaseTestExtfunc, OORtypeMixin):
     from pypy.rpython.ootypesystem.module import ll_os

Modified: pypy/dist/pypy/rpython/test/tool.py
==============================================================================
--- pypy/dist/pypy/rpython/test/tool.py	(original)
+++ pypy/dist/pypy/rpython/test/tool.py	Sun Jun  4 15:07:02 2006
@@ -3,11 +3,11 @@
 from pypy.rpython.test.test_llinterp import interpret, interpret_raises
 
 class BaseRtypingTest(object):
-    def interpret(self, fn, args):
-        return interpret(fn, args, type_system=self.type_system)
+    def interpret(self, fn, args, **kwds):
+        return interpret(fn, args, type_system=self.type_system, **kwds)
 
-    def interpret_raises(self, exc, fn, args):
-        return interpret_raises(exc, fn, args, type_system=self.type_system)
+    def interpret_raises(self, exc, fn, args, **kwds):
+        return interpret_raises(exc, fn, args, type_system=self.type_system, **kwds)
 
     def _skip_oo(self, reason):
         if self.type_system == 'ootype':



More information about the Pypy-commit mailing list