Commit e08940ef authored by Georg Brandl's avatar Georg Brandl

Some code style tweaks, and remove apply.

parent b9120e77
...@@ -189,69 +189,68 @@ class ExceptionTests(unittest.TestCase): ...@@ -189,69 +189,68 @@ class ExceptionTests(unittest.TestCase):
except Exception, e: sampleUnicodeDecodeError = e except Exception, e: sampleUnicodeDecodeError = e
exceptionList = [ exceptionList = [
( BaseException, (), { 'message' : '', 'args' : () }), (BaseException, (), {'message' : '', 'args' : ()}),
( BaseException, (1, ), { 'message' : 1, 'args' : ( 1, ) }), (BaseException, (1, ), {'message' : 1, 'args' : (1,)}),
( BaseException, ('foo', ), { 'message' : 'foo', 'args' : ( 'foo', ) }), (BaseException, ('foo',),
( BaseException, ('foo', 1), { 'message' : '', 'args' : ( 'foo', 1 ) }), {'message' : 'foo', 'args' : ('foo',)}),
( SystemExit, ('foo',), { 'message' : 'foo', 'args' : ( 'foo', ), (BaseException, ('foo', 1),
'code' : 'foo' }), {'message' : '', 'args' : ('foo', 1)}),
( IOError, ('foo',), { 'message' : 'foo', 'args' : ( 'foo', ), }), (SystemExit, ('foo',),
( IOError, ('foo', 'bar'), { 'message' : '', {'message' : 'foo', 'args' : ('foo',), 'code' : 'foo'}),
'args' : ('foo', 'bar'), }), (IOError, ('foo',),
( IOError, ('foo', 'bar', 'baz'), {'message' : 'foo', 'args' : ('foo',)}),
{ 'message' : '', 'args' : ('foo', 'bar'), }), (IOError, ('foo', 'bar'),
( EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'), {'message' : '', 'args' : ('foo', 'bar')}),
{ 'message' : '', 'args' : ('errnoStr', 'strErrorStr'), (IOError, ('foo', 'bar', 'baz'),
'strerror' : 'strErrorStr', {'message' : '', 'args' : ('foo', 'bar')}),
'errno' : 'errnoStr', 'filename' : 'filenameStr' }), (EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'),
( EnvironmentError, (1, 'strErrorStr', 'filenameStr'), {'message' : '', 'args' : ('errnoStr', 'strErrorStr'),
{ 'message' : '', 'args' : (1, 'strErrorStr'), 'strerror' : 'strErrorStr', 'errno' : 'errnoStr',
'strerror' : 'strErrorStr', 'errno' : 1, 'filename' : 'filenameStr'}),
'filename' : 'filenameStr' }), (EnvironmentError, (1, 'strErrorStr', 'filenameStr'),
( SyntaxError, ('msgStr',), {'message' : '', 'args' : (1, 'strErrorStr'), 'errno' : 1,
{ 'message' : 'msgStr', 'args' : ('msgStr', ), 'strerror' : 'strErrorStr', 'filename' : 'filenameStr'}),
'print_file_and_line' : None, 'msg' : 'msgStr', (SyntaxError, ('msgStr',),
'filename' : None, 'lineno' : None, 'offset' : None, {'message' : 'msgStr', 'args' : ('msgStr',), 'text' : None,
'text' : None }), 'print_file_and_line' : None, 'msg' : 'msgStr',
( SyntaxError, ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr', 'filename' : None, 'lineno' : None, 'offset' : None}),
'textStr')), (SyntaxError, ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr',
{ 'message' : '', 'args' : ('msgStr', ('filenameStr', 'textStr')),
'linenoStr', 'offsetStr', 'textStr' )), {'message' : '', 'offset' : 'offsetStr', 'text' : 'textStr',
'print_file_and_line' : None, 'msg' : 'msgStr', 'args' : ('msgStr', ('filenameStr', 'linenoStr',
'filename' : 'filenameStr', 'lineno' : 'linenoStr', 'offsetStr', 'textStr')),
'offset' : 'offsetStr', 'text' : 'textStr' }), 'print_file_and_line' : None, 'msg' : 'msgStr',
( SyntaxError, ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr', 'filename' : 'filenameStr', 'lineno' : 'linenoStr'}),
'textStr', 'print_file_and_lineStr'), (SyntaxError, ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr',
{ 'message' : '', 'args' : ('msgStr', 'filenameStr', 'textStr', 'print_file_and_lineStr'),
'linenoStr', 'offsetStr', 'textStr', {'message' : '', 'text' : None,
'print_file_and_lineStr'), 'args' : ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr',
'print_file_and_line' : None, 'msg' : 'msgStr', 'textStr', 'print_file_and_lineStr'),
'filename' : None, 'lineno' : None, 'offset' : None, 'print_file_and_line' : None, 'msg' : 'msgStr',
'text' : None }), 'filename' : None, 'lineno' : None, 'offset' : None}),
( UnicodeError, (), (UnicodeError, (), {'message' : '', 'args' : (),}),
{ 'message' : '', 'args' : (), }), (sampleUnicodeEncodeError,
( sampleUnicodeEncodeError, {'message' : '', 'args' : ('ascii', u'Hello \xe1', 6, 7,
{ 'message' : '', 'args' : ('ascii', u'Hello \xe1', 6, 7, 'ordinal not in range(128)'),
'ordinal not in range(128)'), 'encoding' : 'ascii', 'object' : u'Hello \xe1',
'encoding' : 'ascii', 'object' : u'Hello \xe1', 'start' : 6, 'reason' : 'ordinal not in range(128)'}),
'start' : 6, 'reason' : 'ordinal not in range(128)' }), (sampleUnicodeDecodeError,
( sampleUnicodeDecodeError, {'message' : '', 'args' : ('ascii', '\xff', 0, 1,
{ 'message' : '', 'args' : ('ascii', '\xff', 0, 1, 'ordinal not in range(128)'),
'ordinal not in range(128)'), 'encoding' : 'ascii', 'object' : '\xff',
'encoding' : 'ascii', 'object' : '\xff', 'start' : 0, 'reason' : 'ordinal not in range(128)'}),
'start' : 0, 'reason' : 'ordinal not in range(128)' }), (UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"),
( UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"), {'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
{ 'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'), 'object' : u'\u3042', 'reason' : 'ouch',
'object' : u'\u3042', 'reason' : 'ouch', 'start' : 0, 'end' : 1}),
'start' : 0, 'end' : 1 }), ]
]
try: try:
exceptionList.append( exceptionList.append(
( WindowsError, (1, 'strErrorStr', 'filenameStr'), (WindowsError, (1, 'strErrorStr', 'filenameStr'),
{ 'message' : '', 'args' : (1, 'strErrorStr'), {'message' : '', 'args' : (1, 'strErrorStr'),
'strerror' : 'strErrorStr', 'strerror' : 'strErrorStr', 'winerror' : 1,
'errno' : 22, 'filename' : 'filenameStr', 'errno' : 22, 'filename' : 'filenameStr'})
'winerror' : 1 })) )
except NameError: pass except NameError: pass
import pickle, random import pickle, random
...@@ -259,9 +258,13 @@ class ExceptionTests(unittest.TestCase): ...@@ -259,9 +258,13 @@ class ExceptionTests(unittest.TestCase):
for args in exceptionList: for args in exceptionList:
expected = args[-1] expected = args[-1]
try: try:
if len(args) == 2: raise args[0] exc = args[0]
else: raise apply(args[0], args[1]) if len(args) == 2: raise exc
else: raise exc(*args[1])
except BaseException, e: except BaseException, e:
if (e is not exc and # needed for sampleUnicode errors
type(e) is not exc):
raise
for checkArgName in expected.keys(): for checkArgName in expected.keys():
self.assertEquals(repr(getattr(e, checkArgName)), self.assertEquals(repr(getattr(e, checkArgName)),
repr(expected[checkArgName]), repr(expected[checkArgName]),
...@@ -280,6 +283,7 @@ class ExceptionTests(unittest.TestCase): ...@@ -280,6 +283,7 @@ class ExceptionTests(unittest.TestCase):
"""test that builtin exception don't take keyword args, """test that builtin exception don't take keyword args,
but user-defined subclasses can if they want""" but user-defined subclasses can if they want"""
self.assertRaises(TypeError, BaseException, a=1) self.assertRaises(TypeError, BaseException, a=1)
class DerivedException(BaseException): class DerivedException(BaseException):
def __init__(self, fancy_arg): def __init__(self, fancy_arg):
BaseException.__init__(self) BaseException.__init__(self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment