Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_exceptions.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 226ba34bd998 |
| children | 90342f395721 |
| rev | line source |
|---|---|
| 653 | 1 # Python test set -- part 5, built-in exceptions |
| 2 | |
|
24442
226ba34bd998
Complete the absolute import patch for the test suite. All relative
Barry Warsaw <barry@python.org>
parents:
23073
diff
changeset
|
3 from test.test_support import TestFailed, TESTFN, unlink |
|
6194
cff105a3a384
Expanded r() function to handle class exceptions.
Barry Warsaw <barry@python.org>
parents:
2970
diff
changeset
|
4 from types import ClassType |
|
19437
5fec1c9a21ea
Turn OverflowWarning into an error locally, in order to make the
Guido van Rossum <guido@python.org>
parents:
19239
diff
changeset
|
5 import warnings |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
6 import sys, traceback |
|
19437
5fec1c9a21ea
Turn OverflowWarning into an error locally, in order to make the
Guido van Rossum <guido@python.org>
parents:
19239
diff
changeset
|
7 |
| 653 | 8 print '5. Built-in exceptions' |
| 9 # XXX This is not really enough, each *operation* should be tested! | |
| 10 | |
|
19239
a08d0e5861cc
reload(exceptions) should not raise an ImportError, but should act
Barry Warsaw <barry@python.org>
parents:
16398
diff
changeset
|
11 # Reloading the built-in exceptions module failed prior to Py2.2, while it |
|
a08d0e5861cc
reload(exceptions) should not raise an ImportError, but should act
Barry Warsaw <barry@python.org>
parents:
16398
diff
changeset
|
12 # should act the same as reloading built-in sys. |
|
a08d0e5861cc
reload(exceptions) should not raise an ImportError, but should act
Barry Warsaw <barry@python.org>
parents:
16398
diff
changeset
|
13 try: |
|
a08d0e5861cc
reload(exceptions) should not raise an ImportError, but should act
Barry Warsaw <barry@python.org>
parents:
16398
diff
changeset
|
14 import exceptions |
|
a08d0e5861cc
reload(exceptions) should not raise an ImportError, but should act
Barry Warsaw <barry@python.org>
parents:
16398
diff
changeset
|
15 reload(exceptions) |
|
a08d0e5861cc
reload(exceptions) should not raise an ImportError, but should act
Barry Warsaw <barry@python.org>
parents:
16398
diff
changeset
|
16 except ImportError, e: |
|
a08d0e5861cc
reload(exceptions) should not raise an ImportError, but should act
Barry Warsaw <barry@python.org>
parents:
16398
diff
changeset
|
17 raise TestFailed, e |
|
a08d0e5861cc
reload(exceptions) should not raise an ImportError, but should act
Barry Warsaw <barry@python.org>
parents:
16398
diff
changeset
|
18 |
|
12969
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
19 def test_raise_catch(exc): |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
20 try: |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
21 raise exc, "spam" |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
22 except exc, err: |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
23 buf = str(err) |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
24 try: |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
25 raise exc("spam") |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
26 except exc, err: |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
27 buf = str(err) |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
28 print buf |
|
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
29 |
|
6194
cff105a3a384
Expanded r() function to handle class exceptions.
Barry Warsaw <barry@python.org>
parents:
2970
diff
changeset
|
30 def r(thing): |
|
12969
e6b407ba4715
add minimal test of exception use. verify that each exception can be
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12758
diff
changeset
|
31 test_raise_catch(thing) |
|
14342
d41c41371dc1
Applying patch #100994 to allow JPython to use more of the standard
Barry Warsaw <barry@python.org>
parents:
13539
diff
changeset
|
32 if isinstance(thing, ClassType): |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6194
diff
changeset
|
33 print thing.__name__ |
|
6194
cff105a3a384
Expanded r() function to handle class exceptions.
Barry Warsaw <barry@python.org>
parents:
2970
diff
changeset
|
34 else: |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6194
diff
changeset
|
35 print thing |
| 653 | 36 |
| 37 r(AttributeError) | |
| 38 import sys | |
| 39 try: x = sys.undefined_attribute | |
| 40 except AttributeError: pass | |
| 41 | |
| 42 r(EOFError) | |
| 43 import sys | |
| 44 fp = open(TESTFN, 'w') | |
| 45 fp.close() | |
| 46 fp = open(TESTFN, 'r') | |
| 47 savestdin = sys.stdin | |
| 48 try: | |
| 15304 | 49 try: |
| 50 sys.stdin = fp | |
| 51 x = raw_input() | |
| 52 except EOFError: | |
| 53 pass | |
| 653 | 54 finally: |
| 15304 | 55 sys.stdin = savestdin |
| 56 fp.close() | |
| 653 | 57 |
| 58 r(IOError) | |
| 59 try: open('this file does not exist', 'r') | |
| 60 except IOError: pass | |
| 61 | |
| 62 r(ImportError) | |
| 63 try: import undefined_module | |
| 64 except ImportError: pass | |
| 65 | |
| 66 r(IndexError) | |
| 67 x = [] | |
| 68 try: a = x[10] | |
| 69 except IndexError: pass | |
| 70 | |
| 71 r(KeyError) | |
| 72 x = {} | |
| 73 try: a = x['key'] | |
| 74 except KeyError: pass | |
| 75 | |
| 76 r(KeyboardInterrupt) | |
| 77 print '(not testable in a script)' | |
| 78 | |
| 79 r(MemoryError) | |
| 80 print '(not safe to test)' | |
| 81 | |
| 82 r(NameError) | |
| 83 try: x = undefined_variable | |
| 84 except NameError: pass | |
| 85 | |
| 86 r(OverflowError) | |
|
23073
21d252028404
Tighten up some warning filters, and break some dependencies on the
Tim Peters <tim.peters@gmail.com>
parents:
21309
diff
changeset
|
87 # XXX |
|
21d252028404
Tighten up some warning filters, and break some dependencies on the
Tim Peters <tim.peters@gmail.com>
parents:
21309
diff
changeset
|
88 # Obscure: this test relies on int+int raising OverflowError if the |
|
21d252028404
Tighten up some warning filters, and break some dependencies on the
Tim Peters <tim.peters@gmail.com>
parents:
21309
diff
changeset
|
89 # ints are big enough. But ints no longer do that by default. This |
|
21d252028404
Tighten up some warning filters, and break some dependencies on the
Tim Peters <tim.peters@gmail.com>
parents:
21309
diff
changeset
|
90 # test will have to go away someday. For now, we can convert the |
|
21d252028404
Tighten up some warning filters, and break some dependencies on the
Tim Peters <tim.peters@gmail.com>
parents:
21309
diff
changeset
|
91 # transitional OverflowWarning into an error. |
|
21d252028404
Tighten up some warning filters, and break some dependencies on the
Tim Peters <tim.peters@gmail.com>
parents:
21309
diff
changeset
|
92 warnings.filterwarnings("error", "", OverflowWarning, __name__) |
| 653 | 93 x = 1 |
| 94 try: | |
| 15304 | 95 while 1: x = x+x |
| 653 | 96 except OverflowError: pass |
| 97 | |
| 98 r(RuntimeError) | |
| 99 print '(not used any more?)' | |
| 100 | |
| 101 r(SyntaxError) | |
| 2970 | 102 try: exec '/\n' |
| 653 | 103 except SyntaxError: pass |
| 104 | |
|
14472
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
105 # make sure the right exception message is raised for each of these |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
106 # code fragments: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
107 |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
108 def ckmsg(src, msg): |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
109 try: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
110 compile(src, '<fragment>', 'exec') |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
111 except SyntaxError, e: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
112 print e.msg |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
113 if e.msg == msg: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
114 print "ok" |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
115 else: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
116 print "expected:", msg |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
117 else: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
118 print "failed to get expected SyntaxError" |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
119 |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
120 s = '''\ |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
121 while 1: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
122 try: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
123 pass |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
124 finally: |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15304
diff
changeset
|
125 continue |
|
14472
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
126 ''' |
|
21309
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
127 if sys.platform.startswith('java'): |
|
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
128 print "'continue' not supported inside 'finally' clause" |
|
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
129 print "ok" |
|
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
130 else: |
|
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
131 ckmsg(s, "'continue' not supported inside 'finally' clause") |
|
14472
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
132 s = '''\ |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
133 try: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
134 continue |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
135 except: |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
136 pass |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
137 ''' |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
138 ckmsg(s, "'continue' not properly in loop") |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
139 ckmsg("continue\n", "'continue' not properly in loop") |
|
f6b86e2dc55b
Add test cases to make sure we get the right SyntaxError message for
Fred Drake <fdrake@acm.org>
parents:
14342
diff
changeset
|
140 |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
12969
diff
changeset
|
141 r(IndentationError) |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
12969
diff
changeset
|
142 |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
12969
diff
changeset
|
143 r(TabError) |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
12969
diff
changeset
|
144 # can only be tested under -tt, and is the only test for -tt |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
12969
diff
changeset
|
145 #try: compile("try:\n\t1/0\n \t1/0\nfinally:\n pass\n", '<string>', 'exec') |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
12969
diff
changeset
|
146 #except TabError: pass |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
12969
diff
changeset
|
147 #else: raise TestFailed |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
12969
diff
changeset
|
148 |
| 653 | 149 r(SystemError) |
| 150 print '(hard to reproduce)' | |
| 151 | |
| 152 r(SystemExit) | |
| 153 import sys | |
| 154 try: sys.exit(0) | |
| 155 except SystemExit: pass | |
| 156 | |
| 157 r(TypeError) | |
| 158 try: [] + () | |
| 159 except TypeError: pass | |
| 160 | |
| 161 r(ValueError) | |
| 162 try: x = chr(10000) | |
| 163 except ValueError: pass | |
| 164 | |
| 165 r(ZeroDivisionError) | |
| 166 try: x = 1/0 | |
| 167 except ZeroDivisionError: pass | |
| 168 | |
|
12758
406b0e24d62e
Added a test to catch the base class.
Barry Warsaw <barry@python.org>
parents:
7747
diff
changeset
|
169 r(Exception) |
|
406b0e24d62e
Added a test to catch the base class.
Barry Warsaw <barry@python.org>
parents:
7747
diff
changeset
|
170 try: x = 1/0 |
|
406b0e24d62e
Added a test to catch the base class.
Barry Warsaw <barry@python.org>
parents:
7747
diff
changeset
|
171 except Exception, e: pass |
|
406b0e24d62e
Added a test to catch the base class.
Barry Warsaw <barry@python.org>
parents:
7747
diff
changeset
|
172 |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
173 # test that setting an exception at the C level works even if the |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
174 # exception object can't be constructed. |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
175 |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
176 class BadException: |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
177 def __init__(self): |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
178 raise RuntimeError, "can't instantiate BadException" |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
179 |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
180 def test_capi1(): |
|
21309
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
181 import _testcapi |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
182 try: |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
183 _testcapi.raise_exception(BadException, 1) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
184 except TypeError, err: |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
185 exc, err, tb = sys.exc_info() |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
186 co = tb.tb_frame.f_code |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
187 assert co.co_name == "test_capi1" |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
188 assert co.co_filename.endswith('test_exceptions.py') |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
189 else: |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
190 print "Expected exception" |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
191 |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
192 def test_capi2(): |
|
21309
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
193 import _testcapi |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
194 try: |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
195 _testcapi.raise_exception(BadException, 0) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
196 except RuntimeError, err: |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
197 exc, err, tb = sys.exc_info() |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
198 co = tb.tb_frame.f_code |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
199 assert co.co_name == "__init__" |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
200 assert co.co_filename.endswith('test_exceptions.py') |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
201 co2 = tb.tb_frame.f_back.f_code |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
202 assert co2.co_name == "test_capi2" |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
203 else: |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
204 print "Expected exception" |
|
21309
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
205 |
|
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
206 if not sys.platform.startswith('java'): |
|
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
207 test_capi1() |
|
2607433b13e9
Enable support for jython:
Finn Bock <bckfnn@worldonline.dk>
parents:
20117
diff
changeset
|
208 test_capi2() |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19437
diff
changeset
|
209 |
| 653 | 210 unlink(TESTFN) |
