[pypy-svn] r8001 - in pypy/branch/src-pytest/pypy: . tool
arigo at codespeak.net
arigo at codespeak.net
Mon Dec 27 16:31:52 CET 2004
Author: arigo
Date: Mon Dec 27 16:31:52 2004
New Revision: 8001
Modified:
pypy/branch/src-pytest/pypy/conftest.py
pypy/branch/src-pytest/pypy/tool/pytestsupport.py
Log:
The PyPy version of raises(), which is pushed into the space's builtins for
use by application-level tests.
Modified: pypy/branch/src-pytest/pypy/conftest.py
==============================================================================
--- pypy/branch/src-pytest/pypy/conftest.py (original)
+++ pypy/branch/src-pytest/pypy/conftest.py Mon Dec 27 16:31:52 2004
@@ -35,6 +35,8 @@
_spacecache[name] = space
space.setitem(space.w_builtins, space.wrap('AssertionError'),
pytestsupport.build_pytest_assertion(space))
+ space.setitem(space.w_builtins, space.wrap('raises'),
+ space.wrap(pytestsupport.app_raises))
return space
#
Modified: pypy/branch/src-pytest/pypy/tool/pytestsupport.py
==============================================================================
--- pypy/branch/src-pytest/pypy/tool/pytestsupport.py (original)
+++ pypy/branch/src-pytest/pypy/tool/pytestsupport.py Mon Dec 27 16:31:52 2004
@@ -2,6 +2,7 @@
import py
from py.__impl__.magic import exprinfo
from pypy.interpreter.gateway import interp2app_temp
+from pypy.interpreter.error import OperationError
# ____________________________________________________________
@@ -107,3 +108,39 @@
space.wrap('AssertionError'),
space.newtuple([w_BuiltinAssertionError]),
w_dict)
+
+def pypyraises(space, w_ExpectedException, w_expr, __args__):
+ """A built-in function providing the equivalent of py.test.raises()."""
+ args_w, kwds_w = __args__.unpack()
+ if space.is_true(space.isinstance(w_expr, space.w_str)):
+ if args_w:
+ raise OperationError(space.w_TypeError,
+ space.wrap("raises() takes no argument "
+ "after a string expression"))
+ expr = space.unwrap(w_expr)
+ source = py.code.Source(expr)
+ frame = space.executioncontext.framestack.top()
+ w_locals = frame.getdictscope()
+ w_locals = space.call_method(w_locals, 'copy')
+ for key, w_value in kwds_w.items():
+ space.setitem(w_locals, space.wrap(key), w_value)
+ try:
+ space.call_method(space.w_builtin, 'eval',
+ space.wrap(str(source)),
+ frame.w_globals,
+ w_locals)
+ except OperationError, e:
+ if e.match(space, w_ExpectedException):
+ return space.sys.exc_info()
+ raise
+ else:
+ try:
+ space.call_args(w_expr, __args__)
+ except OperationError, e:
+ if e.match(space, w_ExpectedException):
+ return space.sys.exc_info()
+ raise
+ raise OperationError(space.w_AssertionError,
+ space.wrap("DID NOT RAISE"))
+
+app_raises = interp2app_temp(pypyraises)
More information about the Pypy-commit
mailing list