[pypy-svn] r28946 - in pypy/dist/pypy: . interpreter/test
hpk at codespeak.net
hpk at codespeak.net
Mon Jun 19 14:37:01 CEST 2006
Author: hpk
Date: Mon Jun 19 14:37:00 2006
New Revision: 28946
Modified:
pypy/dist/pypy/conftest.py
pypy/dist/pypy/interpreter/test/test_exec.py
Log:
- unified test_exec to also pass on cpython
- (XXX?) now "raises" and "skip" are pushed to __builtin__
for PyPy test runs (unifying our applevel and interplevel
code runs some more, "raises" has already been added to
module globals earlier on by armin, but i think doing
it on builtin levels should be ok, feel free to disagree)
Modified: pypy/dist/pypy/conftest.py
==============================================================================
--- pypy/dist/pypy/conftest.py (original)
+++ pypy/dist/pypy/conftest.py Mon Jun 19 14:37:00 2006
@@ -104,6 +104,17 @@
#
# 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
+ apparently earlier on "raises" was already added
+ to module's globals.
+ """
+ import __builtin__
+ for helper in helpers:
+ if not hasattr(__builtin__, helper):
+ setattr(__builtin__, helper, getattr(py.test, helper))
class Module(py.test.collect.Module):
""" we take care of collecting classes both at app level
@@ -117,8 +128,7 @@
def setup(self):
# stick py.test raise in module globals -- carefully
- if not hasattr(self.obj, 'raises'):
- self.obj.raises = py.test.raises
+ ensure_pytest_builtin_helpers()
super(Module, self).setup()
# if hasattr(mod, 'objspacename'):
# mod.space = getttestobjspace(mod.objspacename)
Modified: pypy/dist/pypy/interpreter/test/test_exec.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_exec.py (original)
+++ pypy/dist/pypy/interpreter/test/test_exec.py Mon Jun 19 14:37:00 2006
@@ -90,8 +90,7 @@
def f():
exec 'a=3'
return a
- x = f()
- """
+ x = f()\n"""
assert x == 3
def test_specialcase_free_load2(self):
@@ -99,8 +98,7 @@
def f(a):
exec 'a=3'
return a
- x = f(4)
- """
+ x = f(4)\n"""
assert x == 3
def test_specialcase_globals_and_exec(self):
@@ -115,8 +113,7 @@
return a,b,c,d
#import dis
#dis.dis(f)
- res = f(3)
- """ in d
+ res = f(3)\n""" in d
r = d['res']
assert r == (3,2,3,42)
@@ -144,7 +141,7 @@
def f():
from sys import *
return platform
- res = f()""" in d
+ res = f()\n""" in d
import sys
assert d['res'] == sys.platform
@@ -155,7 +152,7 @@
global platform
from sys import *
return platform
- res = f()""" in d
+ res = f()\n""" in d
import sys
assert d['platform'] == 3
@@ -166,7 +163,7 @@
save = x
exec "x=3"
return x,save
- """ in d
+ \n""" in d
res = d['f']()
assert res == (3, 2)
@@ -175,7 +172,15 @@
exec "x=5 " in d
assert d['x'] == 5
+ def test_synerr(self):
+ def x():
+ exec "1 2"
+ raises(SyntaxError, x)
+
def test_mapping_as_locals(self):
+ import sys
+ if sys.version_info < (2,5) or not hasattr(sys, 'pypy_objspaceclass'):
+ skip("need CPython 2.5 or PyPy for non-dictionaries in exec statements")
class M(object):
def __getitem__(self, key):
return key
@@ -188,7 +193,3 @@
exec "y=n" in m # NOTE: this doesn't work in CPython 2.4
assert m.result == {'x': 'm', 'y': 'n'}
- def test_synerr(self):
- def x():
- exec "1 2"
- raises(SyntaxError, x)
More information about the Pypy-commit
mailing list