(original) (raw)

changeset: 99076:a2f574896f49 parent: 99073:2899acbd2b46 parent: 99075:4c05e7c195ac user: Serhiy Storchaka storchaka@gmail.com date: Thu Nov 12 11:34:39 2015 +0200 files: Lib/test/test_dictviews.py Misc/NEWS Objects/typeobject.c description: Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now rejects builtin types with not defined __new__. Added tests for non-pickleable types. diff -r 2899acbd2b46 -r a2f574896f49 Lib/test/test_coroutines.py --- a/Lib/test/test_coroutines.py Wed Nov 11 22:45:36 2015 -0800 +++ b/Lib/test/test_coroutines.py Thu Nov 12 11:34:39 2015 +0200 @@ -1,5 +1,7 @@ import contextlib +import copy import inspect +import pickle import sys import types import unittest @@ -1318,6 +1320,34 @@ run_async(foo()) self.assertEqual(CNT, 0) + def test_copy(self): + async def func(): pass + coro = func() + with self.assertRaises(TypeError): + copy.copy(coro) + + aw = coro.__await__() + try: + with self.assertRaises(TypeError): + copy.copy(aw) + finally: + aw.close() + + def test_pickle(self): + async def func(): pass + coro = func() + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + with self.assertRaises((TypeError, pickle.PicklingError)): + pickle.dumps(coro, proto) + + aw = coro.__await__() + try: + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + with self.assertRaises((TypeError, pickle.PicklingError)): + pickle.dumps(aw, proto) + finally: + aw.close() + class CoroAsyncIOCompatTest(unittest.TestCase): diff -r 2899acbd2b46 -r a2f574896f49 Lib/test/test_dictviews.py --- a/Lib/test/test_dictviews.py Wed Nov 11 22:45:36 2015 -0800 +++ b/Lib/test/test_dictviews.py Thu Nov 12 11:34:39 2015 +0200 @@ -1,4 +1,6 @@ import collections +import copy +import pickle import unittest class DictSetTest(unittest.TestCase): @@ -198,6 +200,22 @@ d[42] = d.values() self.assertRaises(RecursionError, 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_abc_registry(self): d = dict(a=1) diff -r 2899acbd2b46 -r a2f574896f49 Lib/test/test_generators.py --- a/Lib/test/test_generators.py Wed Nov 11 22:45:36 2015 -0800 +++ b/Lib/test/test_generators.py Thu Nov 12 11:34:39 2015 +0200 @@ -1,4 +1,6 @@ +import copy import gc +import pickle import sys import unittest import warnings @@ -111,6 +113,21 @@ self.assertEqual(gen.__qualname__, "GeneratorTest.test_name..") + def test_copy(self): + def f(): + yield 1 + g = f() + with self.assertRaises(TypeError): + copy.copy(g) + + def test_pickle(self): + def f(): + yield 1 + g = f() + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + with self.assertRaises((TypeError, pickle.PicklingError)): + pickle.dumps(g, proto) + class ExceptionTest(unittest.TestCase): # Tests for the issue #23353: check that the currently handled exception diff -r 2899acbd2b46 -r a2f574896f49 Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py Wed Nov 11 22:45:36 2015 -0800 +++ b/Lib/test/test_xml_etree.py Thu Nov 12 11:34:39 2015 +0200 @@ -5,6 +5,7 @@ # For this purpose, the module-level "ET" symbol is temporarily # monkey-patched when running the "test_xml_etree_c" test suite. +import copy import html import io import operator @@ -2082,6 +2083,19 @@ self.assertEqual(self._ilist(doc), all_tags) self.assertEqual(self._ilist(doc, '*'), all_tags) + def test_copy(self): + a = ET.Element('a') + it = a.iter() + with self.assertRaises(TypeError): + copy.copy(it) + + def test_pickle(self): + a = ET.Element('a') + it = a.iter() + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + with self.assertRaises((TypeError, pickle.PicklingError)): + pickle.dumps(it, proto) + class TreeBuilderTest(unittest.TestCase): sample1 = ('tp_new == NULL) { + PyErr_Format(PyExc_TypeError, + "can't pickle %s objects", + Py_TYPE(obj)->tp_name); + return NULL; + } if (_PyObject_GetNewArguments(obj, &args, &kwargs) < 0) return NULL;/storchaka@gmail.com