Cython has moved to github.

cython-devel

view tests/run/funcexceptchained.pyx @ 1622:4f0327bdebc9

test for temp allocation bug in call
author Robert Bradshaw <robertwb@math.washington.edu>
date Sat Jan 17 01:25:34 2009 -0800 (3 years ago)
parents
children eb4cf5d094a5
line source
1 __doc__ = u"""
2 >>> import sys
3 >>> if not IS_PY3: sys.exc_clear()
5 >>> def test_py(outer_exc):
6 ... try:
7 ... raise AttributeError
8 ... except AttributeError:
9 ... print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0])
10 ... try: raise KeyError
11 ... except: print(sys.exc_info()[0] is KeyError or sys.exc_info()[0])
12 ... print((IS_PY3 and sys.exc_info()[0] is AttributeError) or
13 ... (not IS_PY3 and sys.exc_info()[0] is KeyError) or
14 ... sys.exc_info()[0])
15 ... print((IS_PY3 and sys.exc_info()[0] is outer_exc) or
16 ... (not IS_PY3 and sys.exc_info()[0] is KeyError) or
17 ... sys.exc_info()[0])
19 >>> print(sys.exc_info()[0]) # 0
20 None
22 >>> test_py(None)
23 True
24 True
25 True
26 True
27 >>> print(sys.exc_info()[0]) # test_py()
28 None
30 >>> test_c(None)
31 True
32 True
33 True
34 True
35 >>> print(sys.exc_info()[0]) # test_c()
36 None
38 >>> def test_py2():
39 ... try:
40 ... raise Exception
41 ... except Exception:
42 ... test_py(Exception)
43 ... print(sys.exc_info()[0] is Exception or sys.exc_info()[0])
44 ... print((IS_PY3 and sys.exc_info()[0] is None) or
45 ... (not IS_PY3 and sys.exc_info()[0] is Exception) or
46 ... sys.exc_info()[0])
48 >>> test_py2()
49 True
50 True
51 True
52 True
53 True
54 True
55 >>> print(sys.exc_info()[0]) # test_py2()
56 None
58 >>> test_c2()
59 True
60 True
61 True
62 True
63 True
64 True
65 >>> print(sys.exc_info()[0]) # test_c2()
66 None
67 """
69 import sys
71 IS_PY3 = sys.version_info[0] >= 3
73 def test_c(outer_exc):
74 try:
75 raise AttributeError
76 except AttributeError:
77 print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0])
78 try: raise KeyError
79 except: print(sys.exc_info()[0] is KeyError or sys.exc_info()[0])
80 print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0])
81 print(sys.exc_info()[0] is outer_exc or sys.exc_info()[0])
83 def test_c2():
84 try:
85 raise Exception
86 except Exception:
87 test_c(Exception)
88 print(sys.exc_info()[0] is Exception or sys.exc_info()[0])
89 print(sys.exc_info()[0] is None or sys.exc_info()[0])