Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now

rejects builtin types with not defined __new__.
Added tests for non-pickleable types.
This commit is contained in:
Serhiy Storchaka 2015-11-12 11:23:04 +02:00
parent a9dcdabccb
commit d7a4415599
6 changed files with 78 additions and 0 deletions

View file

@ -1,3 +1,5 @@
import copy
import pickle
import unittest
from test import support
@ -198,6 +200,22 @@ class DictSetTest(unittest.TestCase):
d[42] = d.values()
self.assertRaises(RuntimeError, repr, d)
def test_copy(self):
d = {1: 10, "a": "ABC"}
self.assertRaises(TypeError, copy.copy, d.keys())
self.assertRaises(TypeError, copy.copy, d.values())
self.assertRaises(TypeError, copy.copy, d.items())
def test_pickle(self):
d = {1: 10, "a": "ABC"}
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
self.assertRaises((TypeError, pickle.PicklingError),
pickle.dumps, d.keys(), proto)
self.assertRaises((TypeError, pickle.PicklingError),
pickle.dumps, d.values(), proto)
self.assertRaises((TypeError, pickle.PicklingError),
pickle.dumps, d.items(), proto)
def test_main():
support.run_unittest(DictSetTest)