[pypy-svn] r8163 - in pypy/branch/src-pytest/pypy: . interpreter interpreter/test
hpk at codespeak.net
hpk at codespeak.net
Sat Jan 8 13:54:46 CET 2005
Author: hpk
Date: Sat Jan 8 13:54:46 2005
New Revision: 8163
Modified:
pypy/branch/src-pytest/pypy/conftest.py
pypy/branch/src-pytest/pypy/interpreter/baseobjspace.py
pypy/branch/src-pytest/pypy/interpreter/test/test_eval.py
Log:
ported interpreter/test_eval.py to pytest and therefore:
- fixed and cleaned up the pypy conftest.py test configuration.
It now uses the new setup/teardown hooks on Items
thus simplifying the create-space-magic a bit.
We might want to think about cleaner semantics where
exactly "space" gets created and bound.
- baseobjspace now has a _isequal(w_1, w_2) helper
which returns an interpreter-level boolean, to
simplify testing at interp-level:
assert space._iseq(w_1, w_2)
Modified: pypy/branch/src-pytest/pypy/conftest.py
==============================================================================
--- pypy/branch/src-pytest/pypy/conftest.py (original)
+++ pypy/branch/src-pytest/pypy/conftest.py Sat Jan 8 13:54:46 2005
@@ -78,7 +78,21 @@
class PyPyItem(py.test.Item):
# All PyPy test items catch and display OperationErrors specially.
- def execute_in_space(self, space, target, *args):
+
+ #def setup_module(self, mod):
+ # if hasattr(mod, 'objspacename'):
+ # mod.space = getttestobjspace(mod.objspacename)
+ # super(PyPyItem, self).setup_module(mod)
+
+ def setup_method(self, method):
+ base = getattr(method, 'im_self', method)
+ name = getattr(base, 'objspacename', None)
+ if name is None:
+ name = method.im_func.func_globals.get('objspacename', None)
+ base.space = gettestobjspace(name)
+ super(PyPyItem, self).setup_method(method)
+
+ def execute_appex(self, space, target, *args):
try:
target(*args)
except OperationError, e:
@@ -90,7 +104,7 @@
if 'space' in co.co_varnames[:co.co_argcount]:
name = target.func_globals.get('objspacename', None)
space = gettestobjspace(name)
- self.execute_in_space(space, target, space, *args)
+ self.execute_appex(space, target, space, *args)
else:
target(*args)
@@ -100,26 +114,19 @@
name = target.func_globals.get('objspacename', None)
space = gettestobjspace(name)
func = app2interp_temp(target, target.__name__)
- self.execute_in_space(space, func, space)
+ self.execute_appex(space, func, space)
class IntTestMethod(PyPyItem):
def execute(self, target, *args):
- name = target.func_globals.get('objspacename', None)
- if name is None:
- name = getattr(target.im_class, 'objspacename', None)
- instance = target.im_self
- instance.space = space = gettestobjspace(name)
- self.execute_in_space(space, target, *args)
+ space = target.im_self.space
+ self.execute_appex(space, target, *args)
class AppTestMethod(PyPyItem):
def execute(self, target, *args):
assert not args
- name = target.func_globals.get('objspacename', None)
- if name is None:
- name = getattr(target.im_class, 'objspacename', None)
- space = gettestobjspace(name)
+ space = target.im_self.space
func = app2interp_temp(target.im_func, target.__name__)
- self.execute_in_space(space, func, space, space.w_None)
+ self.execute_appex(space, func, space, space.w_None)
class AppClassCollector(py.test.collect.Class):
Item = AppTestMethod
Modified: pypy/branch/src-pytest/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/baseobjspace.py (original)
+++ pypy/branch/src-pytest/pypy/interpreter/baseobjspace.py Sat Jan 8 13:54:46 2005
@@ -119,6 +119,10 @@
# w_id_x = self.id(w_x)
# w_id_y = self.id(w_y)
# return self.eq(w_id_x, w_id_y)
+ #
+ def _isequal(self, w_obj1, w_obj2):
+ """ only for shortcutting purposes. """
+ return self.is_true(self.eq(w_obj1, w_obj2))
def not_(self, w_obj):
return self.wrap(not self.is_true(w_obj))
Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_eval.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_eval.py (original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_eval.py Sat Jan 8 13:54:46 2005
@@ -1,13 +1,11 @@
import autopath
-from pypy.tool import testit
from pypy.interpreter.eval import Frame, UNDEFINED
from pypy.interpreter.pycode import PyCode
-class TestFrame(testit.IntTestCase):
- def setUp(self):
- self.space = testit.objspace()
+class TestFrame:
+ def setup_method(self, method):
def c(x, y, *args):
pass
code = PyCode()._from_code(c.func_code)
@@ -15,26 +13,27 @@
def test_fast2locals(self):
w = self.space.wrap
+ space = self.space
self.f.fast2locals()
- self.assertEqual_w(self.f.w_locals, self.space.newdict([]))
+ assert space._isequal(self.f.w_locals, self.space.newdict([]))
self.f.fastlocals_w[0] = w(5)
self.f.fast2locals()
- self.assertEqual_w(self.f.w_locals, self.space.newdict([
- (w('x'), w(5))]))
+ assert space._isequal(self.f.w_locals, self.space.newdict([
+ (w('x'), w(5))]))
self.f.fastlocals_w[2] = w(7)
self.f.fast2locals()
- self.assertEqual_w(self.f.w_locals, self.space.newdict([
+ assert space._isequal(self.f.w_locals, self.space.newdict([
(w('x'), w(5)),
(w('args'), w(7))]))
def sameList(self, l1, l2):
- self.assertEqual(len(l1), len(l2))
+ assert len(l1) == len(l2)
for w_1, w_2 in zip(l1, l2):
- self.failIf((w_1 is UNDEFINED) != (w_2 is UNDEFINED))
+ assert not ((w_1 is UNDEFINED) != (w_2 is UNDEFINED))
if w_1 is not UNDEFINED:
- self.assertEqual_w(w_1, w_2)
+ assert self.space._isequal(w_1, w_2)
def test_locals2fast(self):
w = self.space.wrap
@@ -53,6 +52,3 @@
self.f.locals2fast()
self.sameList(self.f.fastlocals_w, [w(5), UNDEFINED, w(7),
UNDEFINED, UNDEFINED])
-
-if __name__ == '__main__':
- testit.main()
More information about the Pypy-commit
mailing list