[pypy-svn] r10726 - py/branch/py-collect/code py/branch/py-collect/code/testing pypy/branch/pycollect-dist-pypy/pypy/tool pypy/branch/pycollect-dist-pypy/pypy/tool/test
hpk at codespeak.net
hpk at codespeak.net
Sat Apr 16 13:25:49 CEST 2005
Author: hpk
Date: Sat Apr 16 13:25:49 2005
New Revision: 10726
Modified:
py/branch/py-collect/code/excinfo.py
py/branch/py-collect/code/testing/test_excinfo.py
pypy/branch/pycollect-dist-pypy/pypy/tool/pytestsupport.py
pypy/branch/pycollect-dist-pypy/pypy/tool/test/test_pytestsupport.py
Log:
add some introspection methods to both py and pypy's
ExceptionInfo objects.
Modified: py/branch/py-collect/code/excinfo.py
==============================================================================
--- py/branch/py-collect/code/excinfo.py (original)
+++ py/branch/py-collect/code/excinfo.py Sat Apr 16 13:25:49 2005
@@ -32,6 +32,9 @@
text = text[:-1]
return text
+ def errisinstance(self, exc):
+ return isinstance(self.value, exc)
+
def __str__(self):
return self.exception_text
Modified: py/branch/py-collect/code/testing/test_excinfo.py
==============================================================================
--- py/branch/py-collect/code/testing/test_excinfo.py (original)
+++ py/branch/py-collect/code/testing/test_excinfo.py Sat Apr 16 13:25:49 2005
@@ -112,3 +112,6 @@
excinfo = py.test.raises(ValueError, h)
assert excinfo.exception_text.startswith('ValueError')
+def test_excinfo_errisinstance():
+ excinfo = py.test.raises(ValueError, h)
+ assert excinfo.errisinstance(ValueError)
Modified: pypy/branch/pycollect-dist-pypy/pypy/tool/pytestsupport.py
==============================================================================
--- pypy/branch/pycollect-dist-pypy/pypy/tool/pytestsupport.py (original)
+++ pypy/branch/pycollect-dist-pypy/pypy/tool/pytestsupport.py Sat Apr 16 13:25:49 2005
@@ -44,6 +44,21 @@
self.operr = operr
self.traceback = AppTraceback(self.operr.application_traceback)
+ def exconly(self):
+ return '(application-level) ' + self.operr.errorstr(self.space)
+
+ def errisinstance(self, exc):
+ clsname = exc.__name__
+ try:
+ w_exc = getattr(self.space, 'w_' + clsname)
+ except KeyboardInterrupt:
+ raise
+ except:
+ pass
+ else:
+ return self.operr.match(self.space, w_exc)
+ return False
+
def __str__(self):
return '(application-level) ' + self.operr.errorstr(self.space)
Modified: pypy/branch/pycollect-dist-pypy/pypy/tool/test/test_pytestsupport.py
==============================================================================
--- pypy/branch/pycollect-dist-pypy/pypy/tool/test/test_pytestsupport.py (original)
+++ pypy/branch/pycollect-dist-pypy/pypy/tool/test/test_pytestsupport.py Sat Apr 16 13:25:49 2005
@@ -5,7 +5,7 @@
from pypy.interpreter.argument import Arguments
from pypy.interpreter.pycode import PyCode
from pypy.interpreter.pyframe import PyFrame
-from pypy.tool.pytestsupport import AppFrame, build_pytest_assertion
+from pypy.tool.pytestsupport import AppFrame, build_pytest_assertion, AppExceptionInfo
def somefunc(x):
@@ -53,4 +53,18 @@
assert e.msg == "Failed"
+def test_appexecinfo(space):
+ try:
+ space.appexec([], "(): raise ValueError")
+ except OperationError, e:
+ appex = AppExceptionInfo(space, e)
+ else:
+ py.test.fail("did not raise!")
+ assert appex.exconly().find('ValueError') != -1
+ assert appex.errisinstance(ValueError)
+ assert not appex.errisinstance(RuntimeError)
+ class A:
+ pass
+ assert not appex.errisinstance(A)
+
More information about the Pypy-commit
mailing list