Commit 43ac4725 authored by Guido van Rossum's avatar Guido van Rossum

Got test_exceptions.py working.

parent a9d4043b
...@@ -929,12 +929,12 @@ class Unpickler: ...@@ -929,12 +929,12 @@ class Unpickler:
break break
else: else:
raise ValueError, "insecure string pickle" raise ValueError, "insecure string pickle"
self.append(rep.decode("string-escape")) self.append(str8(rep.decode("string-escape")))
dispatch[STRING[0]] = load_string dispatch[STRING[0]] = load_string
def load_binstring(self): def load_binstring(self):
len = mloads(b'i' + self.read(4)) len = mloads(b'i' + self.read(4))
self.append(self.read(len)) self.append(str8(self.read(len)))
dispatch[BINSTRING[0]] = load_binstring dispatch[BINSTRING[0]] = load_binstring
def load_unicode(self): def load_unicode(self):
...@@ -948,7 +948,7 @@ class Unpickler: ...@@ -948,7 +948,7 @@ class Unpickler:
def load_short_binstring(self): def load_short_binstring(self):
len = ord(self.read(1)) len = ord(self.read(1))
self.append(self.read(len)) self.append(str8(self.read(len)))
dispatch[SHORT_BINSTRING[0]] = load_short_binstring dispatch[SHORT_BINSTRING[0]] = load_short_binstring
def load_tuple(self): def load_tuple(self):
......
...@@ -251,17 +251,19 @@ class ExceptionTests(unittest.TestCase): ...@@ -251,17 +251,19 @@ class ExceptionTests(unittest.TestCase):
'print_file_and_line' : None, 'msg' : 'msgStr', 'print_file_and_line' : None, 'msg' : 'msgStr',
'filename' : None, 'lineno' : None, 'offset' : None}), 'filename' : None, 'lineno' : None, 'offset' : None}),
(UnicodeError, (), {'message' : '', 'args' : (),}), (UnicodeError, (), {'message' : '', 'args' : (),}),
(UnicodeEncodeError, (str8('ascii'), 'a', 0, 1, str8('ordinal not in range')), (UnicodeEncodeError, (str8('ascii'), 'a', 0, 1,
str8('ordinal not in range')),
{'message' : '', 'args' : ('ascii', 'a', 0, 1, {'message' : '', 'args' : ('ascii', 'a', 0, 1,
'ordinal not in range'), 'ordinal not in range'),
'encoding' : 'ascii', 'object' : 'a', 'encoding' : 'ascii', 'object' : 'a',
'start' : 0, 'reason' : 'ordinal not in range'}), 'start' : 0, 'reason' : 'ordinal not in range'}),
(UnicodeDecodeError, (str8('ascii'), b'\xff', 0, 1, str8('ordinal not in range')), (UnicodeDecodeError, (str8('ascii'), b'\xff', 0, 1,
{'message' : '', 'args' : ('ascii', '\xff', 0, 1, str8('ordinal not in range')),
{'message' : '', 'args' : ('ascii', b'\xff', 0, 1,
'ordinal not in range'), 'ordinal not in range'),
'encoding' : 'ascii', 'object' : '\xff', 'encoding' : 'ascii', 'object' : b'\xff',
'start' : 0, 'reason' : 'ordinal not in range'}), 'start' : 0, 'reason' : 'ordinal not in range'}),
(UnicodeTranslateError, ("\u3042", 0, 1, "ouch"), (UnicodeTranslateError, ("\u3042", 0, 1, str8("ouch")),
{'message' : '', 'args' : ('\u3042', 0, 1, 'ouch'), {'message' : '', 'args' : ('\u3042', 0, 1, 'ouch'),
'object' : '\u3042', 'reason' : 'ouch', 'object' : '\u3042', 'reason' : 'ouch',
'start' : 0, 'end' : 1}), 'start' : 0, 'end' : 1}),
...@@ -278,27 +280,28 @@ class ExceptionTests(unittest.TestCase): ...@@ -278,27 +280,28 @@ class ExceptionTests(unittest.TestCase):
for exc, args, expected in exceptionList: for exc, args, expected in exceptionList:
try: try:
print("exc=%r, args=%r" % (exc, args)) e = exc(*args)
raise exc(*args) except:
except BaseException as e: print("\nexc=%r, args=%r" % (exc, args))
if type(e) is not exc: raise
raise else:
# Verify module name # Verify module name
self.assertEquals(type(e).__module__, '__builtin__') self.assertEquals(type(e).__module__, '__builtin__')
# Verify no ref leaks in Exc_str() # Verify no ref leaks in Exc_str()
s = str(e) s = str(e)
for checkArgName in expected: for checkArgName in expected:
self.assertEquals(repr(getattr(e, checkArgName)), value = getattr(e, checkArgName)
self.assertEquals(repr(value),
repr(expected[checkArgName]), repr(expected[checkArgName]),
'exception "%s", attribute "%s"' % '%r.%s == %r, expected %r' % (
(repr(e), checkArgName)) e, checkArgName,
value, expected[checkArgName]))
# test for pickling support # test for pickling support
for p in pickle, cPickle: for p in pickle, cPickle:
if p is None: if p is None:
continue # cPickle not found -- skip it continue # cPickle not found -- skip it
for protocol in range(p.HIGHEST_PROTOCOL + 1): for protocol in range(p.HIGHEST_PROTOCOL + 1):
##print("p=%s, protocol=%s, e=%r" % (p.__name__, protocol, e))
s = p.dumps(e, protocol) s = p.dumps(e, protocol)
new = p.loads(s) new = p.loads(s)
for checkArgName in expected: for checkArgName in expected:
...@@ -356,4 +359,4 @@ def test_main(): ...@@ -356,4 +359,4 @@ def test_main():
run_unittest(ExceptionTests) run_unittest(ExceptionTests)
if __name__ == '__main__': if __name__ == '__main__':
test_main() unittest.main()
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