@@ -81,14 +81,6 @@ def r(thing):
8181except NameError : pass
8282
8383r (OverflowError )
84- # XXX
85- # Obscure: in 2.2 and 2.3, this test relied on changing OverflowWarning
86- # into an error, in order to trigger OverflowError. In 2.4, OverflowWarning
87- # should no longer be generated, so the focus of the test shifts to showing
88- # that OverflowError *isn't* generated. OverflowWarning should be gone
89- # in Python 2.5, and then the filterwarnings() call, and this comment,
90- # should go away.
91- warnings .filterwarnings ("error" , "" , OverflowWarning , __name__ )
9284x = 1
9385for dummy in range (128 ):
9486 x += x # this simply shouldn't blow up
@@ -206,3 +198,88 @@ def test_capi2():
206198 test_capi2 ()
207199
208200unlink (TESTFN )
201+
202+ # test that exception attributes are happy.
203+ try : str (u'Hello \u00E1 ' )
204+ except Exception , e : sampleUnicodeEncodeError = e
205+ try : unicode ('\xff ' )
206+ except Exception , e : sampleUnicodeDecodeError = e
207+ exceptionList = [
208+ ( BaseException , (), { 'message' : '' , 'args' : () }),
209+ ( BaseException , (1 , ), { 'message' : 1 , 'args' : ( 1 , ) }),
210+ ( BaseException , ('foo' , ), { 'message' : 'foo' , 'args' : ( 'foo' , ) }),
211+ ( BaseException , ('foo' , 1 ), { 'message' : '' , 'args' : ( 'foo' , 1 ) }),
212+ ( SystemExit , ('foo' ,), { 'message' : 'foo' , 'args' : ( 'foo' , ),
213+ 'code' : 'foo' }),
214+ ( IOError , ('foo' ,), { 'message' : 'foo' , 'args' : ( 'foo' , ), }),
215+ ( IOError , ('foo' , 'bar' ), { 'message' : '' ,
216+ 'args' : ('foo' , 'bar' ), }),
217+ ( IOError , ('foo' , 'bar' , 'baz' ),
218+ { 'message' : '' , 'args' : ('foo' , 'bar' ), }),
219+ ( EnvironmentError , ('errnoStr' , 'strErrorStr' , 'filenameStr' ),
220+ { 'message' : '' , 'args' : ('errnoStr' , 'strErrorStr' ),
221+ 'strerror' : 'strErrorStr' ,
222+ 'errno' : 'errnoStr' , 'filename' : 'filenameStr' }),
223+ ( EnvironmentError , (1 , 'strErrorStr' , 'filenameStr' ),
224+ { 'message' : '' , 'args' : (1 , 'strErrorStr' ),
225+ 'strerror' : 'strErrorStr' , 'errno' : 1 ,
226+ 'filename' : 'filenameStr' }),
227+ ( SyntaxError , ('msgStr' ,),
228+ { 'message' : 'msgStr' , 'args' : ('msgStr' , ),
229+ 'print_file_and_line' : None , 'msg' : 'msgStr' ,
230+ 'filename' : None , 'lineno' : None , 'offset' : None ,
231+ 'text' : None }),
232+ ( SyntaxError , ('msgStr' , ('filenameStr' , 'linenoStr' , 'offsetStr' ,
233+ 'textStr' )),
234+ { 'message' : '' , 'args' : ('msgStr' , ('filenameStr' ,
235+ 'linenoStr' , 'offsetStr' , 'textStr' )),
236+ 'print_file_and_line' : None , 'msg' : 'msgStr' ,
237+ 'filename' : 'filenameStr' , 'lineno' : 'linenoStr' ,
238+ 'offset' : 'offsetStr' , 'text' : 'textStr' }),
239+ ( SyntaxError , ('msgStr' , 'filenameStr' , 'linenoStr' , 'offsetStr' ,
240+ 'textStr' , 'print_file_and_lineStr' ),
241+ { 'message' : '' , 'args' : ('msgStr' , 'filenameStr' ,
242+ 'linenoStr' , 'offsetStr' , 'textStr' ,
243+ 'print_file_and_lineStr' ),
244+ 'print_file_and_line' : None , 'msg' : 'msgStr' ,
245+ 'filename' : None , 'lineno' : None , 'offset' : None ,
246+ 'text' : None }),
247+ ( UnicodeError , (),
248+ { 'message' : '' , 'args' : (), }),
249+ ( sampleUnicodeEncodeError ,
250+ { 'message' : '' , 'args' : ('ascii' , u'Hello \xe1 ' , 6 , 7 ,
251+ 'ordinal not in range(128)' ),
252+ 'encoding' : 'ascii' , 'object' : u'Hello \xe1 ' ,
253+ 'start' : 6 , 'reason' : 'ordinal not in range(128)' }),
254+ ( sampleUnicodeDecodeError ,
255+ { 'message' : '' , 'args' : ('ascii' , '\xff ' , 0 , 1 ,
256+ 'ordinal not in range(128)' ),
257+ 'encoding' : 'ascii' , 'object' : '\xff ' ,
258+ 'start' : 0 , 'reason' : 'ordinal not in range(128)' }),
259+ ( UnicodeTranslateError , (u"\u3042 " , 0 , 1 , "ouch" ),
260+ { 'message' : '' , 'args' : (u'\u3042 ' , 0 , 1 , 'ouch' ),
261+ 'object' : u'\u3042 ' , 'reason' : 'ouch' ,
262+ 'start' : 0 , 'end' : 1 }),
263+ ]
264+ try :
265+ exceptionList .append (
266+ ( WindowsError , (1 , 'strErrorStr' , 'filenameStr' ),
267+ { 'message' : '' , 'args' : (1 , 'strErrorStr' ),
268+ 'strerror' : 'strErrorStr' ,
269+ 'errno' : 22 , 'filename' : 'filenameStr' ,
270+ 'winerror' : 1 }))
271+ except NameError : pass
272+
273+ for args in exceptionList :
274+ expected = args [- 1 ]
275+ try :
276+ if len (args ) == 2 : raise args [0 ]
277+ else : raise apply (args [0 ], args [1 ])
278+ except BaseException , e :
279+ for checkArgName in expected .keys ():
280+ if repr (getattr (e , checkArgName )) != repr (expected [checkArgName ]):
281+ raise TestFailed ('Checking exception arguments, exception '
282+ '"%s", attribute "%s" expected %s got %s.' %
283+ ( repr (e ), checkArgName ,
284+ repr (expected [checkArgName ]),
285+ repr (getattr (e , checkArgName )) ))
0 commit comments