Reverting the Revision: 77368. I committed Flox's big patch for tests by

mistake. ( It may come in for sure tough)
This commit is contained in:
Senthil Kumaran 2010-01-08 19:04:16 +00:00
parent 3ddc435af6
commit ce8e33a095
107 changed files with 436 additions and 794 deletions

View file

@ -7,7 +7,7 @@ import pickle, cPickle
import warnings
from test.test_support import TESTFN, unlink, run_unittest, captured_output
from test.test_pep352 import ignore_deprecation_warnings
from test.test_pep352 import ignore_message_warning
# XXX This is not really enough, each *operation* should be tested!
@ -17,7 +17,6 @@ class ExceptionTests(unittest.TestCase):
# Reloading the built-in exceptions module failed prior to Py2.2, while it
# should act the same as reloading built-in sys.
try:
from imp import reload
import exceptions
reload(exceptions)
except ImportError, e:
@ -109,11 +108,11 @@ class ExceptionTests(unittest.TestCase):
self.assertRaises(ValueError, chr, 10000)
self.raise_catch(ZeroDivisionError, "ZeroDivisionError")
try: x = 1 // 0
try: x = 1/0
except ZeroDivisionError: pass
self.raise_catch(Exception, "Exception")
try: x = 1 // 0
try: x = 1/0
except Exception, e: pass
def testSyntaxErrorMessage(self):
@ -198,7 +197,6 @@ class ExceptionTests(unittest.TestCase):
self.assertEqual(WindowsError(1001, "message").errno, 22)
self.assertEqual(WindowsError(1001, "message").winerror, 1001)
@ignore_deprecation_warnings
def testAttributes(self):
# test that exception attributes are happy
@ -276,32 +274,34 @@ class ExceptionTests(unittest.TestCase):
except NameError:
pass
for exc, args, expected in exceptionList:
try:
raise exc(*args)
except BaseException, e:
if type(e) is not exc:
raise
# Verify module name
self.assertEquals(type(e).__module__, 'exceptions')
# Verify no ref leaks in Exc_str()
s = str(e)
for checkArgName in expected:
self.assertEquals(repr(getattr(e, checkArgName)),
repr(expected[checkArgName]),
'exception "%s", attribute "%s"' %
(repr(e), checkArgName))
with warnings.catch_warnings():
ignore_message_warning()
for exc, args, expected in exceptionList:
try:
raise exc(*args)
except BaseException, e:
if type(e) is not exc:
raise
# Verify module name
self.assertEquals(type(e).__module__, 'exceptions')
# Verify no ref leaks in Exc_str()
s = str(e)
for checkArgName in expected:
self.assertEquals(repr(getattr(e, checkArgName)),
repr(expected[checkArgName]),
'exception "%s", attribute "%s"' %
(repr(e), checkArgName))
# test for pickling support
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))
# test for pickling support
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 testDeprecatedMessageAttribute(self):
@ -330,7 +330,6 @@ class ExceptionTests(unittest.TestCase):
with self.assertRaises(AttributeError):
exc.message
@ignore_deprecation_warnings
def testPickleMessageAttribute(self):
# Pickling with message attribute must work, as well.
e = Exception("foo")
@ -338,7 +337,9 @@ class ExceptionTests(unittest.TestCase):
f.message = "bar"
for p in pickle, cPickle:
ep = p.loads(p.dumps(e))
self.assertEqual(ep.message, "foo")
with warnings.catch_warnings():
ignore_message_warning()
self.assertEqual(ep.message, "foo")
fp = p.loads(p.dumps(f))
self.assertEqual(fp.message, "bar")
@ -347,12 +348,7 @@ class ExceptionTests(unittest.TestCase):
# going through the 'args' attribute.
args = (1, 2, 3)
exc = BaseException(*args)
self.assertEqual(exc.args[:], args)
with warnings.catch_warnings():
# Silence Py3k warning
warnings.filterwarnings("ignore", "__getslice__ not supported for "
"exception classes", DeprecationWarning)
self.assertEqual(exc[:], args)
self.assertEqual(exc[:], args)
def testKeywordArgs(self):
# test that builtin exception don't take keyword args,