Add a test case for exception pickling. args is never NULL.

This commit is contained in:
Georg Brandl 2006-05-30 07:13:29 +00:00
parent ddba473e26
commit 05f97bffac
2 changed files with 21 additions and 11 deletions

View file

@ -270,6 +270,8 @@ try:
'winerror' : 1 }))
except NameError: pass
import pickle, random
for args in exceptionList:
expected = args[-1]
try:
@ -283,3 +285,14 @@ for args in exceptionList:
( repr(e), checkArgName,
repr(expected[checkArgName]),
repr(getattr(e, checkArgName)) ))
# test for pickling support
new = pickle.loads(pickle.dumps(e, random.randint(0, 2)))
for checkArgName in expected.keys():
if repr(getattr(e, checkArgName)) != repr(expected[checkArgName]):
raise TestFailed('Checking unpickled exception arguments, '
'exception '
'"%s", attribute "%s" expected %s got %s.' %
( repr(e), checkArgName,
repr(expected[checkArgName]),
repr(getattr(e, checkArgName)) ))