summaryrefslogtreecommitdiffstats
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-10-04 07:25:28 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-10-04 07:25:28 (GMT)
commit5a688dbf97f1537d3f2309bfe6be93dab2f10ce0 (patch)
tree669b73365df94fcb787c7dfe0edaf43e9e4a33d6 /Lib/test/pickletester.py
parent29f43f7368115c47c97acff02816a680c3ebd73e (diff)
parentffd41d9f101e31973b8713e884c95118fceb6f59 (diff)
downloadcpython-5a688dbf97f1537d3f2309bfe6be93dab2f10ce0.zip
cpython-5a688dbf97f1537d3f2309bfe6be93dab2f10ce0.tar.gz
cpython-5a688dbf97f1537d3f2309bfe6be93dab2f10ce0.tar.bz2
Issue #7689: Allow pickling of dynamically created classes when their
metaclass is registered with copyreg. Patch by Nicolas M. ThiƩry and Craig Citro.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index d79aab7..ca46457 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -122,6 +122,19 @@ class metaclass(type):
class use_metaclass(object, metaclass=metaclass):
pass
+class pickling_metaclass(type):
+ def __eq__(self, other):
+ return (type(self) == type(other) and
+ self.reduce_args == other.reduce_args)
+
+ def __reduce__(self):
+ return (create_dynamic_class, self.reduce_args)
+
+def create_dynamic_class(name, bases):
+ result = pickling_metaclass(name, bases, dict())
+ result.reduce_args = (name, bases)
+ return result
+
# DATA0 .. DATA2 are the pickles we expect under the various protocols, for
# the object returned by create_data().
@@ -696,6 +709,14 @@ class AbstractPickleTests(unittest.TestCase):
b = self.loads(s)
self.assertEqual(a.__class__, b.__class__)
+ def test_dynamic_class(self):
+ a = create_dynamic_class("my_dynamic_class", (object,))
+ copyreg.pickle(pickling_metaclass, pickling_metaclass.__reduce__)
+ for proto in protocols:
+ s = self.dumps(a, proto)
+ b = self.loads(s)
+ self.assertEqual(a, b)
+
def test_structseq(self):
import time
import os