diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-15 10:51:34 (GMT) |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-15 10:51:34 (GMT) |
| commit | 6560e22c6664b720077643a338c71578baba6b58 (patch) | |
| tree | 1570f7d44d59866c0f3ad2dc9c798554e7de35f3 /Lib/test/pickletester.py | |
| parent | 7117d35dfc4db1dd9347d0bf99f579f570da427a (diff) | |
| download | cpython-6560e22c6664b720077643a338c71578baba6b58.zip cpython-6560e22c6664b720077643a338c71578baba6b58.tar.gz cpython-6560e22c6664b720077643a338c71578baba6b58.tar.bz2 | |
Issue #28925: cPickle now correctly propagates errors when unpickle instances
of old-style classes.
Diffstat (limited to 'Lib/test/pickletester.py')
| -rw-r--r-- | Lib/test/pickletester.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 022789d..138e17e 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -147,6 +147,17 @@ class E(C): class H(object): pass +class MyErr(Exception): + def __init__(self): + pass + +class I: + def __init__(self, *args, **kwargs): + raise MyErr() + + def __getinitargs__(self): + return () + # Hashable mutable key class K(object): def __init__(self, value): @@ -165,6 +176,8 @@ __main__.E = E E.__module__ = "__main__" __main__.H = H H.__module__ = "__main__" +__main__.I = I +I.__module__ = "__main__" __main__.K = K K.__module__ = "__main__" @@ -623,6 +636,36 @@ class AbstractUnpickleTests(unittest.TestCase): 'q\x00oq\x01}q\x02b.').replace('X', xname) self.assert_is_copy(X(*args), self.loads(pickle2)) + def test_load_classic_instance_error(self): + # Issue #28925. + # Protocol 0 (text mode pickle): + """ + 0: ( MARK + 1: i INST '__main__ I' (MARK at 0) + 13: ( MARK + 14: d DICT (MARK at 13) + 15: b BUILD + 16: . STOP + """ + pickle0 = ('(i__main__\n' + 'I\n' + '(db.') + self.assertRaises(MyErr, self.loads, pickle0) + + # Protocol 1 (binary mode pickle) + """ + 0: ( MARK + 1: c GLOBAL '__main__ I' + 13: o OBJ (MARK at 0) + 14: } EMPTY_DICT + 15: b BUILD + 16: . STOP + """ + pickle1 = ('(c__main__\n' + 'I\n' + 'o}b.') + self.assertRaises(MyErr, self.loads, pickle1) + def test_load_str(self): # From Python 2: pickle.dumps('a\x00\xa0', protocol=0) self.assertEqual(self.loads("S'a\\x00\\xa0'\n."), 'a\x00\xa0') |
