summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2006-06-07 06:57:51 (GMT)
committerTim Peters <tim.peters@gmail.com>2006-06-07 06:57:51 (GMT)
commit80dc76e9072c4adaedf5c52032699b859c82eca2 (patch)
tree5315ceff7d08766115bc54d8d91ce56d054bf8e5 /Lib
parentc27d655c00ec08f44abea646ae06456cbcca84b6 (diff)
downloadcpython-80dc76e9072c4adaedf5c52032699b859c82eca2.zip
cpython-80dc76e9072c4adaedf5c52032699b859c82eca2.tar.gz
cpython-80dc76e9072c4adaedf5c52032699b859c82eca2.tar.bz2
SF patch 1501987: Remove randomness from test_exceptions,
from ?iga Seilnacht (sorry about the name, but Firefox on my box can't display the first character of the name -- the SF "Unix name" is zseil). This appears to cure the oddball intermittent leaks across runs when running test_exceptions under -R. I'm not sure why, but I'm too sleepy to care ;-) The thrust of the SF patch was to remove randomness in the pickle protocol used. I changed the patch to use range(pickle.HIGHEST_PROTOCOL + 1), to try both pickle and cPickle, and randomly mucked with other test lines to put statements on their own lines. Not a bugfix candidate (this is fiddling new-in-2.5 code).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_exceptions.py49
1 files changed, 30 insertions, 19 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 84d2798..45f5188 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1,9 +1,12 @@
# Python test set -- part 5, built-in exceptions
-from test.test_support import TESTFN, unlink, run_unittest
-import warnings
-import sys, traceback, os
+import os
+import sys
import unittest
+import warnings
+import pickle, cPickle
+
+from test.test_support import TESTFN, unlink, run_unittest
# XXX This is not really enough, each *operation* should be tested!
@@ -182,11 +185,15 @@ class ExceptionTests(unittest.TestCase):
def testAttributes(self):
# test that exception attributes are happy
- try: str(u'Hello \u00E1')
- except Exception, e: sampleUnicodeEncodeError = e
+ try:
+ str(u'Hello \u00E1')
+ except Exception, e:
+ sampleUnicodeEncodeError = e
- try: unicode('\xff')
- except Exception, e: sampleUnicodeDecodeError = e
+ try:
+ unicode('\xff')
+ except Exception, e:
+ sampleUnicodeDecodeError = e
exceptionList = [
(BaseException, (), {'message' : '', 'args' : ()}),
@@ -251,19 +258,20 @@ class ExceptionTests(unittest.TestCase):
'strerror' : 'strErrorStr', 'winerror' : 1,
'errno' : 22, 'filename' : 'filenameStr'})
)
- except NameError: pass
-
- import pickle, random
+ except NameError:
+ pass
for args in exceptionList:
expected = args[-1]
try:
exc = args[0]
- if len(args) == 2: raise exc
- else: raise exc(*args[1])
+ if len(args) == 2:
+ raise exc
+ else:
+ raise exc(*args[1])
except BaseException, e:
if (e is not exc and # needed for sampleUnicode errors
- type(e) is not exc):
+ type(e) is not exc):
raise
# Verify no ref leaks in Exc_str()
s = str(e)
@@ -274,12 +282,15 @@ class ExceptionTests(unittest.TestCase):
(repr(e), checkArgName))
# test for pickling support
- new = pickle.loads(pickle.dumps(e, random.randint(0, 2)))
- for checkArgName in expected:
- self.assertEquals(repr(getattr(e, checkArgName)),
- repr(expected[checkArgName]),
- 'pickled exception "%s", attribute "%s' %
- (repr(e), checkArgName))
+ for p in pickle, cPickle:
+ for protocol in range(p.HIGHEST_PROTOCOL + 1):
+ new = p.loads(p.dumps(e, protocol))
+ for checkArgName in expected:
+ got = repr(getattr(new, checkArgName))
+ want = repr(expected[checkArgName])
+ self.assertEquals(got, want,
+ 'pickled "%r", attribute "%s' %
+ (e, checkArgName))
def testKeywordArgs(self):
# test that builtin exception don't take keyword args,