summaryrefslogtreecommitdiffstats
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-22 19:43:59 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-22 19:43:59 (GMT)
commit7eecffd05dcef6666f3f75bd960d5087cb85d629 (patch)
treee611782a95c748524410c2062951118dfb5ec065 /Lib/test/pickletester.py
parent61ec8de8097237e83a42bf6c732abf15c3fd7610 (diff)
downloadcpython-7eecffd05dcef6666f3f75bd960d5087cb85d629.zip
cpython-7eecffd05dcef6666f3f75bd960d5087cb85d629.tar.gz
cpython-7eecffd05dcef6666f3f75bd960d5087cb85d629.tar.bz2
Issue #9935: Speed up pickling of instances of user-defined classes.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 7645b54..e21d490 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -3,6 +3,7 @@ import unittest
import pickle
import pickletools
import copyreg
+import weakref
from http.cookies import SimpleCookie
from test.support import TestFailed, TESTFN, run_with_locale
@@ -842,6 +843,25 @@ class AbstractPickleTests(unittest.TestCase):
self.assertEqual(B(x), B(y), detail)
self.assertEqual(x.__dict__, y.__dict__, detail)
+ def test_newobj_proxies(self):
+ # NEWOBJ should use the __class__ rather than the raw type
+ classes = myclasses[:]
+ # Cannot create weakproxies to these classes
+ for c in (MyInt, MyTuple):
+ classes.remove(c)
+ for proto in protocols:
+ for C in classes:
+ B = C.__base__
+ x = C(C.sample)
+ x.foo = 42
+ p = weakref.proxy(x)
+ s = self.dumps(p, proto)
+ y = self.loads(s)
+ self.assertEqual(type(y), type(x)) # rather than type(p)
+ detail = (proto, C, B, x, y, type(y))
+ self.assertEqual(B(x), B(y), detail)
+ self.assertEqual(x.__dict__, y.__dict__, detail)
+
# Register a type with copyreg, with extension code extcode. Pickle
# an object of that type. Check that the resulting pickle uses opcode
# (EXT[124]) under proto 2, and not in proto 1.
@@ -1008,7 +1028,6 @@ class AbstractPickleTests(unittest.TestCase):
self.assertRaises(RuntimeError, self.dumps, x, proto)
# protocol 2 don't raise a RuntimeError.
d = self.dumps(x, 2)
- self.assertRaises(RuntimeError, self.loads, d)
def test_reduce_bad_iterator(self):
# Issue4176: crash when 4th and 5th items of __reduce__()