diff options
author | Georg Brandl <georg@python.org> | 2009-09-16 20:34:51 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-09-16 20:34:51 +0000 |
commit | 8997103be0a63962cb8a4b4ccff8575d205f44c6 (patch) | |
tree | 3c3d6077c5ad1b5921f6999ea04fa903aae5f98a /Lib/test/test_exceptions.py | |
parent | 6bb97a2ec4e9cdfb8e234c3613ceae79ddce1351 (diff) | |
download | cpython-git-8997103be0a63962cb8a4b4ccff8575d205f44c6.tar.gz |
Merged revisions 74845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74845 | georg.brandl | 2009-09-16 22:30:09 +0200 (Mi, 16 Sep 2009) | 5 lines
#6844: do not emit DeprecationWarnings on access if Exception.message has been set by the user.
This works by always setting it in __dict__, except when it's implicitly set in __init__.
........
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 06a23781c5..aa5c7efc36 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -303,6 +303,45 @@ class ExceptionTests(unittest.TestCase): 'pickled "%r", attribute "%s"' % (e, checkArgName)) + + def testDeprecatedMessageAttribute(self): + # Accessing BaseException.message and relying on its value set by + # BaseException.__init__ triggers a deprecation warning. + exc = BaseException("foo") + with warnings.catch_warnings(record=True) as w: + self.assertEquals(exc.message, "foo") + self.assertEquals(len(w), 1) + self.assertEquals(w[0].category, DeprecationWarning) + self.assertEquals( + str(w[0].message), + "BaseException.message has been deprecated as of Python 2.6") + + + def testRegularMessageAttribute(self): + # Accessing BaseException.message after explicitly setting a value + # for it does not trigger a deprecation warning. + exc = BaseException("foo") + exc.message = "bar" + with warnings.catch_warnings(record=True) as w: + self.assertEquals(exc.message, "bar") + self.assertEquals(len(w), 0) + # Deleting the message is supported, too. + del exc.message + self.assertRaises(AttributeError, getattr, exc, "message") + + def testPickleMessageAttribute(self): + # Pickling with message attribute must work, as well. + e = Exception("foo") + f = Exception("foo") + f.message = "bar" + for p in pickle, cPickle: + ep = p.loads(p.dumps(e)) + with warnings.catch_warnings(): + ignore_message_warning() + self.assertEqual(ep.message, "foo") + fp = p.loads(p.dumps(f)) + self.assertEqual(fp.message, "bar") + def testSlicing(self): # Test that you can slice an exception directly instead of requiring # going through the 'args' attribute. |