annotate Lib/test/pickletester.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents e54141d63e01
children aac26de8b5d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
1 import unittest
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
2 import pickle
27864
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
3 import cPickle
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
4 import cStringIO
27645
b66acbe29575 Proper testing of proto 2 in part requires checking that the new opcodes
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
5 import pickletools
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
6 import copy_reg
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
7
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
8 from test.test_support import TestFailed, have_unicode, TESTFN
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
9
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
10 # Tests that try a number of pickle protocols should have a
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
11 # for proto in protocols:
27864
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
12 # kind of outer loop.
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
13 assert pickle.HIGHEST_PROTOCOL == cPickle.HIGHEST_PROTOCOL == 2
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
14 protocols = range(pickle.HIGHEST_PROTOCOL + 1)
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
15
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
16 # Copy of test.test_support.run_with_locale. This is needed to support Python
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
17 # 2.4, which didn't include it. This is all to support test_xpickle, which
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
18 # bounces pickled objects through older Python versions to test backwards
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
19 # compatibility.
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
20 def run_with_locale(catstr, *locales):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
21 def decorator(func):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
22 def inner(*args, **kwds):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
23 try:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
24 import locale
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
25 category = getattr(locale, catstr)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
26 orig_locale = locale.setlocale(category)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
27 except AttributeError:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
28 # if the test author gives us an invalid category string
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
29 raise
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
30 except:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
31 # cannot retrieve original locale, so do nothing
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
32 locale = orig_locale = None
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
33 else:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
34 for loc in locales:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
35 try:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
36 locale.setlocale(category, loc)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
37 break
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
38 except:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
39 pass
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
40
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
41 # now run the function, resetting the locale on exceptions
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
42 try:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
43 return func(*args, **kwds)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
44 finally:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
45 if locale and orig_locale:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
46 locale.setlocale(category, orig_locale)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
47 inner.func_name = func.func_name
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
48 inner.__doc__ = func.__doc__
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
49 return inner
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
50 return decorator
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
51
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
52
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
53 # Return True if opcode code appears in the pickle, else False.
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
54 def opcode_in_pickle(code, pickle):
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
55 for op, dummy, dummy in pickletools.genops(pickle):
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
56 if op.code == code:
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
57 return True
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
58 return False
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
59
27813
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
60 # Return the number of times opcode code appears in pickle.
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
61 def count_opcode(code, pickle):
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
62 n = 0
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
63 for op, dummy, dummy in pickletools.genops(pickle):
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
64 if op.code == code:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
65 n += 1
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
66 return n
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
67
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
68 # We can't very well test the extension registry without putting known stuff
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
69 # in it, but we have to be careful to restore its original state. Code
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
70 # should do this:
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
71 #
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
72 # e = ExtensionSaver(extension_code)
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
73 # try:
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
74 # fiddle w/ the extension registry's stuff for extension_code
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
75 # finally:
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
76 # e.restore()
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
77
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
78 class ExtensionSaver:
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
79 # Remember current registration for code (if any), and remove it (if
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
80 # there is one).
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
81 def __init__(self, code):
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
82 self.code = code
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
83 if code in copy_reg._inverted_registry:
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
84 self.pair = copy_reg._inverted_registry[code]
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
85 copy_reg.remove_extension(self.pair[0], self.pair[1], code)
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
86 else:
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
87 self.pair = None
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
88
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
89 # Restore previous registration for code.
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
90 def restore(self):
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
91 code = self.code
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
92 curpair = copy_reg._inverted_registry.get(code)
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
93 if curpair is not None:
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
94 copy_reg.remove_extension(curpair[0], curpair[1], code)
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
95 pair = self.pair
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
96 if pair is not None:
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
97 copy_reg.add_extension(pair[0], pair[1], code)
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
98
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
99 class C:
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
100 def __cmp__(self, other):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
101 return cmp(self.__dict__, other.__dict__)
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
102
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
103 import __main__
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
104 __main__.C = C
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
105 C.__module__ = "__main__"
17365
11e8bb4d845d Test full range of native ints. This exposes two more binary pickle
Tim Peters <tim.peters@gmail.com>
parents: 17358
diff changeset
106
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
107 class myint(int):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
108 def __init__(self, x):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
109 self.str = str(x)
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
110
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
111 class initarg(C):
21481
003a985cab95 The test using class initarg failed, because it was lacking a
Guido van Rossum <guido@python.org>
parents: 20547
diff changeset
112
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
113 def __init__(self, a, b):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
114 self.a = a
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
115 self.b = b
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
116
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
117 def __getinitargs__(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
118 return self.a, self.b
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
119
21488
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
120 class metaclass(type):
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
121 pass
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
122
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
123 class use_metaclass(object):
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
124 __metaclass__ = metaclass
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
125
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
126 # DATA0 .. DATA2 are the pickles we expect under the various protocols, for
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
127 # the object returned by create_data().
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
128
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
129 # break into multiple strings to avoid confusing font-lock-mode
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
130 DATA0 = """(lp1
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
131 I0
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
132 aL1L
17358
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
133 aF2
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
134 ac__builtin__
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
135 complex
17358
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
136 p2
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
137 """ + \
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
138 """(F3
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
139 F0
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
140 tRp3
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
141 aI1
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
142 aI-1
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
143 aI255
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
144 aI-255
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
145 aI-256
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
146 aI65535
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
147 aI-65535
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
148 aI-65536
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
149 aI2147483647
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
150 aI-2147483647
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
151 aI-2147483648
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
152 a""" + \
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
153 """(S'abc'
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
154 p4
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
155 g4
17358
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
156 """ + \
17538
162fa6b1366f Change the test data to ask for class C from module __main__ rather
Guido van Rossum <guido@python.org>
parents: 17365
diff changeset
157 """(i__main__
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
158 C
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
159 p5
17358
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
160 """ + \
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
161 """(dp6
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
162 S'foo'
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
163 p7
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
164 I1
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
165 sS'bar'
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
166 p8
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
167 I2
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
168 sbg5
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
169 tp9
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
170 ag9
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
171 aI5
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
172 a.
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
173 """
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
174
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
175 # Disassembly of DATA0.
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
176 DATA0_DIS = """\
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
177 0: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
178 1: l LIST (MARK at 0)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
179 2: p PUT 1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
180 5: I INT 0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
181 8: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
182 9: L LONG 1L
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
183 13: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
184 14: F FLOAT 2.0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
185 17: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
186 18: c GLOBAL '__builtin__ complex'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
187 39: p PUT 2
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
188 42: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
189 43: F FLOAT 3.0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
190 46: F FLOAT 0.0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
191 49: t TUPLE (MARK at 42)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
192 50: R REDUCE
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
193 51: p PUT 3
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
194 54: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
195 55: I INT 1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
196 58: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
197 59: I INT -1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
198 63: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
199 64: I INT 255
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
200 69: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
201 70: I INT -255
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
202 76: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
203 77: I INT -256
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
204 83: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
205 84: I INT 65535
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
206 91: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
207 92: I INT -65535
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
208 100: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
209 101: I INT -65536
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
210 109: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
211 110: I INT 2147483647
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
212 122: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
213 123: I INT -2147483647
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
214 136: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
215 137: I INT -2147483648
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
216 150: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
217 151: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
218 152: S STRING 'abc'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
219 159: p PUT 4
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
220 162: g GET 4
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
221 165: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
222 166: i INST '__main__ C' (MARK at 165)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
223 178: p PUT 5
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
224 181: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
225 182: d DICT (MARK at 181)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
226 183: p PUT 6
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
227 186: S STRING 'foo'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
228 193: p PUT 7
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
229 196: I INT 1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
230 199: s SETITEM
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
231 200: S STRING 'bar'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
232 207: p PUT 8
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
233 210: I INT 2
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
234 213: s SETITEM
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
235 214: b BUILD
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
236 215: g GET 5
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
237 218: t TUPLE (MARK at 151)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
238 219: p PUT 9
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
239 222: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
240 223: g GET 9
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
241 226: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
242 227: I INT 5
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
243 230: a APPEND
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
244 231: . STOP
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
245 highest protocol among opcodes = 0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
246 """
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
247
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
248 DATA1 = (']q\x01(K\x00L1L\nG@\x00\x00\x00\x00\x00\x00\x00'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
249 'c__builtin__\ncomplex\nq\x02(G@\x08\x00\x00\x00\x00\x00'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
250 '\x00G\x00\x00\x00\x00\x00\x00\x00\x00tRq\x03K\x01J\xff\xff'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
251 '\xff\xffK\xffJ\x01\xff\xff\xffJ\x00\xff\xff\xffM\xff\xff'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
252 'J\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff\xff\xff\x7fJ\x01\x00'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
253 '\x00\x80J\x00\x00\x00\x80(U\x03abcq\x04h\x04(c__main__\n'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
254 'C\nq\x05oq\x06}q\x07(U\x03fooq\x08K\x01U\x03barq\tK\x02ubh'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
255 '\x06tq\nh\nK\x05e.'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
256 )
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
257
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
258 # Disassembly of DATA1.
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
259 DATA1_DIS = """\
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
260 0: ] EMPTY_LIST
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
261 1: q BINPUT 1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
262 3: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
263 4: K BININT1 0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
264 6: L LONG 1L
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
265 10: G BINFLOAT 2.0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
266 19: c GLOBAL '__builtin__ complex'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
267 40: q BINPUT 2
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
268 42: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
269 43: G BINFLOAT 3.0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
270 52: G BINFLOAT 0.0
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
271 61: t TUPLE (MARK at 42)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
272 62: R REDUCE
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
273 63: q BINPUT 3
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
274 65: K BININT1 1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
275 67: J BININT -1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
276 72: K BININT1 255
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
277 74: J BININT -255
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
278 79: J BININT -256
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
279 84: M BININT2 65535
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
280 87: J BININT -65535
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
281 92: J BININT -65536
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
282 97: J BININT 2147483647
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
283 102: J BININT -2147483647
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
284 107: J BININT -2147483648
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
285 112: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
286 113: U SHORT_BINSTRING 'abc'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
287 118: q BINPUT 4
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
288 120: h BINGET 4
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
289 122: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
290 123: c GLOBAL '__main__ C'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
291 135: q BINPUT 5
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
292 137: o OBJ (MARK at 122)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
293 138: q BINPUT 6
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
294 140: } EMPTY_DICT
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
295 141: q BINPUT 7
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
296 143: ( MARK
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
297 144: U SHORT_BINSTRING 'foo'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
298 149: q BINPUT 8
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
299 151: K BININT1 1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
300 153: U SHORT_BINSTRING 'bar'
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
301 158: q BINPUT 9
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
302 160: K BININT1 2
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
303 162: u SETITEMS (MARK at 143)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
304 163: b BUILD
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
305 164: h BINGET 6
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
306 166: t TUPLE (MARK at 112)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
307 167: q BINPUT 10
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
308 169: h BINGET 10
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
309 171: K BININT1 5
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
310 173: e APPENDS (MARK at 3)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
311 174: . STOP
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
312 highest protocol among opcodes = 1
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
313 """
20547
a12ccdbce8da Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 20444
diff changeset
314
28132
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
315 DATA2 = ('\x80\x02]q\x01(K\x00\x8a\x01\x01G@\x00\x00\x00\x00\x00\x00\x00'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
316 'c__builtin__\ncomplex\nq\x02G@\x08\x00\x00\x00\x00\x00\x00G\x00'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
317 '\x00\x00\x00\x00\x00\x00\x00\x86Rq\x03K\x01J\xff\xff\xff\xffK'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
318 '\xffJ\x01\xff\xff\xffJ\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xff'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
319 'J\x00\x00\xff\xffJ\xff\xff\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
320 '\x80(U\x03abcq\x04h\x04(c__main__\nC\nq\x05oq\x06}q\x07(U\x03foo'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
321 'q\x08K\x01U\x03barq\tK\x02ubh\x06tq\nh\nK\x05e.')
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
322
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
323 # Disassembly of DATA2.
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
324 DATA2_DIS = """\
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
325 0: \x80 PROTO 2
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
326 2: ] EMPTY_LIST
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
327 3: q BINPUT 1
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
328 5: ( MARK
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
329 6: K BININT1 0
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
330 8: \x8a LONG1 1L
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
331 11: G BINFLOAT 2.0
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
332 20: c GLOBAL '__builtin__ complex'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
333 41: q BINPUT 2
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
334 43: G BINFLOAT 3.0
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
335 52: G BINFLOAT 0.0
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
336 61: \x86 TUPLE2
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
337 62: R REDUCE
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
338 63: q BINPUT 3
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
339 65: K BININT1 1
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
340 67: J BININT -1
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
341 72: K BININT1 255
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
342 74: J BININT -255
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
343 79: J BININT -256
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
344 84: M BININT2 65535
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
345 87: J BININT -65535
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
346 92: J BININT -65536
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
347 97: J BININT 2147483647
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
348 102: J BININT -2147483647
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
349 107: J BININT -2147483648
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
350 112: ( MARK
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
351 113: U SHORT_BINSTRING 'abc'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
352 118: q BINPUT 4
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
353 120: h BINGET 4
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
354 122: ( MARK
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
355 123: c GLOBAL '__main__ C'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
356 135: q BINPUT 5
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
357 137: o OBJ (MARK at 122)
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
358 138: q BINPUT 6
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
359 140: } EMPTY_DICT
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
360 141: q BINPUT 7
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
361 143: ( MARK
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
362 144: U SHORT_BINSTRING 'foo'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
363 149: q BINPUT 8
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
364 151: K BININT1 1
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
365 153: U SHORT_BINSTRING 'bar'
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
366 158: q BINPUT 9
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
367 160: K BININT1 2
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
368 162: u SETITEMS (MARK at 143)
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
369 163: b BUILD
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
370 164: h BINGET 6
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
371 166: t TUPLE (MARK at 112)
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
372 167: q BINPUT 10
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
373 169: h BINGET 10
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
374 171: K BININT1 5
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
375 173: e APPENDS (MARK at 5)
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
376 174: . STOP
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
377 highest protocol among opcodes = 2
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
378 """
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
379
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
380 def create_data():
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
381 c = C()
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
382 c.foo = 1
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
383 c.bar = 2
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
384 x = [0, 1L, 2.0, 3.0+0j]
17358
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
385 # Append some integer test cases at cPickle.c's internal size
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
386 # cutoffs.
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
387 uint1max = 0xff
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
388 uint2max = 0xffff
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
389 int4max = 0x7fffffff
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
390 x.extend([1, -1,
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
391 uint1max, -uint1max, -uint1max-1,
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
392 uint2max, -uint2max, -uint2max-1,
3aaedbac95b3 Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents: 17356
diff changeset
393 int4max, -int4max, -int4max-1])
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
394 y = ('abc', 'abc', c, c)
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
395 x.append(y)
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
396 x.append(y)
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
397 x.append(5)
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
398 return x
17356
28cf0a7943cf No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents: 16134
diff changeset
399
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
400 class AbstractPickleTests(unittest.TestCase):
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
401 # Subclass must define self.dumps, self.loads, self.error.
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
402
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
403 _testdata = create_data()
17356
28cf0a7943cf No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents: 16134
diff changeset
404
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
405 def setUp(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
406 pass
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
407
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
408 def test_misc(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
409 # test various datatypes not tested by testdata
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
410 for proto in protocols:
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
411 x = myint(4)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
412 s = self.dumps(x, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
413 y = self.loads(s)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
414 self.assertEqual(x, y)
17356
28cf0a7943cf No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents: 16134
diff changeset
415
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
416 x = (1, ())
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
417 s = self.dumps(x, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
418 y = self.loads(s)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
419 self.assertEqual(x, y)
17356
28cf0a7943cf No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents: 16134
diff changeset
420
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
421 x = initarg(1, x)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
422 s = self.dumps(x, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
423 y = self.loads(s)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
424 self.assertEqual(x, y)
17356
28cf0a7943cf No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents: 16134
diff changeset
425
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
426 # XXX test __reduce__ protocol?
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
427
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
428 def test_roundtrip_equality(self):
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
429 expected = self._testdata
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
430 for proto in protocols:
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
431 s = self.dumps(expected, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
432 got = self.loads(s)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
433 self.assertEqual(expected, got)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
434
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
435 def test_load_from_canned_string(self):
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
436 expected = self._testdata
28132
97b97e57190c test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents: 27951
diff changeset
437 for canned in DATA0, DATA1, DATA2:
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
438 got = self.loads(canned)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
439 self.assertEqual(expected, got)
17356
28cf0a7943cf No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents: 16134
diff changeset
440
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
441 # There are gratuitous differences between pickles produced by
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
442 # pickle and cPickle, largely because cPickle starts PUT indices at
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
443 # 1 and pickle starts them at 0. See XXX comment in cPickle's put2() --
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
444 # there's a comment with an exclamation point there whose meaning
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
445 # is a mystery. cPickle also suppresses PUT for objects with a refcount
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
446 # of 1.
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
447 def dont_test_disassembly(self):
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
448 from pickletools import dis
17356
28cf0a7943cf No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents: 16134
diff changeset
449
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
450 for proto, expected in (0, DATA0_DIS), (1, DATA1_DIS):
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
451 s = self.dumps(self._testdata, proto)
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
452 filelike = cStringIO.StringIO()
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
453 dis(s, out=filelike)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
454 got = filelike.getvalue()
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
455 self.assertEqual(expected, got)
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
456
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
457 def test_recursive_list(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
458 l = []
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
459 l.append(l)
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
460 for proto in protocols:
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
461 s = self.dumps(l, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
462 x = self.loads(s)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
463 self.assertEqual(len(x), 1)
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
464 self.assert_(x is x[0])
17356
28cf0a7943cf No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents: 16134
diff changeset
465
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
466 def test_recursive_dict(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
467 d = {}
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
468 d[1] = d
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
469 for proto in protocols:
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
470 s = self.dumps(d, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
471 x = self.loads(s)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
472 self.assertEqual(x.keys(), [1])
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
473 self.assert_(x[1] is x)
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
474
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
475 def test_recursive_inst(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
476 i = C()
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
477 i.attr = i
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
478 for proto in protocols:
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
479 s = self.dumps(i, 2)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
480 x = self.loads(s)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
481 self.assertEqual(dir(x), dir(i))
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
482 self.assert_(x.attr is x)
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
483
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
484 def test_recursive_multi(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
485 l = []
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
486 d = {1:l}
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
487 i = C()
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
488 i.attr = d
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
489 l.append(i)
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
490 for proto in protocols:
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
491 s = self.dumps(l, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
492 x = self.loads(s)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
493 self.assertEqual(len(x), 1)
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
494 self.assertEqual(dir(x[0]), dir(i))
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
495 self.assertEqual(x[0].attr.keys(), [1])
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 28135
diff changeset
496 self.assert_(x[0].attr[1] is x)
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
497
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
498 def test_garyp(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
499 self.assertRaises(self.error, self.loads, 'garyp')
16133
d48018b33e35 Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
500
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
501 def test_insecure_strings(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
502 insecure = ["abc", "2 + 2", # not quoted
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24710
diff changeset
503 #"'abc' + 'def'", # not a single quoted string
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
504 "'abc", # quote is not closed
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
505 "'abc\"", # open quote and close quote don't match
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
506 "'abc' ?", # junk after close quote
24809
c75cdc471b22 Check for trailing backslash. Fixes #593656.
Martin v. Löwis <martin@v.loewis.de>
parents: 24808
diff changeset
507 "'\\'", # trailing backslash
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
508 # some tests of the quoting rules
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24710
diff changeset
509 #"'abc\"\''",
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24710
diff changeset
510 #"'\\\\a\'\'\'\\\'\\\\\''",
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
511 ]
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
512 for s in insecure:
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
513 buf = "S" + s + "\012p0\012."
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
514 self.assertRaises(ValueError, self.loads, buf)
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
515
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 17538
diff changeset
516 if have_unicode:
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
517 def test_unicode(self):
50305
e673632e1885 Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50290
diff changeset
518 endcases = [u'', u'<\\u>', u'<\\\u1234>', u'<\n>',
e673632e1885 Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50290
diff changeset
519 u'<\\>', u'<\\\U00012345>']
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
520 for proto in protocols:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
521 for u in endcases:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
522 p = self.dumps(u, proto)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
523 u2 = self.loads(p)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
524 self.assertEqual(u2, u)
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
525
50290
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
526 def test_unicode_high_plane(self):
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
527 t = u'\U00012345'
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
528 for proto in protocols:
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
529 p = self.dumps(t, proto)
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
530 t2 = self.loads(p)
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
531 self.assertEqual(t2, t)
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
532
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
533 def test_ints(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
534 import sys
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
535 for proto in protocols:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
536 n = sys.maxint
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
537 while n:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
538 for expected in (-n, n):
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
539 s = self.dumps(expected, proto)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
540 n2 = self.loads(s)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
541 self.assertEqual(expected, n2)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
542 n = n >> 1
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
543
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
544 def test_maxint64(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
545 maxint64 = (1L << 63) - 1
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
546 data = 'I' + str(maxint64) + '\n.'
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
547 got = self.loads(data)
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
548 self.assertEqual(got, maxint64)
17365
11e8bb4d845d Test full range of native ints. This exposes two more binary pickle
Tim Peters <tim.peters@gmail.com>
parents: 17358
diff changeset
549
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
550 # Try too with a bogus literal.
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
551 data = 'I' + str(maxint64) + 'JUNK\n.'
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
552 self.assertRaises(ValueError, self.loads, data)
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
553
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
554 def test_long(self):
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
555 for proto in protocols:
27587
7283140d4319 long(string, base) now takes time linear in len(string) when base is a
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
556 # 256 bytes is where LONG4 begins.
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
557 for nbits in 1, 8, 8*254, 8*255, 8*256, 8*257:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
558 nbase = 1L << nbits
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
559 for npos in nbase-1, nbase, nbase+1:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
560 for n in npos, -npos:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
561 pickle = self.dumps(n, proto)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
562 got = self.loads(pickle)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
563 self.assertEqual(n, got)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
564 # Try a monster. This is quadratic-time in protos 0 & 1, so don't
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
565 # bother with those.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
566 nbase = long("deadbeeffeedface", 16)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
567 nbase += nbase << 1000000
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
568 for n in nbase, -nbase:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
569 p = self.dumps(n, 2)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
570 got = self.loads(p)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
571 self.assertEqual(n, got)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
572
51020
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
573 def test_float(self):
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
574 test_values = [0.0, 4.94e-324, 1e-310, 7e-308, 6.626e-34, 0.1, 0.5,
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
575 3.14, 263.44582062374053, 6.022e23, 1e30]
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
576 test_values = test_values + [-x for x in test_values]
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
577 for proto in protocols:
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
578 for value in test_values:
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
579 pickle = self.dumps(value, proto)
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
580 got = self.loads(pickle)
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
581 self.assertEqual(value, got)
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50305
diff changeset
582
38055
fcc61835c6ac Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents: 32829
diff changeset
583 @run_with_locale('LC_ALL', 'de_DE', 'fr_FR')
fcc61835c6ac Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents: 32829
diff changeset
584 def test_float_format(self):
fcc61835c6ac Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents: 32829
diff changeset
585 # make sure that floats are formatted locale independent
fcc61835c6ac Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents: 32829
diff changeset
586 self.assertEqual(self.dumps(1.2)[0:3], 'F1.')
fcc61835c6ac Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents: 32829
diff changeset
587
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
588 def test_reduce(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
589 pass
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
590
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
591 def test_getinitargs(self):
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
592 pass
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
593
21488
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
594 def test_metaclass(self):
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
595 a = use_metaclass()
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
596 for proto in protocols:
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
597 s = self.dumps(a, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
598 b = self.loads(s)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
599 self.assertEqual(a.__class__, b.__class__)
21488
bb168de50a03 Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents: 21481
diff changeset
600
22138
ed2a17a376d0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21488
diff changeset
601 def test_structseq(self):
ed2a17a376d0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21488
diff changeset
602 import time
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
603 import os
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
604
22138
ed2a17a376d0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21488
diff changeset
605 t = time.localtime()
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
606 for proto in protocols:
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
607 s = self.dumps(t, proto)
22165
22c66587c452 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22138
diff changeset
608 u = self.loads(s)
22c66587c452 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22138
diff changeset
609 self.assertEqual(t, u)
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
610 if hasattr(os, "stat"):
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
611 t = os.stat(os.curdir)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
612 s = self.dumps(t, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
613 u = self.loads(s)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
614 self.assertEqual(t, u)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
615 if hasattr(os, "statvfs"):
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
616 t = os.statvfs(os.curdir)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
617 s = self.dumps(t, proto)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
618 u = self.loads(s)
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27591
diff changeset
619 self.assertEqual(t, u)
22138
ed2a17a376d0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21488
diff changeset
620
27456
115ee40518a8 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents: 26202
diff changeset
621 # Tests for protocol 2
115ee40518a8 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents: 26202
diff changeset
622
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
623 def test_proto(self):
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
624 build_none = pickle.NONE + pickle.STOP
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
625 for proto in protocols:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
626 expected = build_none
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
627 if proto >= 2:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
628 expected = pickle.PROTO + chr(proto) + expected
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
629 p = self.dumps(None, proto)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
630 self.assertEqual(p, expected)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
631
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
632 oob = protocols[-1] + 1 # a future protocol
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
633 badpickle = pickle.PROTO + chr(oob) + build_none
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
634 try:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
635 self.loads(badpickle)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
636 except ValueError, detail:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
637 self.failUnless(str(detail).startswith(
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
638 "unsupported pickle protocol"))
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
639 else:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
640 self.fail("expected bad protocol number to raise ValueError")
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
641
27456
115ee40518a8 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents: 26202
diff changeset
642 def test_long1(self):
115ee40518a8 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents: 26202
diff changeset
643 x = 12345678910111213141516178920L
27655
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
644 for proto in protocols:
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
645 s = self.dumps(x, proto)
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
646 y = self.loads(s)
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
647 self.assertEqual(x, y)
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
648 self.assertEqual(opcode_in_pickle(pickle.LONG1, s), proto >= 2)
27456
115ee40518a8 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents: 26202
diff changeset
649
115ee40518a8 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents: 26202
diff changeset
650 def test_long4(self):
115ee40518a8 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents: 26202
diff changeset
651 x = 12345678910111213141516178920L << (256*8)
27655
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
652 for proto in protocols:
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
653 s = self.dumps(x, proto)
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
654 y = self.loads(s)
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
655 self.assertEqual(x, y)
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
656 self.assertEqual(opcode_in_pickle(pickle.LONG4, s), proto >= 2)
27456
115ee40518a8 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents: 26202
diff changeset
657
27459
ea480406cc65 More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents: 27456
diff changeset
658 def test_short_tuples(self):
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
659 # Map (proto, len(tuple)) to expected opcode.
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
660 expected_opcode = {(0, 0): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
661 (0, 1): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
662 (0, 2): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
663 (0, 3): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
664 (0, 4): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
665
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
666 (1, 0): pickle.EMPTY_TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
667 (1, 1): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
668 (1, 2): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
669 (1, 3): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
670 (1, 4): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
671
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
672 (2, 0): pickle.EMPTY_TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
673 (2, 1): pickle.TUPLE1,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
674 (2, 2): pickle.TUPLE2,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
675 (2, 3): pickle.TUPLE3,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
676 (2, 4): pickle.TUPLE,
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
677 }
27459
ea480406cc65 More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents: 27456
diff changeset
678 a = ()
27460
0554b7c5f6d7 Shouldn't test short tuples with all items equal -- one potential bug
Guido van Rossum <guido@python.org>
parents: 27459
diff changeset
679 b = (1,)
0554b7c5f6d7 Shouldn't test short tuples with all items equal -- one potential bug
Guido van Rossum <guido@python.org>
parents: 27459
diff changeset
680 c = (1, 2)
0554b7c5f6d7 Shouldn't test short tuples with all items equal -- one potential bug
Guido van Rossum <guido@python.org>
parents: 27459
diff changeset
681 d = (1, 2, 3)
0554b7c5f6d7 Shouldn't test short tuples with all items equal -- one potential bug
Guido van Rossum <guido@python.org>
parents: 27459
diff changeset
682 e = (1, 2, 3, 4)
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
683 for proto in protocols:
27459
ea480406cc65 More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents: 27456
diff changeset
684 for x in a, b, c, d, e:
ea480406cc65 More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents: 27456
diff changeset
685 s = self.dumps(x, proto)
ea480406cc65 More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents: 27456
diff changeset
686 y = self.loads(s)
ea480406cc65 More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents: 27456
diff changeset
687 self.assertEqual(x, y, (proto, x, s, y))
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
688 expected = expected_opcode[proto, len(x)]
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
689 self.assertEqual(opcode_in_pickle(expected, s), True)
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
690
27461
883af28b9a0d OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents: 27460
diff changeset
691 def test_singletons(self):
27655
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
692 # Map (proto, singleton) to expected opcode.
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
693 expected_opcode = {(0, None): pickle.NONE,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
694 (1, None): pickle.NONE,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
695 (2, None): pickle.NONE,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
696
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
697 (0, True): pickle.INT,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
698 (1, True): pickle.INT,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
699 (2, True): pickle.NEWTRUE,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
700
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
701 (0, False): pickle.INT,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
702 (1, False): pickle.INT,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
703 (2, False): pickle.NEWFALSE,
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
704 }
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27587
diff changeset
705 for proto in protocols:
27461
883af28b9a0d OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents: 27460
diff changeset
706 for x in None, False, True:
883af28b9a0d OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents: 27460
diff changeset
707 s = self.dumps(x, proto)
883af28b9a0d OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents: 27460
diff changeset
708 y = self.loads(s)
883af28b9a0d OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents: 27460
diff changeset
709 self.assert_(x is y, (proto, x, s, y))
27655
e11e976fee78 Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents: 27645
diff changeset
710 expected = expected_opcode[proto, x]
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
711 self.assertEqual(opcode_in_pickle(expected, s), True)
27599
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
712
27482
7c8dfd3f4ae9 Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents: 27461
diff changeset
713 def test_newobj_tuple(self):
27486
e9578747f43d The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents: 27482
diff changeset
714 x = MyTuple([1, 2, 3])
e9578747f43d The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents: 27482
diff changeset
715 x.foo = 42
e9578747f43d The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents: 27482
diff changeset
716 x.bar = "hello"
27659
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
717 for proto in protocols:
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
718 s = self.dumps(x, proto)
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
719 y = self.loads(s)
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
720 self.assertEqual(tuple(x), tuple(y))
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
721 self.assertEqual(x.__dict__, y.__dict__)
27482
7c8dfd3f4ae9 Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents: 27461
diff changeset
722
7c8dfd3f4ae9 Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents: 27461
diff changeset
723 def test_newobj_list(self):
27486
e9578747f43d The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents: 27482
diff changeset
724 x = MyList([1, 2, 3])
e9578747f43d The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents: 27482
diff changeset
725 x.foo = 42
e9578747f43d The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents: 27482
diff changeset
726 x.bar = "hello"
27659
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
727 for proto in protocols:
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
728 s = self.dumps(x, proto)
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
729 y = self.loads(s)
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
730 self.assertEqual(list(x), list(y))
0bbbcacc05fb test_newobj_tuple(), test_newobj_list(): These tests should work under
Tim Peters <tim.peters@gmail.com>
parents: 27658
diff changeset
731 self.assertEqual(x.__dict__, y.__dict__)
27482
7c8dfd3f4ae9 Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents: 27461
diff changeset
732
27521
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
733 def test_newobj_generic(self):
27658
b595c4735fcc test_newobj_generic(): Use the global protocols vector instead of a
Tim Peters <tim.peters@gmail.com>
parents: 27657
diff changeset
734 for proto in protocols:
27521
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
735 for C in myclasses:
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
736 B = C.__base__
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
737 x = C(C.sample)
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
738 x.foo = 42
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
739 s = self.dumps(x, proto)
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
740 y = self.loads(s)
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
741 detail = (proto, C, B, x, y, type(y))
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
742 self.assertEqual(B(x), B(y), detail)
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
743 self.assertEqual(x.__dict__, y.__dict__, detail)
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
744
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
745 # Register a type with copy_reg, with extension code extcode. Pickle
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
746 # an object of that type. Check that the resulting pickle uses opcode
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
747 # (EXT[124]) under proto 2, and not in proto 1.
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
748
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
749 def produce_global_ext(self, extcode, opcode):
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
750 e = ExtensionSaver(extcode)
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
751 try:
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
752 copy_reg.add_extension(__name__, "MyList", extcode)
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
753 x = MyList([1, 2, 3])
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
754 x.foo = 42
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
755 x.bar = "hello"
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
756
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
757 # Dump using protocol 1 for comparison.
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
758 s1 = self.dumps(x, 1)
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
759 self.assert_(__name__ in s1)
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
760 self.assert_("MyList" in s1)
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
761 self.assertEqual(opcode_in_pickle(opcode, s1), False)
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
762
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
763 y = self.loads(s1)
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
764 self.assertEqual(list(x), list(y))
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
765 self.assertEqual(x.__dict__, y.__dict__)
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
766
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
767 # Dump using protocol 2 for test.
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
768 s2 = self.dumps(x, 2)
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
769 self.assert_(__name__ not in s2)
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
770 self.assert_("MyList" not in s2)
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
771 self.assertEqual(opcode_in_pickle(opcode, s2), True)
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
772
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
773 y = self.loads(s2)
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
774 self.assertEqual(list(x), list(y))
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
775 self.assertEqual(x.__dict__, y.__dict__)
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
776
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
777 finally:
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
778 e.restore()
27657
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
779
67315026d6d3 Added a bit to the EXT[124] tests, and refactored them to squash code
Tim Peters <tim.peters@gmail.com>
parents: 27655
diff changeset
780 def test_global_ext1(self):
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
781 self.produce_global_ext(0x00000001, pickle.EXT1) # smallest EXT1 code
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
782 self.produce_global_ext(0x000000ff, pickle.EXT1) # largest EXT1 code
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
783
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
784 def test_global_ext2(self):
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
785 self.produce_global_ext(0x00000100, pickle.EXT2) # smallest EXT2 code
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
786 self.produce_global_ext(0x0000ffff, pickle.EXT2) # largest EXT2 code
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
787 self.produce_global_ext(0x0000abcd, pickle.EXT2) # check endianness
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
788
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
789 def test_global_ext4(self):
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
790 self.produce_global_ext(0x00010000, pickle.EXT4) # smallest EXT4 code
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
791 self.produce_global_ext(0x7fffffff, pickle.EXT4) # largest EXT4 code
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
792 self.produce_global_ext(0x12abcdef, pickle.EXT4) # check endianness
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
793
27813
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
794 def test_list_chunking(self):
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
795 n = 10 # too small to chunk
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
796 x = range(n)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
797 for proto in protocols:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
798 s = self.dumps(x, proto)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
799 y = self.loads(s)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
800 self.assertEqual(x, y)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
801 num_appends = count_opcode(pickle.APPENDS, s)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
802 self.assertEqual(num_appends, proto > 0)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
803
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
804 n = 2500 # expect at least two chunks when proto > 0
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
805 x = range(n)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
806 for proto in protocols:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
807 s = self.dumps(x, proto)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
808 y = self.loads(s)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
809 self.assertEqual(x, y)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
810 num_appends = count_opcode(pickle.APPENDS, s)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
811 if proto == 0:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
812 self.assertEqual(num_appends, 0)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
813 else:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
814 self.failUnless(num_appends >= 2)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
815
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
816 def test_dict_chunking(self):
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
817 n = 10 # too small to chunk
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
818 x = dict.fromkeys(range(n))
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
819 for proto in protocols:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
820 s = self.dumps(x, proto)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
821 y = self.loads(s)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
822 self.assertEqual(x, y)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
823 num_setitems = count_opcode(pickle.SETITEMS, s)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
824 self.assertEqual(num_setitems, proto > 0)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
825
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
826 n = 2500 # expect at least two chunks when proto > 0
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
827 x = dict.fromkeys(range(n))
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
828 for proto in protocols:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
829 s = self.dumps(x, proto)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
830 y = self.loads(s)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
831 self.assertEqual(x, y)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
832 num_setitems = count_opcode(pickle.SETITEMS, s)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
833 if proto == 0:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
834 self.assertEqual(num_setitems, 0)
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
835 else:
f6c95f9138ad Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
836 self.failUnless(num_setitems >= 2)
27510
20c581c23bce Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents: 27500
diff changeset
837
27872
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
838 def test_simple_newobj(self):
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
839 x = object.__new__(SimpleNewObj) # avoid __init__
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
840 x.abc = 666
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
841 for proto in protocols:
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
842 s = self.dumps(x, proto)
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
843 self.assertEqual(opcode_in_pickle(pickle.NEWOBJ, s), proto >= 2)
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
844 y = self.loads(s) # will raise TypeError if __init__ called
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
845 self.assertEqual(y.abc, 666)
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
846 self.assertEqual(x.__dict__, y.__dict__)
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
847
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
848 def test_newobj_list_slots(self):
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
849 x = SlotList([1, 2, 3])
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
850 x.foo = 42
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
851 x.bar = "hello"
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
852 s = self.dumps(x, 2)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
853 y = self.loads(s)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
854 self.assertEqual(list(x), list(y))
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
855 self.assertEqual(x.__dict__, y.__dict__)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
856 self.assertEqual(x.foo, y.foo)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
857 self.assertEqual(x.bar, y.bar)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
858
27951
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
859 def test_reduce_overrides_default_reduce_ex(self):
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
860 for proto in protocols:
27951
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
861 x = REX_one()
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
862 self.assertEqual(x._reduce_called, 0)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
863 s = self.dumps(x, proto)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
864 self.assertEqual(x._reduce_called, 1)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
865 y = self.loads(s)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
866 self.assertEqual(y._reduce_called, 0)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
867
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
868 def test_reduce_ex_called(self):
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
869 for proto in protocols:
27951
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
870 x = REX_two()
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
871 self.assertEqual(x._proto, None)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
872 s = self.dumps(x, proto)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
873 self.assertEqual(x._proto, proto)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
874 y = self.loads(s)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
875 self.assertEqual(y._proto, None)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
876
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
877 def test_reduce_ex_overrides_reduce(self):
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
878 for proto in protocols:
27951
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
879 x = REX_three()
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
880 self.assertEqual(x._proto, None)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
881 s = self.dumps(x, proto)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
882 self.assertEqual(x._proto, proto)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
883 y = self.loads(s)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
884 self.assertEqual(y._proto, None)
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
885
41201
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
886 def test_reduce_ex_calls_base(self):
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
887 for proto in protocols:
41201
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
888 x = REX_four()
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
889 self.assertEqual(x._proto, None)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
890 s = self.dumps(x, proto)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
891 self.assertEqual(x._proto, proto)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
892 y = self.loads(s)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
893 self.assertEqual(y._proto, proto)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
894
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
895 def test_reduce_calls_base(self):
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
896 for proto in protocols:
41201
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
897 x = REX_five()
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
898 self.assertEqual(x._reduce_called, 0)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
899 s = self.dumps(x, proto)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
900 self.assertEqual(x._reduce_called, 1)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
901 y = self.loads(s)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
902 self.assertEqual(y._reduce_called, 1)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
903
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
904 def test_reduce_bad_iterator(self):
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
905 # Issue4176: crash when 4th and 5th items of __reduce__()
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
906 # are not iterators
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
907 class C(object):
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
908 def __reduce__(self):
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
909 # 4th item is not an iterator
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
910 return list, (), None, [], None
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
911 class D(object):
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
912 def __reduce__(self):
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
913 # 5th item is not an iterator
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
914 return dict, (), None, None, []
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
915
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
916 # Protocol 0 is less strict and also accept iterables.
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
917 for proto in protocols:
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
918 try:
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
919 self.dumps(C(), proto)
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
920 except (AttributeError, pickle.PickleError, cPickle.PickleError):
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
921 pass
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
922 try:
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
923 self.dumps(D(), proto)
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
924 except (AttributeError, pickle.PickleError, cPickle.PickleError):
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
925 pass
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47189
diff changeset
926
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
927 def test_many_puts_and_gets(self):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
928 # Test that internal data structures correctly deal with lots of
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
929 # puts/gets.
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
930 keys = ("aaa" + str(i) for i in xrange(100))
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
931 large_dict = dict((k, [4, 5, 6]) for k in keys)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
932 obj = [dict(large_dict), dict(large_dict), dict(large_dict)]
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
933
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
934 for proto in protocols:
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
935 dumped = self.dumps(obj, proto)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
936 loaded = self.loads(dumped)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
937 self.assertEqual(loaded, obj,
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
938 "Failed protocol %d: %r != %r"
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
939 % (proto, obj, loaded))
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
940
53693
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
941 def test_attribute_name_interning(self):
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
942 # Test that attribute names of pickled objects are interned when
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
943 # unpickling.
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
944 for proto in protocols:
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
945 x = C()
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
946 x.foo = 42
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
947 x.bar = "hello"
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
948 s = self.dumps(x, proto)
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
949 y = self.loads(s)
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
950 x_keys = sorted(x.__dict__)
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
951 y_keys = sorted(y.__dict__)
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
952 for x_key, y_key in zip(x_keys, y_keys):
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
953 self.assertIs(x_key, y_key)
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53000
diff changeset
954
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
955
27951
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
956 # Test classes for reduce_ex
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
957
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
958 class REX_one(object):
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
959 _reduce_called = 0
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
960 def __reduce__(self):
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
961 self._reduce_called = 1
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
962 return REX_one, ()
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
963 # No __reduce_ex__ here, but inheriting it from object
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
964
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
965 class REX_two(object):
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
966 _proto = None
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
967 def __reduce_ex__(self, proto):
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
968 self._proto = proto
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
969 return REX_two, ()
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
970 # No __reduce__ here, but inheriting it from object
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
971
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
972 class REX_three(object):
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
973 _proto = None
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
974 def __reduce_ex__(self, proto):
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
975 self._proto = proto
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
976 return REX_two, ()
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
977 def __reduce__(self):
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
978 raise TestFailed, "This __reduce__ shouldn't be called"
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
979
41201
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
980 class REX_four(object):
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
981 _proto = None
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
982 def __reduce_ex__(self, proto):
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
983 self._proto = proto
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
984 return object.__reduce_ex__(self, proto)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
985 # Calling base class method should succeed
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
986
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
987 class REX_five(object):
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
988 _reduce_called = 0
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
989 def __reduce__(self):
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
990 self._reduce_called = 1
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
991 return object.__reduce__(self)
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
992 # This one used to fail with infinite recursion
4217f3850f0b Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents: 38055
diff changeset
993
27951
b540e608bb8a Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents: 27901
diff changeset
994 # Test classes for newobj
27901
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
995
27521
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
996 class MyInt(int):
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
997 sample = 1
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
998
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
999 class MyLong(long):
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1000 sample = 1L
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1001
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1002 class MyFloat(float):
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1003 sample = 1.0
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1004
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1005 class MyComplex(complex):
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1006 sample = 1.0 + 0.0j
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1007
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1008 class MyStr(str):
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1009 sample = "hello"
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1010
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1011 class MyUnicode(unicode):
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1012 sample = u"hello \u1234"
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1013
27482
7c8dfd3f4ae9 Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents: 27461
diff changeset
1014 class MyTuple(tuple):
27521
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1015 sample = (1, 2, 3)
27482
7c8dfd3f4ae9 Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents: 27461
diff changeset
1016
7c8dfd3f4ae9 Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents: 27461
diff changeset
1017 class MyList(list):
27521
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1018 sample = [1, 2, 3]
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1019
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1020 class MyDict(dict):
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1021 sample = {"a": 1, "b": 2}
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1022
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1023 myclasses = [MyInt, MyLong, MyFloat,
28135
b53455a51b78 MyComplex now works.
Guido van Rossum <guido@python.org>
parents: 28132
diff changeset
1024 MyComplex,
27521
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1025 MyStr, MyUnicode,
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1026 MyTuple, MyList, MyDict]
17bfd5dbc0f1 Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents: 27510
diff changeset
1027
27482
7c8dfd3f4ae9 Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents: 27461
diff changeset
1028
27494
1f16abfaf63e Add a test for a list subclass with a __dict__ as well as slots.
Guido van Rossum <guido@python.org>
parents: 27486
diff changeset
1029 class SlotList(MyList):
1f16abfaf63e Add a test for a list subclass with a __dict__ as well as slots.
Guido van Rossum <guido@python.org>
parents: 27486
diff changeset
1030 __slots__ = ["foo"]
1f16abfaf63e Add a test for a list subclass with a __dict__ as well as slots.
Guido van Rossum <guido@python.org>
parents: 27486
diff changeset
1031
27872
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
1032 class SimpleNewObj(object):
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
1033 def __init__(self, a, b, c):
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
1034 # raise an error, to make sure this isn't called
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
1035 raise TypeError("SimpleNewObj.__init__() didn't expect to get called")
11e6123de6fe Added a simple NEWOBJ test. This is in the pickle-only part of the
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
1036
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
1037 class AbstractPickleModuleTests(unittest.TestCase):
19544
d711e82ece23 pickle.py, load_int(): Match cPickle's just-repaired ability to unpickle
Tim Peters <tim.peters@gmail.com>
parents: 19343
diff changeset
1038
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
1039 def test_dump_closed_file(self):
24710
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1040 import os
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1041 f = open(TESTFN, "w")
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1042 try:
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1043 f.close()
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1044 self.assertRaises(ValueError, self.module.dump, 123, f)
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1045 finally:
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1046 os.remove(TESTFN)
20444
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
1047
bc905a11c148 Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19544
diff changeset
1048 def test_load_closed_file(self):
24710
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1049 import os
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1050 f = open(TESTFN, "w")
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1051 try:
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1052 f.close()
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1053 self.assertRaises(ValueError, self.module.dump, 123, f)
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1054 finally:
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24442
diff changeset
1055 os.remove(TESTFN)
26202
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1056
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1057 def test_load_from_and_dump_to_file(self):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1058 stream = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1059 data = [123, {}, 124]
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1060 self.module.dump(data, stream)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1061 stream.seek(0)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1062 unpickled = self.module.load(stream)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1063 self.assertEqual(unpickled, data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1064
27874
6af780e0862d We didn't have any tests making pickles with one of {pickle, cPickle},
Tim Peters <tim.peters@gmail.com>
parents: 27872
diff changeset
1065 def test_highest_protocol(self):
6af780e0862d We didn't have any tests making pickles with one of {pickle, cPickle},
Tim Peters <tim.peters@gmail.com>
parents: 27872
diff changeset
1066 # Of course this needs to be changed when HIGHEST_PROTOCOL changes.
6af780e0862d We didn't have any tests making pickles with one of {pickle, cPickle},
Tim Peters <tim.peters@gmail.com>
parents: 27872
diff changeset
1067 self.assertEqual(self.module.HIGHEST_PROTOCOL, 2)
6af780e0862d We didn't have any tests making pickles with one of {pickle, cPickle},
Tim Peters <tim.peters@gmail.com>
parents: 27872
diff changeset
1068
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 30801
diff changeset
1069 def test_callapi(self):
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1070 f = cStringIO.StringIO()
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 30801
diff changeset
1071 # With and without keyword arguments
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 30801
diff changeset
1072 self.module.dump(123, f, -1)
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 30801
diff changeset
1073 self.module.dump(123, file=f, protocol=-1)
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 30801
diff changeset
1074 self.module.dumps(123, -1)
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 30801
diff changeset
1075 self.module.dumps(123, protocol=-1)
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 30801
diff changeset
1076 self.module.Pickler(f, -1)
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 30801
diff changeset
1077 self.module.Pickler(f, protocol=-1)
27874
6af780e0862d We didn't have any tests making pickles with one of {pickle, cPickle},
Tim Peters <tim.peters@gmail.com>
parents: 27872
diff changeset
1078
26202
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1079 class AbstractPersistentPicklerTests(unittest.TestCase):
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1080
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1081 # This class defines persistent_id() and persistent_load()
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1082 # functions that should be used by the pickler. All even integers
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1083 # are pickled using persistent ids.
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1084
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1085 def persistent_id(self, object):
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1086 if isinstance(object, int) and object % 2 == 0:
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1087 self.id_count += 1
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1088 return str(object)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1089 else:
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1090 return None
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1091
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1092 def persistent_load(self, oid):
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1093 self.load_count += 1
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1094 object = int(oid)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1095 assert object % 2 == 0
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1096 return object
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1097
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1098 def test_persistence(self):
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1099 self.id_count = 0
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1100 self.load_count = 0
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1101 L = range(10)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1102 self.assertEqual(self.loads(self.dumps(L)), L)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1103 self.assertEqual(self.id_count, 5)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1104 self.assertEqual(self.load_count, 5)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1105
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1106 def test_bin_persistence(self):
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1107 self.id_count = 0
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1108 self.load_count = 0
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1109 L = range(10)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1110 self.assertEqual(self.loads(self.dumps(L, 1)), L)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1111 self.assertEqual(self.id_count, 5)
1cd8106bcd20 Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24809
diff changeset
1112 self.assertEqual(self.load_count, 5)
53000
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1113
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1114 class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1115
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1116 pickler_class = None
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1117 unpickler_class = None
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1118
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1119 def setUp(self):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1120 assert self.pickler_class
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1121 assert self.unpickler_class
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1122
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1123 def test_clear_pickler_memo(self):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1124 # To test whether clear_memo() has any effect, we pickle an object,
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1125 # then pickle it again without clearing the memo; the two serialized
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1126 # forms should be different. If we clear_memo() and then pickle the
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1127 # object again, the third serialized form should be identical to the
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1128 # first one we obtained.
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1129 data = ["abcdefg", "abcdefg", 44]
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1130 f = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1131 pickler = self.pickler_class(f)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1132
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1133 pickler.dump(data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1134 first_pickled = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1135
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1136 # Reset StringIO object.
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1137 f.seek(0)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1138 f.truncate()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1139
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1140 pickler.dump(data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1141 second_pickled = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1142
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1143 # Reset the Pickler and StringIO objects.
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1144 pickler.clear_memo()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1145 f.seek(0)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1146 f.truncate()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1147
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1148 pickler.dump(data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1149 third_pickled = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1150
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1151 self.assertNotEqual(first_pickled, second_pickled)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1152 self.assertEqual(first_pickled, third_pickled)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1153
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1154 def test_priming_pickler_memo(self):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1155 # Verify that we can set the Pickler's memo attribute.
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1156 data = ["abcdefg", "abcdefg", 44]
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1157 f = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1158 pickler = self.pickler_class(f)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1159
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1160 pickler.dump(data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1161 first_pickled = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1162
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1163 f = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1164 primed = self.pickler_class(f)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1165 primed.memo = pickler.memo
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1166
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1167 primed.dump(data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1168 primed_pickled = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1169
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1170 self.assertNotEqual(first_pickled, primed_pickled)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1171
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1172 def test_priming_unpickler_memo(self):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1173 # Verify that we can set the Unpickler's memo attribute.
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1174 data = ["abcdefg", "abcdefg", 44]
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1175 f = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1176 pickler = self.pickler_class(f)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1177
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1178 pickler.dump(data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1179 first_pickled = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1180
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1181 f = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1182 primed = self.pickler_class(f)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1183 primed.memo = pickler.memo
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1184
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1185 primed.dump(data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1186 primed_pickled = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1187
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1188 unpickler = self.unpickler_class(cStringIO.StringIO(first_pickled))
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1189 unpickled_data1 = unpickler.load()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1190
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1191 self.assertEqual(unpickled_data1, data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1192
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1193 primed = self.unpickler_class(cStringIO.StringIO(primed_pickled))
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1194 primed.memo = unpickler.memo
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1195 unpickled_data2 = primed.load()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1196
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1197 primed.memo.clear()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1198
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1199 self.assertEqual(unpickled_data2, data)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1200 self.assertTrue(unpickled_data2 is unpickled_data1)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1201
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1202 def test_reusing_unpickler_objects(self):
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1203 data1 = ["abcdefg", "abcdefg", 44]
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1204 f = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1205 pickler = self.pickler_class(f)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1206 pickler.dump(data1)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1207 pickled1 = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1208
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1209 data2 = ["abcdefg", 44, 44]
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1210 f = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1211 pickler = self.pickler_class(f)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1212 pickler.dump(data2)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1213 pickled2 = f.getvalue()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1214
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1215 f = cStringIO.StringIO()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1216 f.write(pickled1)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1217 f.seek(0)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1218 unpickler = self.unpickler_class(f)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1219 self.assertEqual(unpickler.load(), data1)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1220
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1221 f.seek(0)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1222 f.truncate()
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1223 f.write(pickled2)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1224 f.seek(0)
9a7317ce6db9 Issue 5665: add more pickling tests.
Collin Winter <collinw@gmail.com>
parents: 51020
diff changeset
1225 self.assertEqual(unpickler.load(), data2)