[pypy-svn] r9111 - in pypy/branch/dist-interpapp/pypy/interpreter: . test
hpk at codespeak.net
hpk at codespeak.net
Fri Feb 11 14:54:06 CET 2005
Author: hpk
Date: Fri Feb 11 14:54:06 2005
New Revision: 9111
Modified:
pypy/branch/dist-interpapp/pypy/interpreter/gateway.py
pypy/branch/dist-interpapp/pypy/interpreter/test/test_appinterp.py
pypy/branch/dist-interpapp/pypy/interpreter/test/test_class.py
pypy/branch/dist-interpapp/pypy/interpreter/test/test_gateway.py
Log:
get rid of app2interp and app2interp_temp
alltogether.
very few tests had to be changed containing
indentation that makes live for "appdef()"
too hard: multiline source code fed to
'exec'. appdef() dumbly indents/deindents source
code on a line-by-line basis and doesn't
use the tokenizer to detect multiline strings
which should stay unmodified if we want to
be correct.
See the change to test_class.py for how you can
fix the involved indentation problem (which also
makes the test code more nicely readable).
Modified: pypy/branch/dist-interpapp/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/gateway.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/gateway.py Fri Feb 11 14:54:06 2005
@@ -467,56 +467,6 @@
w_obj, space.type(w_obj))
-class app2interp(Gateway):
- """Build a Gateway that calls 'app' at app-level."""
-
- NOT_RPYTHON_ATTRIBUTES = ['_staticcode'] + Gateway.NOT_RPYTHON_ATTRIBUTES
-
- def __init__(self, app, app_name=None):
- "NOT_RPYTHON"
- Gateway.__init__(self)
- # app must be a function whose name starts with 'app_'.
- if not isinstance(app, types.FunctionType):
- raise TypeError, "function expected, got %r instead" % app
- if app_name is None:
- if not app.func_name.startswith('app_'):
- raise ValueError, ("function name must start with 'app_'; "
- "%r does not" % app.func_name)
- app_name = app.func_name[4:]
- self.__name__ = app.func_name
- self.name = app_name
- self._staticcode = app.func_code
- self._staticglobals = app.func_globals
- self._staticdefs = list(app.func_defaults or ())
-
- def getcode(self, space):
- "NOT_RPYTHON"
- from pypy.interpreter import pycode
- code = pycode.PyCode(space)
- code._from_code(self._staticcode)
- return code
-
- def getdefaults(self, space):
- "NOT_RPYTHON"
- return [space.wrap(val) for val in self._staticdefs]
-
- def __call__(self, space, *args_w):
- # to call the Gateway as a non-method, 'space' must be explicitly
- # supplied. We build the Function object and call it.
- fn = self.get_function(space)
- return space.call_function(space.wrap(fn), *args_w)
-
- def __get__(self, obj, cls=None):
- "NOT_RPYTHON"
- if obj is None:
- return self
- else:
- space = obj.space
- w_method = space.wrap(self.get_method(obj))
- def helper_method_caller(*args_w):
- return space.call_function(w_method, *args_w)
- return helper_method_caller
-
class interp2app(Gateway):
"""Build a Gateway that calls 'f' at interp-level."""
@@ -632,12 +582,6 @@
#
# the next gateways are to be used only for
# temporary/initialization purposes
-class app2interp_temp(app2interp):
- "NOT_RPYTHON"
- def getcache(self, space):
- return self.__dict__.setdefault(space, Cache())
- # ^^^^^
- # armin suggested this
class interp2app_temp(interp2app):
"NOT_RPYTHON"
@@ -725,3 +669,29 @@
return wfuncdecl, wfastdecl, defaulthandlingsource
app2interp = appdef
+
+# for app2interp_temp (used for testing mainly) we can use *args
+class app2interp_temp(object):
+ def __init__(self, func, overridename=None):
+ """ NOT_RPYTHON """
+ self.appfunc = appdef(func, overridename)
+
+ def __get__(self, instance, cls=None):
+ """ NOT_RPYTHON """
+ return app2interp_temp_method(self.appfunc, instance)
+
+ def __call__(self, space, *args_w, **kwargs_w):
+ """ NOT_RPYTHON """
+ return self.appfunc(space, *args_w, **kwargs_w)
+
+class app2interp_temp_method(object):
+ def __init__(self, func, instance):
+ """ NOT_RPYTHON """
+ self.func = func
+ self.instance = instance
+
+ def __call__(self, *args_w, **kwargs_w):
+ """ NOT_RPYTHON """
+ space = self.instance.space
+ return self.appfunc(space, space.wrap(self.instance),
+ *args_w, **kwargs_w)
Modified: pypy/branch/dist-interpapp/pypy/interpreter/test/test_appinterp.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/test/test_appinterp.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/test/test_appinterp.py Fri Feb 11 14:54:06 2005
@@ -69,5 +69,14 @@
app = appdef(somefunc)
w_result = app(space)
assert space.eq_w(w_result, space.wrap(42))
+
+def app_test_something_at_app_level():
+ x = 2
+ assert x/2 == 1
+class AppTestMethods:
+ def test_somee_app_test_method(self):
+ assert 2 == 2
+
+
Modified: pypy/branch/dist-interpapp/pypy/interpreter/test/test_class.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/test/test_class.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/test/test_class.py Fri Feb 11 14:54:06 2005
@@ -30,15 +30,14 @@
def test_metaclass_global(self):
d = {}
- metatest_text = """
-class M(type):
- pass
-
-__metaclass__ = M
-
-class C:
- pass
-"""
+ metatest_text = """if 1:
+ class M(type):
+ pass
+
+ __metaclass__ = M
+
+ class C:
+ pass\n"""
exec metatest_text in d
C = d['C']
M = d['M']
Modified: pypy/branch/dist-interpapp/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/test/test_gateway.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/test/test_gateway.py Fri Feb 11 14:54:06 2005
@@ -1,6 +1,7 @@
import autopath
from pypy.interpreter import gateway
+import py
class TestBuiltinCode:
def test_signature(self):
@@ -55,6 +56,11 @@
class TestGateway:
+
+ def setup_method(self, method):
+ name = method.im_func.func_name
+ if name in ('test_importall', 'test_exportall'):
+ py.test.skip("sharing globals for app2interp'ed functions not supported")
def test_app2interp(self):
w = self.space.wrap
def app_g3(a, b):
More information about the Pypy-commit
mailing list