[pypy-svn] r67271 - in pypy/trunk/pypy: . module/_ast/test tool/pytest tool/pytest/test
pedronis at codespeak.net
pedronis at codespeak.net
Fri Aug 28 12:18:19 CEST 2009
Author: pedronis
Date: Fri Aug 28 12:18:18 2009
New Revision: 67271
Modified:
pypy/trunk/pypy/conftest.py
pypy/trunk/pypy/module/_ast/test/test_ast.py
pypy/trunk/pypy/tool/pytest/appsupport.py
pypy/trunk/pypy/tool/pytest/test/test_appsupport.py
Log:
rework 67264, 67182
make the app-level test 'raises' have an interface which is a subset of the py.lib one,
avoids having to wrap the latter in the -A case which avoids some silliness.
adjusted test_appsupport.py
Modified: pypy/trunk/pypy/conftest.py
==============================================================================
--- pypy/trunk/pypy/conftest.py (original)
+++ pypy/trunk/pypy/conftest.py Fri Aug 28 12:18:18 2009
@@ -189,27 +189,13 @@
#
#
-def _pytest_raises_wrapper(*__args, **__kwargs):
- """Emulate the API of appsupport.pypyraises."""
- __tracebackhide__ = True
- # Horrible, nasty, terrible, hideous, ugly hack to help another one.
- if len(__args) == 2 and isinstance(__args[1], str):
- me = sys._getframe()
- them = sys._getframe(1)
- me.f_globals.update(them.f_globals)
- me.f_locals.update(them.f_locals)
- del me, them
- return py.test.raises(*__args, **__kwargs)._excinfo
-
-def ensure_pytest_builtin_helpers(helpers='skip'.split()):
+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__
- if not hasattr(__builtin__, "raises"):
- __builtin__.raises = _pytest_raises_wrapper
for helper in helpers:
if not hasattr(__builtin__, helper):
setattr(__builtin__, helper, getattr(py.test, helper))
Modified: pypy/trunk/pypy/module/_ast/test/test_ast.py
==============================================================================
--- pypy/trunk/pypy/module/_ast/test/test_ast.py (original)
+++ pypy/trunk/pypy/module/_ast/test/test_ast.py Fri Aug 28 12:18:18 2009
@@ -56,13 +56,13 @@
return compile(node, "<test>", "exec")
mod = ast.Module()
raises(AttributeError, getattr, mod, "body")
- exc = raises(TypeError, com, mod)[1]
+ exc = raises(TypeError, com, mod).value
assert str(exc) == "required attribute 'body' missing from Module"
expr = ast.Name()
expr.id = "hi"
expr.ctx = ast.Load()
expr.lineno = 4
- exc = raises(TypeError, com, ast.Module([ast.Expr(expr, 0, 0)]))[1]
+ exc = raises(TypeError, com, ast.Module([ast.Expr(expr, 0, 0)])).value
assert str(exc) == "required attribute 'col_offset' missing from Name"
def test_int(self):
@@ -156,7 +156,7 @@
assert fr.body is body
assert fr.lineno == 0
assert fr.col_offset == 1
- exc = raises(TypeError, ast.Module, 1, 2)[1]
+ exc = raises(TypeError, ast.Module, 1, 2).value
msg = str(exc)
assert msg == "Module constructor takes 0 or 1 positional arguments"
raises(AttributeError, ast.Module, nothing=23)
Modified: pypy/trunk/pypy/tool/pytest/appsupport.py
==============================================================================
--- pypy/trunk/pypy/tool/pytest/appsupport.py (original)
+++ pypy/trunk/pypy/tool/pytest/appsupport.py Fri Aug 28 12:18:18 2009
@@ -189,8 +189,17 @@
frame = space.getexecutioncontext().framestack.top()
old = frame.last_exception
frame.last_exception = err
+ if not hasattr(space, '_w_ExceptionInfo'):
+ space._w_ExceptionInfo = space.appexec([], """():
+ class _ExceptionInfo(object):
+ def __init__(self):
+ import sys
+ self.type, self.value, _ = sys.exc_info()
+
+ return _ExceptionInfo
+""")
try:
- return space.sys.call("exc_info")
+ return space.call_function(space._w_ExceptionInfo)
finally:
frame.last_exception = old
Modified: pypy/trunk/pypy/tool/pytest/test/test_appsupport.py
==============================================================================
--- pypy/trunk/pypy/tool/pytest/test/test_appsupport.py (original)
+++ pypy/trunk/pypy/tool/pytest/test/test_appsupport.py Fri Aug 28 12:18:18 2009
@@ -2,8 +2,10 @@
def app_test_raises():
info = raises(TypeError, id)
- assert info[0] is TypeError
- assert isinstance(info[1], TypeError)
+ assert info.type is TypeError
+ assert isinstance(info.value, TypeError)
x = 43
- raises(ZeroDivisionError, "x/0")
+ info = raises(ZeroDivisionError, "x/0")
+ assert info.type is ZeroDivisionError
+ assert isinstance(info.value, ZeroDivisionError)
More information about the Pypy-commit
mailing list