Commits

Hakan Ardo committed 3b4c00b

hg merge default

Comments (0)

Files changed (2)

-import py, sys, os
+import py, sys, os, textwrap, types
 from pypy.interpreter.gateway import app2interp_temp
 from pypy.interpreter.error import OperationError
+from pypy.interpreter.function import Method
 from pypy.tool.pytest import appsupport
 from pypy.tool.option import make_config, make_objspace
 from pypy.config.config import ConflictConfigError
 rsyncdirs = ['.', '../lib-python', '../lib_pypy', '../demo']
 rsyncignore = ['_cache']
 
-# PyPy's command line extra options (these are added 
-# to py.test's standard options) 
+# PyPy's command line extra options (these are added
+# to py.test's standard options)
 #
 
 def _set_platform(opt, opt_str, value, parser):
 
 _SPACECACHE={}
 def gettestobjspace(name=None, **kwds):
-    """ helper for instantiating and caching space's for testing. 
-    """ 
+    """ helper for instantiating and caching space's for testing.
+    """
     try:
         config = make_config(option, objspace=name, **kwds)
     except ConflictConfigError, e:
     except AttributeError:
         pass
 
-# 
-# Interfacing/Integrating with py.test's collection process 
+#
+# Interfacing/Integrating with py.test's collection process
 #
 #
 
 def ensure_pytest_builtin_helpers(helpers='skip raises'.split()):
     """ hack (py.test.) raises and skip into builtins, needed
-        for applevel tests to run directly on cpython but 
+        for applevel tests to run directly on cpython but
         apparently earlier on "raises" was already added
-        to module's globals. 
-    """ 
+        to module's globals.
+    """
     import __builtin__
-    for helper in helpers: 
+    for helper in helpers:
         if not hasattr(__builtin__, helper):
             setattr(__builtin__, helper, getattr(py.test, helper))
 
 def pytest_pycollect_makemodule(path, parent):
     return PyPyModule(path, parent)
 
-class PyPyModule(py.test.collect.Module): 
-    """ we take care of collecting classes both at app level 
-        and at interp-level (because we need to stick a space 
-        at the class) ourselves. 
-    """    
+class PyPyModule(py.test.collect.Module):
+    """ we take care of collecting classes both at app level
+        and at interp-level (because we need to stick a space
+        at the class) ourselves.
+    """
     def __init__(self, *args, **kwargs):
         if hasattr(sys, 'pypy_objspaceclass'):
             option.conf_iocapture = "sys" # pypy cannot do FD-based
         #    return True
         return False
 
-    def setup(self): 
+    def setup(self):
         # stick py.test raise in module globals -- carefully
-        ensure_pytest_builtin_helpers() 
-        super(PyPyModule, self).setup() 
-        #    if hasattr(mod, 'objspacename'): 
+        ensure_pytest_builtin_helpers()
+        super(PyPyModule, self).setup()
+        #    if hasattr(mod, 'objspacename'):
         #        mod.space = getttestobjspace(mod.objspacename)
 
-    def makeitem(self, name, obj): 
-        if isclass(obj) and self.classnamefilter(name): 
-            if name.startswith('AppTest'): 
+    def makeitem(self, name, obj):
+        if isclass(obj) and self.classnamefilter(name):
+            if name.startswith('AppTest'):
                 return AppClassCollector(name, parent=self)
             elif name.startswith('ExpectTest'):
                 if option.rundirect:
             #    return AppExpectClassCollector(name, parent=self)
             else:
                 return IntClassCollector(name, parent=self)
-            
-        elif hasattr(obj, 'func_code') and self.funcnamefilter(name): 
-            if name.startswith('app_test_'): 
+
+        elif hasattr(obj, 'func_code') and self.funcnamefilter(name):
+            if name.startswith('app_test_'):
                 assert not obj.func_code.co_flags & 32, \
-                    "generator app level functions? you must be joking" 
-                return AppTestFunction(name, parent=self) 
-            elif obj.func_code.co_flags & 32: # generator function 
-                return self.Generator(name, parent=self) 
-            else: 
-                return IntTestFunction(name, parent=self) 
+                    "generator app level functions? you must be joking"
+                return AppTestFunction(name, parent=self)
+            elif obj.func_code.co_flags & 32: # generator function
+                return self.Generator(name, parent=self)
+            else:
+                return IntTestFunction(name, parent=self)
 
-def skip_on_missing_buildoption(**ropts): 
+def skip_on_missing_buildoption(**ropts):
     __tracebackhide__ = True
     import sys
     options = getattr(sys, 'pypy_translation_info', None)
         py.test.skip("not running on translated pypy "
                      "(btw, i would need options: %s)" %
                      (ropts,))
-    for opt in ropts: 
-        if not options.has_key(opt) or options[opt] != ropts[opt]: 
+    for opt in ropts:
+        if not options.has_key(opt) or options[opt] != ropts[opt]:
             break
     else:
         return
-    py.test.skip("need translated pypy with: %s, got %s" 
+    py.test.skip("need translated pypy with: %s, got %s"
                  %(ropts,options))
 
 def getwithoutbinding(x, name):
             tb = sys.exc_info()[2]
             if e.match(space, space.w_KeyboardInterrupt):
                 raise OpErrKeyboardInterrupt, OpErrKeyboardInterrupt(), tb
-            appexcinfo = appsupport.AppExceptionInfo(space, e) 
-            if appexcinfo.traceback: 
+            appexcinfo = appsupport.AppExceptionInfo(space, e)
+            if appexcinfo.traceback:
                 raise AppError, AppError(appexcinfo), tb
             raise
 
         target = self.obj
         if option.runappdirect:
             return target()
-        space = gettestobjspace() 
+        space = gettestobjspace()
         filename = self._getdynfilename(target)
         func = app2interp_temp(target, filename=filename)
         print "executing", func
         code = getattr(func, 'im_func', func).func_code
         return "[%s:%s]" % (code.co_filename, code.co_firstlineno)
 
-class AppTestMethod(AppTestFunction): 
-
-    def setup(self): 
-        super(AppTestMethod, self).setup() 
-        instance = self.parent.obj 
-        w_instance = self.parent.w_instance 
-        space = instance.space  
-        for name in dir(instance): 
-            if name.startswith('w_'): 
+class AppTestMethod(AppTestFunction):
+    def setup(self):
+        super(AppTestMethod, self).setup()
+        instance = self.parent.obj
+        w_instance = self.parent.w_instance
+        space = instance.space
+        for name in dir(instance):
+            if name.startswith('w_'):
                 if option.runappdirect:
                     # if the value is a function living on the class,
                     # don't turn it into a bound method here
                     obj = getwithoutbinding(instance, name)
                     setattr(instance, name[2:], obj)
                 else:
-                    space.setattr(w_instance, space.wrap(name[2:]), 
-                                  getattr(instance, name)) 
+                    obj = getattr(instance, name)
+                    if isinstance(obj, types.MethodType):
+                        source = py.std.inspect.getsource(obj).lstrip()
+                        w_func = space.appexec([], textwrap.dedent("""
+                        ():
+                            %s
+                            return %s
+                        """) % (source, name))
+                        w_obj = Method(space, w_func, w_instance, space.w_None)
+                    else:
+                        w_obj = obj
+                    space.setattr(w_instance, space.wrap(name[2:]), w_obj)
 
     def runtest_perform(self):
         target = self.obj
         if option.runappdirect:
             return target()
-        space = target.im_self.space 
+        space = target.im_self.space
         filename = self._getdynfilename(target)
-        func = app2interp_temp(target.im_func, filename=filename) 
-        w_instance = self.parent.w_instance 
-        self.execute_appex(space, func, space, w_instance) 
+        func = app2interp_temp(target.im_func, filename=filename)
+        w_instance = self.parent.w_instance
+        self.execute_appex(space, func, space, w_instance)
 
 class PyPyClassCollector(py.test.collect.Class):
     def setup(self):
-        cls = self.obj 
+        cls = self.obj
         if not hasattr(cls, 'spaceconfig'):
-            cls.space = LazyObjSpaceGetter() 
+            cls.space = LazyObjSpaceGetter()
         else:
             assert hasattr(cls, 'space') # set by pytest_runtest_setup
-        super(PyPyClassCollector, self).setup() 
+        super(PyPyClassCollector, self).setup()
 
 class IntInstanceCollector(py.test.collect.Instance):
-    Function = IntTestFunction 
-    
-class IntClassCollector(PyPyClassCollector): 
+    Function = IntTestFunction
+
+class IntClassCollector(PyPyClassCollector):
     Instance = IntInstanceCollector
 
     def _haskeyword(self, keyword):
     def _keywords(self):
         return super(IntClassCollector, self)._keywords() + ['interplevel']
 
-class AppClassInstance(py.test.collect.Instance): 
-    Function = AppTestMethod 
+class AppClassInstance(py.test.collect.Instance):
+    Function = AppTestMethod
 
-    def setup(self): 
-        super(AppClassInstance, self).setup()         
-        instance = self.obj 
-        space = instance.space 
-        w_class = self.parent.w_class 
+    def setup(self):
+        super(AppClassInstance, self).setup()
+        instance = self.obj
+        space = instance.space
+        w_class = self.parent.w_class
         if option.runappdirect:
             self.w_instance = instance
         else:
             self.w_instance = space.call_function(w_class)
 
-class AppClassCollector(PyPyClassCollector): 
-    Instance = AppClassInstance 
+class AppClassCollector(PyPyClassCollector):
+    Instance = AppClassInstance
 
     def _haskeyword(self, keyword):
         return keyword == 'applevel' or \
     def _keywords(self):
         return super(AppClassCollector, self)._keywords() + ['applevel']
 
-    def setup(self): 
-        super(AppClassCollector, self).setup()        
-        cls = self.obj 
-        space = cls.space 
-        clsname = cls.__name__ 
+    def setup(self):
+        super(AppClassCollector, self).setup()
+        cls = self.obj
+        space = cls.space
+        clsname = cls.__name__
         if option.runappdirect:
             w_class = cls
         else:
                                           space.wrap(clsname),
                                           space.newtuple([]),
                                           space.newdict())
-        self.w_class = w_class 
+        self.w_class = w_class
 
 class ExpectTestMethod(py.test.collect.Function):
     def safe_name(target):
 extensively). PyPy needs a CPython running on the target platform to
 bootstrap, as cross compilation is not really meant to work yet.
 At the moment you need CPython 2.4 (with ctypes) or CPython 2.5 or 2.6
-for the translation process.
+for the translation process. PyPy's JIT requires an x86 or x86_64 CPU.
 
-PyPy also basically works in a 64-bit Linux environment, but
-*it requires a 32-bit Intel CPU* for the JIT right now.  (It works
-fine in a 32-bit chroot of an Intel 64.). There is also an ongoing
-summer of code project to provide 64bit support for JIT. It's scheduled
-to be finished by end of summer 2010.
 
 ------------------------------------------------
 Which Python version (2.x?) does PyPy implement?