1 # Python test set -- part 5, built-in exceptions
3 from test_support
import *
4 from types
import ClassType
6 print '5. Built-in exceptions'
7 # XXX This is not really enough, each *operation* should be tested!
9 def test_raise_catch(exc
):
21 test_raise_catch(thing
)
22 if isinstance(thing
, ClassType
):
29 try: x
= sys
.undefined_attribute
30 except AttributeError: pass
34 fp
= open(TESTFN
, 'w')
36 fp
= open(TESTFN
, 'r')
49 try: open('this file does not exist', 'r')
53 try: import undefined_module
54 except ImportError: pass
59 except IndexError: pass
67 print '(not testable in a script)'
70 print '(not safe to test)'
73 try: x
= undefined_variable
74 except NameError: pass
80 except OverflowError: pass
83 print '(not used any more?)'
87 except SyntaxError: pass
89 # make sure the right exception message is raised for each of these
94 compile(src
, '<fragment>', 'exec')
95 except SyntaxError, e
:
100 print "expected:", msg
102 print "failed to get expected SyntaxError"
111 ckmsg(s
, "'continue' not supported inside 'finally' clause")
118 ckmsg(s
, "'continue' not properly in loop")
119 ckmsg("continue\n", "'continue' not properly in loop")
124 # can only be tested under -tt, and is the only test for -tt
125 #try: compile("try:\n\t1/0\n \t1/0\nfinally:\n pass\n", '<string>', 'exec')
126 #except TabError: pass
127 #else: raise TestFailed
130 print '(hard to reproduce)'
135 except SystemExit: pass
139 except TypeError: pass
143 except ValueError: pass
147 except ZeroDivisionError: pass
151 except Exception, e
: pass