Cython has moved to github.
cython-devel
view tests/run/funcexceptcypy.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 | 421a3edf1abf |
| children |
line source
1 __doc__ = u"""
2 >>> import sys
3 >>> if not IS_PY3: sys.exc_clear()
5 >>> def test_py():
6 ... old_exc = sys.exc_info()[0]
7 ... try:
8 ... raise AttributeError("test")
9 ... except AttributeError:
10 ... test_c(error=AttributeError)
11 ... print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0])
12 ... print((IS_PY3 and sys.exc_info()[0] is old_exc) or
13 ... (not IS_PY3 and sys.exc_info()[0] is AttributeError) or
14 ... sys.exc_info()[0])
16 >>> print(sys.exc_info()[0]) # 0
17 None
18 >>> test_py()
19 True
20 True
21 True
22 True
24 >>> print(sys.exc_info()[0]) # test_py()
25 None
27 >>> test_c(test_py)
28 True
29 True
30 True
31 True
32 True
33 True
35 >>> print(sys.exc_info()[0]) # test_c()
36 None
38 >>> def test_raise():
39 ... raise TestException("test")
40 >>> test_catch(test_raise, TestException)
41 True
42 None
43 """
45 import sys
46 IS_PY3 = sys.version_info[0] >= 3
48 class TestException(Exception):
49 pass
51 def test_c(func=None, error=None):
52 try:
53 raise TestException(u"test")
54 except TestException:
55 if func:
56 func()
57 print(sys.exc_info()[0] is TestException or sys.exc_info()[0])
58 print(sys.exc_info()[0] is error or sys.exc_info()[0])
60 def test_catch(func, error):
61 try:
62 func()
63 except error:
64 print(sys.exc_info()[0] is error or sys.exc_info()[0])
65 print(sys.exc_info()[0] is error or sys.exc_info()[0])
