diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-02-27 13:57:09 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-02-27 13:57:09 (GMT) |
commit | 1cb0cb2fcdc83a6caa871104a622d1217ca034a3 (patch) | |
tree | 30adf3f3b7af0f167b4fa7d618b0fcdddf6e605b /Lib/test/test_exceptions.py | |
parent | 5f794098898b49650b2ef6a0c4f48aa0d03b0298 (diff) | |
download | cpython-1cb0cb2fcdc83a6caa871104a622d1217ca034a3.zip cpython-1cb0cb2fcdc83a6caa871104a622d1217ca034a3.tar.gz cpython-1cb0cb2fcdc83a6caa871104a622d1217ca034a3.tar.bz2 |
#17296: backport fix for issue 1692335, naive exception pickling.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 79bd7ff..28dcb24 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -10,6 +10,15 @@ import errno from test.support import (TESTFN, captured_output, check_impl_detail, cpython_only, gc_collect, run_unittest, unlink) +class NaiveException(Exception): + def __init__(self, x): + self.x = x + +class SlottedNaiveException(Exception): + __slots__ = ('x',) + def __init__(self, x): + self.x = x + # XXX This is not really enough, each *operation* should be tested! class ExceptionTests(unittest.TestCase): @@ -272,6 +281,10 @@ class ExceptionTests(unittest.TestCase): {'args' : ('\u3042', 0, 1, 'ouch'), 'object' : '\u3042', 'reason' : 'ouch', 'start' : 0, 'end' : 1}), + (NaiveException, ('foo',), + {'args': ('foo',), 'x': 'foo'}), + (SlottedNaiveException, ('foo',), + {'args': ('foo',), 'x': 'foo'}), ] try: exceptionList.append( @@ -291,7 +304,8 @@ class ExceptionTests(unittest.TestCase): raise else: # Verify module name - self.assertEqual(type(e).__module__, 'builtins') + if not type(e).__name__.endswith('NaiveException'): + self.assertEqual(type(e).__module__, 'builtins') # Verify no ref leaks in Exc_str() s = str(e) for checkArgName in expected: |