Commit 120364fa authored by Stefan Behnel's avatar Stefan Behnel

extended test cases to check for exception __context__ in Py3

parent 4b446b49
......@@ -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])
......
__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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment