Mercurial > cpython-lru_cache-weakref
annotate Lib/test/pickletester.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | afe6dde80abb |
| children | 787b969d37f0 |
| 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 |
|
55430
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
4 import StringIO |
|
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 |
|
38055
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
32829
diff
changeset
|
8 from test.test_support import TestFailed, have_unicode, TESTFN, \ |
|
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
32829
diff
changeset
|
9 run_with_locale |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
10 |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27573
diff
changeset
|
11 # 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
|
12 # 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
|
13 # 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
|
14 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
|
15 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
|
16 |
|
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
|
17 |
|
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
|
18 # 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
25 # 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
|
26 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
|
27 n = 0 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
28 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
|
29 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
|
30 n += 1 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
31 return n |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
32 |
|
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
|
33 # 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
|
34 # 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
|
35 # 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
|
36 # |
|
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
|
37 # 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
|
38 # 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
|
39 # 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
|
40 # 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
|
41 # 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
|
42 |
|
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
|
43 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
|
44 # 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
|
45 # 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
|
46 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
|
47 self.code = code |
|
47189
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
48 if code in copy_reg._inverted_registry: |
|
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
49 self.pair = copy_reg._inverted_registry[code] |
|
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 |
|
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
|
54 # 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
|
55 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
|
56 code = self.code |
|
47189
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
57 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
|
58 if curpair is not None: |
|
47189
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
59 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
|
60 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
|
61 if pair is not None: |
|
47189
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
62 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
|
63 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
64 class C: |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
65 def __cmp__(self, other): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
66 return cmp(self.__dict__, other.__dict__) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
67 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
68 import __main__ |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
69 __main__.C = C |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
70 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
|
71 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
72 class myint(int): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
73 def __init__(self, x): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
74 self.str = str(x) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
75 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
76 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
|
77 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
78 def __init__(self, a, b): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
79 self.a = a |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
80 self.b = b |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
81 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
82 def __getinitargs__(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
83 return self.a, self.b |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
84 |
|
21488
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
85 class metaclass(type): |
|
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
86 pass |
|
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
87 |
|
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
88 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
|
89 __metaclass__ = metaclass |
|
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
90 |
|
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
|
91 # 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
|
92 # 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
|
93 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
94 # 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
|
95 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
|
96 I0 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
97 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
|
98 aF2 |
|
16133
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
99 ac__builtin__ |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
100 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
|
101 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
|
102 """ + \ |
|
3aaedbac95b3
Pickles have a number of storage formats for various sizes and kinds of
Tim Peters <tim.peters@gmail.com>
parents:
17356
diff
changeset
|
103 """(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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 """(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
|
119 p4 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
120 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
|
121 """ + \ |
|
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
|
122 """(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
|
123 C |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
124 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
|
125 """ + \ |
|
16133
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
126 """(dp6 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
127 S'foo' |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
128 p7 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
129 I1 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
130 sS'bar' |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
131 p8 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
132 I2 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
133 sbg5 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
134 tp9 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
135 ag9 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
136 aI5 |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
137 a. |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
138 """ |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
139 |
|
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
|
140 # 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 """ |
|
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 |
|
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 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
|
214 '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
|
215 '\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
|
216 '\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
|
217 '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
|
218 '\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
|
219 '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
|
220 '\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
|
221 ) |
|
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 |
|
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 # 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 """ |
|
20547
a12ccdbce8da
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
20444
diff
changeset
|
279 |
|
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
|
280 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
|
281 '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
|
282 '\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
|
283 '\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
|
284 '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
|
285 '\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
|
286 '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
|
287 |
|
97b97e57190c
test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents:
27951
diff
changeset
|
288 # 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 """ |
|
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 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
345 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
|
346 c = C() |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 # 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
|
351 # 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 x.append(5) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
363 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
|
364 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
365 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
|
366 # 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
|
367 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
368 _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
|
369 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
370 def setUp(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
371 pass |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
372 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
373 def test_misc(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
374 # 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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 |
|
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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 |
|
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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
391 # XXX test __reduce__ protocol? |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
392 |
|
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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 |
|
72228a25daaa
Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents:
27591
diff
changeset
|
400 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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 |
|
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
|
406 # 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
|
407 # 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
|
408 # 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
|
409 # 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
|
410 # 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
|
411 # 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
|
412 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
|
413 from cStringIO import StringIO |
|
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 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
|
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 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
|
417 s = self.dumps(self._testdata, 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 filelike = StringIO() |
|
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 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
|
420 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
|
421 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
|
422 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
423 def test_recursive_list(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
424 l = [] |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
425 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
|
426 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
|
427 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
|
428 x = self.loads(s) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
429 self.assertEqual(len(x), 1) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
430 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
|
431 |
|
54344
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
432 def test_recursive_tuple(self): |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
433 t = ([],) |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
434 t[0].append(t) |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
435 for proto in protocols: |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
436 s = self.dumps(t, proto) |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
437 x = self.loads(s) |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
438 self.assertEqual(len(x), 1) |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
439 self.assertEqual(len(x[0]), 1) |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
440 self.assert_(x is x[0][0]) |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
441 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
442 def test_recursive_dict(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
443 d = {} |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
444 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
|
445 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
|
446 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
|
447 x = self.loads(s) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
448 self.assertEqual(x.keys(), [1]) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
449 self.assert_(x[1] is x) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
450 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
451 def test_recursive_inst(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
452 i = C() |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 x = self.loads(s) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
457 self.assertEqual(dir(x), dir(i)) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
458 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
|
459 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
460 def test_recursive_multi(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
461 l = [] |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
462 d = {1:l} |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
463 i = C() |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
464 i.attr = d |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
465 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
|
466 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
|
467 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
|
468 x = self.loads(s) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
469 self.assertEqual(len(x), 1) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
470 self.assertEqual(dir(x[0]), dir(i)) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
471 self.assertEqual(x[0].attr.keys(), [1]) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
472 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
|
473 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
474 def test_garyp(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
475 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
|
476 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
477 def test_insecure_strings(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
478 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
|
479 #"'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
|
480 "'abc", # quote is not closed |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
481 "'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
|
482 "'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
|
483 "'\\'", # trailing backslash |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
484 # 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
|
485 #"'abc\"\''", |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24710
diff
changeset
|
486 #"'\\\\a\'\'\'\\\'\\\\\''", |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
487 ] |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
488 for s in insecure: |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
489 buf = "S" + s + "\012p0\012." |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
490 self.assertRaises(ValueError, self.loads, buf) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
491 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
17538
diff
changeset
|
492 if have_unicode: |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 self.assertEqual(u2, u) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
501 |
|
50290
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
502 def test_unicode_high_plane(self): |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
503 t = u'\U00012345' |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
504 for proto in protocols: |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
505 p = self.dumps(t, proto) |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
506 t2 = self.loads(p) |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
507 self.assertEqual(t2, t) |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
508 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
509 def test_ints(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 n = n >> 1 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
519 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
520 def test_maxint64(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
521 maxint64 = (1L << 63) - 1 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
522 data = 'I' + str(maxint64) + '\n.' |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
523 got = self.loads(data) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
524 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
|
525 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
526 # Try too with a bogus literal. |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
527 data = 'I' + str(maxint64) + 'JUNK\n.' |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
528 self.assertRaises(ValueError, self.loads, data) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
529 |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27573
diff
changeset
|
530 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
|
531 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
|
532 # 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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 # 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
|
541 # 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
|
542 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
|
543 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
|
544 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
|
545 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
|
546 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
|
547 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
|
548 |
|
51020
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
549 def test_float(self): |
|
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
550 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
|
551 3.14, 263.44582062374053, 6.022e23, 1e30] |
|
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
552 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
|
553 for proto in protocols: |
|
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
554 for value in test_values: |
|
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
555 pickle = self.dumps(value, proto) |
|
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
556 got = self.loads(pickle) |
|
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
557 self.assertEqual(value, got) |
|
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
558 |
|
38055
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
32829
diff
changeset
|
559 @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
|
560 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
|
561 # 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
|
562 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
|
563 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
564 def test_reduce(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
565 pass |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
566 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
567 def test_getinitargs(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
568 pass |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
569 |
|
21488
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
570 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 |
|
22138
ed2a17a376d0
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21488
diff
changeset
|
577 def test_structseq(self): |
|
ed2a17a376d0
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21488
diff
changeset
|
578 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
|
579 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
|
580 |
|
22138
ed2a17a376d0
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21488
diff
changeset
|
581 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
|
582 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
|
583 s = self.dumps(t, proto) |
|
22165
22c66587c452
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22138
diff
changeset
|
584 u = self.loads(s) |
|
22c66587c452
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22138
diff
changeset
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 self.assertEqual(t, u) |
|
22138
ed2a17a376d0
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21488
diff
changeset
|
596 |
|
27456
115ee40518a8
First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents:
26202
diff
changeset
|
597 # 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
|
598 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
608 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
|
609 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
|
610 try: |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
611 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
|
612 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
|
613 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
|
614 "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
|
615 else: |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
616 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
|
617 |
|
27456
115ee40518a8
First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents:
26202
diff
changeset
|
618 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
|
619 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
|
620 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
|
621 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
|
622 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
|
623 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
|
624 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
|
625 |
|
115ee40518a8
First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents:
26202
diff
changeset
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 |
|
27459
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
634 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
|
635 # 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
|
636 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
|
637 (0, 1): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
638 (0, 2): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
639 (0, 3): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
640 (0, 4): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
641 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
642 (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
|
643 (1, 1): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
644 (1, 2): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
645 (1, 3): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
646 (1, 4): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
647 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
648 (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
|
649 (2, 1): pickle.TUPLE1, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
650 (2, 2): pickle.TUPLE2, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
651 (2, 3): pickle.TUPLE3, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
652 (2, 4): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
653 } |
|
27459
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 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
|
658 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
|
659 for proto in protocols: |
|
27459
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
660 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
|
661 s = self.dumps(x, proto) |
|
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
662 y = self.loads(s) |
|
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
663 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
|
664 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
|
665 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
|
666 |
|
27461
883af28b9a0d
OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents:
27460
diff
changeset
|
667 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
|
668 # 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
|
669 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
|
670 (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
|
671 (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
|
672 |
|
e11e976fee78
Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents:
27645
diff
changeset
|
673 (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
|
674 (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
|
675 (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
|
676 |
|
e11e976fee78
Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents:
27645
diff
changeset
|
677 (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
|
678 (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
|
679 (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
|
680 } |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
681 for proto in protocols: |
|
27461
883af28b9a0d
OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents:
27460
diff
changeset
|
682 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
|
683 s = self.dumps(x, proto) |
|
883af28b9a0d
OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents:
27460
diff
changeset
|
684 y = self.loads(s) |
|
883af28b9a0d
OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents:
27460
diff
changeset
|
685 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
|
686 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
|
687 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
|
688 |
|
27482
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
689 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
|
690 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
|
691 x.foo = 42 |
|
e9578747f43d
The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents:
27482
diff
changeset
|
692 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 |
|
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
699 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
|
700 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
|
701 x.foo = 42 |
|
e9578747f43d
The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents:
27482
diff
changeset
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
709 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
|
710 for proto in protocols: |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
711 for C in myclasses: |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
712 B = C.__base__ |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
713 x = C(C.sample) |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
714 x.foo = 42 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
715 s = self.dumps(x, proto) |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
716 y = self.loads(s) |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
717 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
|
718 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
|
719 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
|
720 |
|
47189
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
721 # 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
|
722 # 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
|
723 # (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
|
724 |
|
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
|
725 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
|
726 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
|
727 try: |
|
47189
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
728 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
|
729 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
|
730 x.foo = 42 |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
731 x.bar = "hello" |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
732 |
|
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
|
733 # 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
|
734 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
|
735 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
|
736 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
|
737 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
|
738 |
|
27510
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 |
|
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
|
743 # 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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 |
|
27510
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
749 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
|
750 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
|
751 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
|
752 |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
753 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
|
754 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
|
755 |
|
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
|
756 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
|
757 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
|
758 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
|
759 |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
760 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
|
761 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
|
762 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
|
763 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
|
764 |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
765 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
|
766 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
|
767 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
|
768 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
|
769 |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
770 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
|
771 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
|
772 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
|
773 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
|
774 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
|
775 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
|
776 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
|
777 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
|
778 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
|
779 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
780 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
|
781 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
|
782 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
|
783 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
|
784 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
|
785 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
|
786 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
|
787 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
|
788 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
|
789 else: |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
790 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
|
791 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 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
|
800 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
|
801 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
802 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
|
803 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
|
804 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
|
805 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
|
806 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
|
807 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
|
808 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
|
809 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
|
810 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
|
811 else: |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
812 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
|
813 |
|
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
|
814 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
|
815 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
|
816 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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
824 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
|
825 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
|
826 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
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
835 def test_reduce_overrides_default_reduce_ex(self): |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
836 for proto in 0, 1, 2: |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
837 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
|
838 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
|
839 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
|
840 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
|
841 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
|
842 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
|
843 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
844 def test_reduce_ex_called(self): |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
845 for proto in 0, 1, 2: |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
846 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
|
847 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
|
848 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
|
849 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
|
850 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
|
851 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
|
852 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
853 def test_reduce_ex_overrides_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
|
854 for proto in 0, 1, 2: |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
855 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
|
856 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
|
857 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
|
858 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
|
859 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
|
860 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
|
861 |
|
41201
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
862 def test_reduce_ex_calls_base(self): |
|
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
863 for proto in 0, 1, 2: |
|
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
864 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
|
865 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 |
|
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
871 def test_reduce_calls_base(self): |
|
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
872 for proto in 0, 1, 2: |
|
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
873 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
|
874 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
|
875 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
|
876 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
|
877 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
|
878 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
|
879 |
|
49609
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47189
diff
changeset
|
880 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
|
881 # 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
|
882 # 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
|
883 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
|
884 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
|
885 # 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
|
886 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
|
887 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
|
888 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
|
889 # 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
|
890 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
|
891 |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47189
diff
changeset
|
892 # Protocol 0 is less strict and also accept iterables. |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47189
diff
changeset
|
893 for proto in 0, 1, 2: |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47189
diff
changeset
|
894 try: |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47189
diff
changeset
|
895 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
|
896 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
|
897 pass |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47189
diff
changeset
|
898 try: |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47189
diff
changeset
|
899 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
|
900 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
|
901 pass |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47189
diff
changeset
|
902 |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
903 # 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
|
904 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
905 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
|
906 _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
|
907 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
|
908 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
|
909 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
|
910 # 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
|
911 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
912 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
|
913 _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
|
914 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
|
915 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
|
916 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
|
917 # 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
|
918 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
919 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
|
920 _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
|
921 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
|
922 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
|
923 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
|
924 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
|
925 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
|
926 |
|
41201
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
927 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
|
928 _proto = None |
|
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
929 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
|
930 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
|
931 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
|
932 # 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
|
933 |
|
4217f3850f0b
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
Žiga Seilnacht <ziga.seilnacht@gmail.com>
parents:
38055
diff
changeset
|
934 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
|
935 _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
|
936 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
|
937 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
|
938 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
|
939 # 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
|
940 |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
941 # 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
|
942 |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
943 class MyInt(int): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
944 sample = 1 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
945 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
946 class MyLong(long): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
947 sample = 1L |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
948 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
949 class MyFloat(float): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
950 sample = 1.0 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
951 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
952 class MyComplex(complex): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
953 sample = 1.0 + 0.0j |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
954 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
955 class MyStr(str): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
956 sample = "hello" |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
957 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
958 class MyUnicode(unicode): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
959 sample = u"hello \u1234" |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
960 |
|
27482
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
961 class MyTuple(tuple): |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
962 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
|
963 |
|
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
964 class MyList(list): |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
965 sample = [1, 2, 3] |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
966 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
967 class MyDict(dict): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
968 sample = {"a": 1, "b": 2} |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
969 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
970 myclasses = [MyInt, MyLong, MyFloat, |
| 28135 | 971 MyComplex, |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
972 MyStr, MyUnicode, |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
973 MyTuple, MyList, MyDict] |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
974 |
|
27482
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
975 |
|
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
|
976 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
|
977 __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
|
978 |
|
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
|
979 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
|
980 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
|
981 # 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
|
982 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
|
983 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
984 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
|
985 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
986 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
|
987 import os |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
988 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
|
989 try: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
990 f.close() |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
991 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
|
992 finally: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
993 os.remove(TESTFN) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
994 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
995 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
|
996 import os |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
997 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
|
998 try: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
999 f.close() |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1000 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
|
1001 finally: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1002 os.remove(TESTFN) |
|
26202
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1003 |
|
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
|
1004 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
|
1005 # 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
|
1006 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
|
1007 |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
30801
diff
changeset
|
1008 def test_callapi(self): |
|
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
30801
diff
changeset
|
1009 from cStringIO import StringIO |
|
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
30801
diff
changeset
|
1010 f = StringIO() |
|
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
30801
diff
changeset
|
1011 # 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
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 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
|
1018 |
|
55430
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
1019 def test_incomplete_input(self): |
|
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
1020 s = StringIO.StringIO("X''.") |
|
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
1021 self.assertRaises(EOFError, self.module.load, s) |
|
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
1022 |
|
57439
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1023 def test_restricted(self): |
|
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1024 # issue7128: cPickle failed in restricted mode |
|
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1025 builtins = {self.module.__name__: self.module, |
|
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1026 '__import__': __import__} |
|
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1027 d = {} |
|
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1028 teststr = "def f(): {0}.dumps(0)".format(self.module.__name__) |
|
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1029 exec teststr in {'__builtins__': builtins}, d |
|
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1030 d['f']() |
|
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1031 |
|
58188
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1032 def test_bad_input(self): |
|
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1033 # Test issue4298 |
|
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1034 s = '\x58\0\0\0\x54' |
|
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1035 self.assertRaises(EOFError, self.module.loads, s) |
|
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1036 # Test issue7455 |
|
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1037 s = '0' |
|
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1038 # XXX Why doesn't pickle raise UnpicklingError? |
|
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1039 self.assertRaises((IndexError, cPickle.UnpicklingError), |
|
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
1040 self.module.loads, s) |
|
57439
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
1041 |
|
26202
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1042 class AbstractPersistentPicklerTests(unittest.TestCase): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1043 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1044 # 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
|
1045 # 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
|
1046 # are pickled using persistent ids. |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1047 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1048 def persistent_id(self, object): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1049 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
|
1050 self.id_count += 1 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1051 return str(object) |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1052 else: |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1053 return None |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1054 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1055 def persistent_load(self, oid): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1056 self.load_count += 1 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1057 object = int(oid) |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1058 assert object % 2 == 0 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1059 return object |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1060 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1061 def test_persistence(self): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1062 self.id_count = 0 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1063 self.load_count = 0 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1064 L = range(10) |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1065 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
|
1066 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
|
1067 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
|
1068 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1069 def test_bin_persistence(self): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1070 self.id_count = 0 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1071 self.load_count = 0 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1072 L = range(10) |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1073 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
|
1074 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
|
1075 self.assertEqual(self.load_count, 5) |
