From: Stefan Behnel Date: Sun, 22 Mar 2009 16:55:30 +0000 (+0100) Subject: extended test cases to check for exception __context__ in Py3 X-Git-Tag: 0.11.1.alpha~33^2~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=120364fa8a469116131c085af33e79e579bb07b1;p=cython.git extended test cases to check for exception __context__ in Py3 --- diff --git a/tests/run/funcexceptchained.pyx b/tests/run/funcexceptchained.pyx index 78c02c38..27881111 100644 --- a/tests/run/funcexceptchained.pyx +++ b/tests/run/funcexceptchained.pyx @@ -8,7 +8,13 @@ __doc__ = u""" ... except AttributeError: ... print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0]) ... try: raise KeyError -... except: print(sys.exc_info()[0] is KeyError or sys.exc_info()[0]) +... except: +... print(sys.exc_info()[0] is KeyError or sys.exc_info()[0]) +... if IS_PY3: +... print(isinstance(sys.exc_info()[1].__context__, AttributeError) +... or sys.exc_info()[1].__context__) +... else: +... print(True) ... print((IS_PY3 and sys.exc_info()[0] is AttributeError) or ... (not IS_PY3 and sys.exc_info()[0] is KeyError) or ... sys.exc_info()[0]) @@ -24,6 +30,7 @@ True True True True +True >>> print(sys.exc_info()[0]) # test_py() None @@ -32,6 +39,7 @@ True True True True +True >>> print(sys.exc_info()[0]) # test_c() None @@ -52,6 +60,7 @@ True True True True +True >>> print(sys.exc_info()[0]) # test_py2() None @@ -62,6 +71,7 @@ True True True True +True >>> print(sys.exc_info()[0]) # test_c2() None """ @@ -76,7 +86,13 @@ def test_c(outer_exc): except AttributeError: print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0]) try: raise KeyError - except: print(sys.exc_info()[0] is KeyError or sys.exc_info()[0]) + except: + print(sys.exc_info()[0] is KeyError or sys.exc_info()[0]) + if IS_PY3: + print(isinstance(sys.exc_info()[1].__context__, AttributeError) + or sys.exc_info()[1].__context__) + else: + print(True) print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0]) print(sys.exc_info()[0] is outer_exc or sys.exc_info()[0]) diff --git a/tests/run/funcexceptreplace.pyx b/tests/run/funcexceptreplace.pyx new file mode 100644 index 00000000..084df4fe --- /dev/null +++ b/tests/run/funcexceptreplace.pyx @@ -0,0 +1,18 @@ +__doc__ = u""" +>>> try: exc() +... except IndexError: +... if IS_PY3: +... print(isinstance(sys.exc_info()[1].__context__, ValueError)) +... else: +... print(True) +True +""" + +import sys +IS_PY3 = sys.version_info[0] >= 3 + +def exc(): + try: + raise ValueError + except ValueError: + raise IndexError