diff options
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index d9a00b9..1f7105e 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -5,7 +5,9 @@ import sys import unittest import pickle, cPickle -from test.test_support import TESTFN, unlink, run_unittest +from test.test_support import (TESTFN, unlink, run_unittest, + guard_warnings_filter) +from test.test_pep352 import ignore_message_warning # XXX This is not really enough, each *operation* should be tested! @@ -272,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)) - - # 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)) + with guard_warnings_filter(): + 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)) def testSlicing(self): # Test that you can slice an exception directly instead of requiring |