[pypy-svn] r57737 - pypy/branch/garden-call-code-2/pypy/interpreter/test

pedronis at codespeak.net pedronis at codespeak.net
Mon Sep 1 22:30:44 CEST 2008


Author: pedronis
Date: Mon Sep  1 22:30:41 2008
New Revision: 57737

Modified:
   pypy/branch/garden-call-code-2/pypy/interpreter/test/test_function.py
Log:
repair tests, some new tests



Modified: pypy/branch/garden-call-code-2/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/branch/garden-call-code-2/pypy/interpreter/test/test_function.py	(original)
+++ pypy/branch/garden-call-code-2/pypy/interpreter/test/test_function.py	Mon Sep  1 22:30:41 2008
@@ -457,7 +457,36 @@
         w_meth5 = meth3.descr_method_get(space.wrap('hello'), space.w_str)
         assert space.is_w(w_meth5, w_meth3)
 
-class TestShortcuts(object): 
+class TestShortcuts(object):
+
+    def test_call_function(self):
+        space = self.space
+        
+        d = {}
+        for i in range(10):
+            args = "(" + ''.join(["a%d," % a for a in range(i)]) + ")"
+            exec """
+def f%s:
+    return %s
+""" % (args, args) in d
+            f = d['f']
+            res = f(*range(i))
+            code = PyCode._from_code(self.space, f.func_code)
+            fn = Function(self.space, code, self.space.newdict())
+
+            assert fn.code.fast_natural_arity == i                 
+            if i < 5:
+
+                 def bomb(*args):
+                     assert False, "shortcutting should have avoided this"
+
+                 code.funcrun = bomb
+                 code.funcrun_obj = bomb
+
+            args_w = map(space.wrap, range(i))            
+            w_res = space.call_function(fn, *args_w)
+            check = space.is_true(space.eq(w_res, space.wrap(res)))
+            assert check
 
     def test_fastcall(self):
         space = self.space
@@ -469,28 +498,22 @@
 
         assert fn.code.fast_natural_arity == 1
 
-        called = []
-        fastcall_1 = fn.code.fastcall_1
-        def witness_fastcall_1(space, w_func, w_arg):
-            called.append(w_func)
-            return fastcall_1(space, w_func, w_arg)
+        def bomb(*args):
+            assert False, "shortcutting should have avoided this"
 
-        fn.code.fastcall_1 = witness_fastcall_1
+        code.funcrun = bomb
+        code.funcrun_obj = bomb
 
         w_3 = space.newint(3)
         w_res = space.call_function(fn, w_3)
 
         assert w_res is w_3
-        assert called == [fn]
-
-        called = []
 
         w_res = space.appexec([fn, w_3], """(f, x):
         return f(x)
         """)
 
         assert w_res is w_3
-        assert called == [fn]
 
     def test_fastcall_method(self):
         space = self.space
@@ -502,13 +525,11 @@
 
         assert fn.code.fast_natural_arity == 2
 
-        called = []
-        fastcall_2 = fn.code.fastcall_2
-        def witness_fastcall_2(space, w_func, w_arg1, w_arg2):
-            called.append(w_func)
-            return fastcall_2(space, w_func, w_arg1, w_arg2)
+        def bomb(*args):
+            assert False, "shortcutting should have avoided this"
 
-        fn.code.fastcall_2 = witness_fastcall_2
+        code.funcrun = bomb
+        code.funcrun_obj = bomb
 
         w_3 = space.newint(3)
         w_res = space.appexec([fn, w_3], """(f, x):
@@ -521,7 +542,6 @@
         """)
 
         assert space.is_true(w_res)
-        assert called == [fn, fn]       
 
         
         



More information about the Pypy-commit mailing list