Mercurial > cpython-lru_cache-weakref
annotate Lib/test/pickletester.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 5881a58c5425 |
| children | a982feb29584 b66e82c9f852 |
| rev | line source |
|---|---|
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1 import io |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
2 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
|
3 import pickle |
|
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
|
4 import pickletools |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
5 import sys |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
6 import copyreg |
|
54584
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
7 from http.cookies import SimpleCookie |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
8 |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
9 from test.support import ( |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
10 TestFailed, TESTFN, run_with_locale, |
|
72642
bf39434dd506
Start fixing test_bigmem:
Antoine Pitrou <solipsis@pitrou.net>
parents:
72639
diff
changeset
|
11 _2G, _4G, bigmemtest, |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
12 ) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
13 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
14 from pickle import bytes_types |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
15 |
|
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 # 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
|
17 # 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
|
18 # 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
|
19 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
|
20 |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
21 character_size = 4 if sys.maxunicode > 0xFFFF else 2 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
22 |
|
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
|
23 |
|
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 # 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
|
25 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
|
26 for op, dummy, dummy in pickletools.genops(pickle): |
|
41651
44ebae4f61c4
Got test_pickletools and test_pickle working.
Guido van Rossum <guido@python.org>
parents:
41642
diff
changeset
|
27 if op.code == code.decode("latin-1"): |
|
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
|
28 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
|
29 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
|
30 |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
31 # 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
|
32 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
|
33 n = 0 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
34 for op, dummy, dummy in pickletools.genops(pickle): |
|
41651
44ebae4f61c4
Got test_pickletools and test_pickle working.
Guido van Rossum <guido@python.org>
parents:
41642
diff
changeset
|
35 if op.code == code.decode("latin-1"): |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
36 n += 1 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
37 return n |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
38 |
|
65224
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
39 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
40 class UnseekableIO(io.BytesIO): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
41 def peek(self, *args): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
42 raise NotImplementedError |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
43 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
44 def seekable(self): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
45 return False |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
46 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
47 def seek(self, *args): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
48 raise io.UnsupportedOperation |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
49 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
50 def tell(self): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
51 raise io.UnsupportedOperation |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
52 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
53 |
|
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
|
54 # 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
|
55 # 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
|
56 # 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
|
57 # |
|
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 # 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
|
59 # 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
|
60 # 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
|
61 # 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
|
62 # 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
|
63 |
|
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
|
64 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
|
65 # 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
|
66 # 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
|
67 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
|
68 self.code = code |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
69 if code in copyreg._inverted_registry: |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
70 self.pair = copyreg._inverted_registry[code] |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
71 copyreg.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
|
72 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
|
73 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
|
74 |
|
3599f6593fe9
cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents:
27684
diff
changeset
|
75 # 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
|
76 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
|
77 code = self.code |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
78 curpair = copyreg._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
|
79 if curpair is not None: |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
80 copyreg.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
|
81 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
|
82 if pair is not None: |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
83 copyreg.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
|
84 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
85 class C: |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39543
diff
changeset
|
86 def __eq__(self, other): |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39543
diff
changeset
|
87 return self.__dict__ == other.__dict__ |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
88 |
|
63062
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
89 class D(C): |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
90 def __init__(self, arg): |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
91 pass |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
92 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
93 class E(C): |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
94 def __getinitargs__(self): |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
95 return () |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
96 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
97 import __main__ |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
98 __main__.C = C |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
99 C.__module__ = "__main__" |
|
63062
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
100 __main__.D = D |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
101 D.__module__ = "__main__" |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
102 __main__.E = E |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
103 E.__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
|
104 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
105 class myint(int): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
106 def __init__(self, x): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
107 self.str = str(x) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
108 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
109 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
|
110 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
111 def __init__(self, a, b): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
112 self.a = a |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
113 self.b = b |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
114 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
115 def __getinitargs__(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
116 return self.a, self.b |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
117 |
|
21488
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
118 class metaclass(type): |
|
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
119 pass |
|
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
120 |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40809
diff
changeset
|
121 class use_metaclass(object, metaclass=metaclass): |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
40809
diff
changeset
|
122 pass |
|
21488
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
123 |
|
72639
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
124 class pickling_metaclass(type): |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
125 def __eq__(self, other): |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
126 return (type(self) == type(other) and |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
127 self.reduce_args == other.reduce_args) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
128 |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
129 def __reduce__(self): |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
130 return (create_dynamic_class, self.reduce_args) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
131 |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
132 def create_dynamic_class(name, bases): |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
133 result = pickling_metaclass(name, bases, dict()) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
134 result.reduce_args = (name, bases) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
135 return result |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
136 |
|
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
|
137 # 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
|
138 # 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
|
139 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
140 DATA0 = ( |
|
50944
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
141 b'(lp0\nL0L\naL1L\naF2.0\nac' |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
142 b'builtins\ncomplex\n' |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
143 b'p1\n(F3.0\nF0.0\ntp2\nRp' |
|
50944
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
144 b'3\naL1L\naL-1L\naL255L\naL-' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
145 b'255L\naL-256L\naL65535L\na' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
146 b'L-65535L\naL-65536L\naL2' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
147 b'147483647L\naL-2147483' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
148 b'647L\naL-2147483648L\na(' |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
149 b'Vabc\np4\ng4\nccopyreg' |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
150 b'\n_reconstructor\np5\n(' |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
151 b'c__main__\nC\np6\ncbu' |
|
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
152 b'iltins\nobject\np7\nNt' |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
153 b'p8\nRp9\n(dp10\nVfoo\np1' |
|
50944
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
154 b'1\nL1L\nsVbar\np12\nL2L\nsb' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
155 b'g9\ntp13\nag13\naL5L\na.' |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
156 ) |
|
16133
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
157 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
158 # Disassembly of DATA0 |
|
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
|
159 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
|
160 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
|
161 1: l LIST (MARK at 0) |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
162 2: p PUT 0 |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
163 5: L LONG 0 |
|
50944
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
164 9: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
165 10: L LONG 1 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
166 14: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
167 15: F FLOAT 2.0 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
168 20: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
169 21: c GLOBAL 'builtins complex' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
170 39: p PUT 1 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
171 42: ( MARK |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
172 43: F FLOAT 3.0 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
173 48: F FLOAT 0.0 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
174 53: t TUPLE (MARK at 42) |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
175 54: p PUT 2 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
176 57: R REDUCE |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
177 58: p PUT 3 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
178 61: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
179 62: L LONG 1 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
180 66: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
181 67: L LONG -1 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
182 72: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
183 73: L LONG 255 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
184 79: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
185 80: L LONG -255 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
186 87: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
187 88: L LONG -256 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
188 95: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
189 96: L LONG 65535 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
190 104: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
191 105: L LONG -65535 |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
192 114: a APPEND |
|
50944
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
193 115: L LONG -65536 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
194 124: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
195 125: L LONG 2147483647 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
196 138: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
197 139: L LONG -2147483647 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
198 153: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
199 154: L LONG -2147483648 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
200 168: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
201 169: ( MARK |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
202 170: V UNICODE 'abc' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
203 175: p PUT 4 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
204 178: g GET 4 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
205 181: c GLOBAL 'copyreg _reconstructor' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
206 205: p PUT 5 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
207 208: ( MARK |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
208 209: c GLOBAL '__main__ C' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
209 221: p PUT 6 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
210 224: c GLOBAL 'builtins object' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
211 241: p PUT 7 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
212 244: N NONE |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
213 245: t TUPLE (MARK at 208) |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
214 246: p PUT 8 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
215 249: R REDUCE |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
216 250: p PUT 9 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
217 253: ( MARK |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
218 254: d DICT (MARK at 253) |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
219 255: p PUT 10 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
220 259: V UNICODE 'foo' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
221 264: p PUT 11 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
222 268: L LONG 1 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
223 272: s SETITEM |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
224 273: V UNICODE 'bar' |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
225 278: p PUT 12 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
226 282: L LONG 2 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
227 286: s SETITEM |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
228 287: b BUILD |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
229 288: g GET 9 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
230 291: t TUPLE (MARK at 169) |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
231 292: p PUT 13 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
232 296: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
233 297: g GET 13 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
234 301: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
235 302: L LONG 5 |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
236 306: a APPEND |
|
d1de077447aa
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
Mark Dickinson <dickinsm@gmail.com>
parents:
50303
diff
changeset
|
237 307: . STOP |
|
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
|
238 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
|
239 """ |
|
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 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
241 DATA1 = ( |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
242 b']q\x00(K\x00K\x01G@\x00\x00\x00\x00\x00\x00\x00c' |
|
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
243 b'builtins\ncomplex\nq\x01' |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
244 b'(G@\x08\x00\x00\x00\x00\x00\x00G\x00\x00\x00\x00\x00\x00\x00\x00t' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
245 b'q\x02Rq\x03K\x01J\xff\xff\xff\xffK\xffJ\x01\xff\xff\xffJ' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
246 b'\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff\xff' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
247 b'\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00\x80(X\x03\x00\x00\x00ab' |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
248 b'cq\x04h\x04ccopyreg\n_reco' |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
249 b'nstructor\nq\x05(c__main' |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
250 b'__\nC\nq\x06cbuiltins\n' |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
251 b'object\nq\x07Ntq\x08Rq\t}q\n(' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
252 b'X\x03\x00\x00\x00fooq\x0bK\x01X\x03\x00\x00\x00bar' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
253 b'q\x0cK\x02ubh\ttq\rh\rK\x05e.' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
254 ) |
|
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
|
255 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
256 # Disassembly of DATA1 |
|
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
|
257 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
|
258 0: ] EMPTY_LIST |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
259 1: q BINPUT 0 |
|
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
|
260 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
|
261 4: K BININT1 0 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
262 6: K BININT1 1 |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
263 8: G BINFLOAT 2.0 |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
264 17: c GLOBAL 'builtins complex' |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
265 35: q BINPUT 1 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
266 37: ( MARK |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
267 38: G BINFLOAT 3.0 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
268 47: G BINFLOAT 0.0 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
269 56: t TUPLE (MARK at 37) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
270 57: q BINPUT 2 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
271 59: R REDUCE |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
272 60: q BINPUT 3 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
273 62: K BININT1 1 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
274 64: J BININT -1 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
275 69: K BININT1 255 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
276 71: J BININT -255 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
277 76: J BININT -256 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
278 81: M BININT2 65535 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
279 84: J BININT -65535 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
280 89: J BININT -65536 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
281 94: J BININT 2147483647 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
282 99: J BININT -2147483647 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
283 104: J BININT -2147483648 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
284 109: ( MARK |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
285 110: X BINUNICODE 'abc' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
286 118: q BINPUT 4 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
287 120: h BINGET 4 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
288 122: c GLOBAL 'copyreg _reconstructor' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
289 146: q BINPUT 5 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
290 148: ( MARK |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
291 149: c GLOBAL '__main__ C' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
292 161: q BINPUT 6 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
293 163: c GLOBAL 'builtins object' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
294 180: q BINPUT 7 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
295 182: N NONE |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
296 183: t TUPLE (MARK at 148) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
297 184: q BINPUT 8 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
298 186: R REDUCE |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
299 187: q BINPUT 9 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
300 189: } EMPTY_DICT |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
301 190: q BINPUT 10 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
302 192: ( MARK |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
303 193: X BINUNICODE 'foo' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
304 201: q BINPUT 11 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
305 203: K BININT1 1 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
306 205: X BINUNICODE 'bar' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
307 213: q BINPUT 12 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
308 215: K BININT1 2 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
309 217: u SETITEMS (MARK at 192) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
310 218: b BUILD |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
311 219: h BINGET 9 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
312 221: t TUPLE (MARK at 109) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
313 222: q BINPUT 13 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
314 224: h BINGET 13 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
315 226: K BININT1 5 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
316 228: e APPENDS (MARK at 3) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
317 229: . STOP |
|
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
|
318 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
|
319 """ |
|
20547
a12ccdbce8da
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
20444
diff
changeset
|
320 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
321 DATA2 = ( |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
322 b'\x80\x02]q\x00(K\x00K\x01G@\x00\x00\x00\x00\x00\x00\x00c' |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
323 b'builtins\ncomplex\n' |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
324 b'q\x01G@\x08\x00\x00\x00\x00\x00\x00G\x00\x00\x00\x00\x00\x00\x00\x00' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
325 b'\x86q\x02Rq\x03K\x01J\xff\xff\xff\xffK\xffJ\x01\xff\xff\xff' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
326 b'J\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
327 b'\xff\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00\x80(X\x03\x00\x00\x00a' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
328 b'bcq\x04h\x04c__main__\nC\nq\x05' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
329 b')\x81q\x06}q\x07(X\x03\x00\x00\x00fooq\x08K\x01' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
330 b'X\x03\x00\x00\x00barq\tK\x02ubh\x06tq\nh' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
331 b'\nK\x05e.' |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
332 ) |
|
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
|
333 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
334 # Disassembly of DATA2 |
|
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
|
335 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
|
336 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
|
337 2: ] EMPTY_LIST |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
338 3: q BINPUT 0 |
|
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
|
339 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
|
340 6: K BININT1 0 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
341 8: K BININT1 1 |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
342 10: G BINFLOAT 2.0 |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
343 19: c GLOBAL 'builtins complex' |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
344 37: q BINPUT 1 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
345 39: G BINFLOAT 3.0 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
346 48: G BINFLOAT 0.0 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
347 57: \x86 TUPLE2 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
348 58: q BINPUT 2 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
349 60: R REDUCE |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
350 61: q BINPUT 3 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
351 63: K BININT1 1 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
352 65: J BININT -1 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
353 70: K BININT1 255 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
354 72: J BININT -255 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
355 77: J BININT -256 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
356 82: M BININT2 65535 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
357 85: J BININT -65535 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
358 90: J BININT -65536 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
359 95: J BININT 2147483647 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
360 100: J BININT -2147483647 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
361 105: J BININT -2147483648 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
362 110: ( MARK |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
363 111: X BINUNICODE 'abc' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
364 119: q BINPUT 4 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
365 121: h BINGET 4 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
366 123: c GLOBAL '__main__ C' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
367 135: q BINPUT 5 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
368 137: ) EMPTY_TUPLE |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
369 138: \x81 NEWOBJ |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
370 139: q BINPUT 6 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
371 141: } EMPTY_DICT |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
372 142: q BINPUT 7 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
373 144: ( MARK |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
374 145: X BINUNICODE 'foo' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
375 153: q BINPUT 8 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
376 155: K BININT1 1 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
377 157: X BINUNICODE 'bar' |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
378 165: q BINPUT 9 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
379 167: K BININT1 2 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
380 169: u SETITEMS (MARK at 144) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
381 170: b BUILD |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
382 171: h BINGET 6 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
383 173: t TUPLE (MARK at 110) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
384 174: q BINPUT 10 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
385 176: h BINGET 10 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
386 178: K BININT1 5 |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
387 180: e APPENDS (MARK at 5) |
|
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
388 181: . STOP |
|
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
|
389 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
|
390 """ |
|
97b97e57190c
test_load_from_canned_string(): Created a DATA2 string to test a canned
Tim Peters <tim.peters@gmail.com>
parents:
27951
diff
changeset
|
391 |
|
54584
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
392 # set([1,2]) pickled from 2.x with protocol 2 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
393 DATA3 = b'\x80\x02c__builtin__\nset\nq\x00]q\x01(K\x01K\x02e\x85q\x02Rq\x03.' |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
394 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
395 # xrange(5) pickled from 2.x with protocol 2 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
396 DATA4 = b'\x80\x02c__builtin__\nxrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02.' |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
397 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
398 # a SimpleCookie() object pickled from 2.x with protocol 2 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
399 DATA5 = (b'\x80\x02cCookie\nSimpleCookie\nq\x00)\x81q\x01U\x03key' |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
400 b'q\x02cCookie\nMorsel\nq\x03)\x81q\x04(U\x07commentq\x05U' |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
401 b'\x00q\x06U\x06domainq\x07h\x06U\x06secureq\x08h\x06U\x07' |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
402 b'expiresq\th\x06U\x07max-ageq\nh\x06U\x07versionq\x0bh\x06U' |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
403 b'\x04pathq\x0ch\x06U\x08httponlyq\rh\x06u}q\x0e(U\x0b' |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
404 b'coded_valueq\x0fU\x05valueq\x10h\x10h\x10h\x02h\x02ubs}q\x11b.') |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
405 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
406 # set([3]) pickled from 2.x with protocol 2 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
407 DATA6 = b'\x80\x02c__builtin__\nset\nq\x00]q\x01K\x03a\x85q\x02Rq\x03.' |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
408 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
409 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
410 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
|
411 c = C() |
|
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
412 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
|
413 c.bar = 2 |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
414 x = [0, 1, 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
|
415 # 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
|
416 # 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 x.append(5) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
428 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
|
429 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
430 class AbstractPickleTests(unittest.TestCase): |
|
47645
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
431 # Subclass must define self.dumps, self.loads. |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
432 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
433 _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
|
434 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
435 def setUp(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
436 pass |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
437 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
438 def test_misc(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
439 # 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 |
|
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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 |
|
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
|
451 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
|
452 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
|
453 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
|
454 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
|
455 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
456 # XXX test __reduce__ protocol? |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
457 |
|
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
|
458 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
|
459 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
|
460 for proto in protocols: |
|
72228a25daaa
Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents:
27591
diff
changeset
|
461 s = self.dumps(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
|
462 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
|
463 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
|
464 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
465 def test_load_from_data0(self): |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
466 self.assertEqual(self._testdata, self.loads(DATA0)) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
467 |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
468 def test_load_from_data1(self): |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
469 self.assertEqual(self._testdata, self.loads(DATA1)) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
470 |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
471 def test_load_from_data2(self): |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
472 self.assertEqual(self._testdata, self.loads(DATA2)) |
|
17356
28cf0a7943cf
No functional change -- just added whitespace in places so I could follow
Tim Peters <tim.peters@gmail.com>
parents:
16134
diff
changeset
|
473 |
|
63062
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
474 def test_load_classic_instance(self): |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
475 # See issue5180. Test loading 2.x pickles that |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
476 # contain an instance of old style class. |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
477 for X, args in [(C, ()), (D, ('x',)), (E, ())]: |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
478 xname = X.__name__.encode('ascii') |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
479 # Protocol 0 (text mode pickle): |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
480 """ |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
481 0: ( MARK |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
482 1: i INST '__main__ X' (MARK at 0) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
483 15: p PUT 0 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
484 18: ( MARK |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
485 19: d DICT (MARK at 18) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
486 20: p PUT 1 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
487 23: b BUILD |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
488 24: . STOP |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
489 """ |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
490 pickle0 = (b"(i__main__\n" |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
491 b"X\n" |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
492 b"p0\n" |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
493 b"(dp1\nb.").replace(b'X', xname) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
494 self.assertEqual(X(*args), self.loads(pickle0)) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
495 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
496 # Protocol 1 (binary mode pickle) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
497 """ |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
498 0: ( MARK |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
499 1: c GLOBAL '__main__ X' |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
500 15: q BINPUT 0 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
501 17: o OBJ (MARK at 0) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
502 18: q BINPUT 1 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
503 20: } EMPTY_DICT |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
504 21: q BINPUT 2 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
505 23: b BUILD |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
506 24: . STOP |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
507 """ |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
508 pickle1 = (b'(c__main__\n' |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
509 b'X\n' |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
510 b'q\x00oq\x01}q\x02b.').replace(b'X', xname) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
511 self.assertEqual(X(*args), self.loads(pickle1)) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
512 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
513 # Protocol 2 (pickle2 = b'\x80\x02' + pickle1) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
514 """ |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
515 0: \x80 PROTO 2 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
516 2: ( MARK |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
517 3: c GLOBAL '__main__ X' |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
518 17: q BINPUT 0 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
519 19: o OBJ (MARK at 2) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
520 20: q BINPUT 1 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
521 22: } EMPTY_DICT |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
522 23: q BINPUT 2 |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
523 25: b BUILD |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
524 26: . STOP |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
525 """ |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
526 pickle2 = (b'\x80\x02(c__main__\n' |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
527 b'X\n' |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
528 b'q\x00oq\x01}q\x02b.').replace(b'X', xname) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
529 self.assertEqual(X(*args), self.loads(pickle2)) |
|
abf69d402883
Merged revisions 82937 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
60578
diff
changeset
|
530 |
|
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
|
531 # 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
|
532 # 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
|
533 # 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
|
534 # 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
|
535 # 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
|
536 # 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
|
537 def dont_test_disassembly(self): |
|
42501
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
42322
diff
changeset
|
538 from io import StringIO |
|
27596
72228a25daaa
Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents:
27591
diff
changeset
|
539 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
|
540 |
|
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
|
541 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
|
542 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
|
543 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
|
544 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
|
545 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
|
546 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
|
547 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
548 def test_recursive_list(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
549 l = [] |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
550 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
|
551 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
|
552 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
|
553 x = self.loads(s) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
554 self.assertEqual(len(x), 1) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
555 self.assertTrue(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
|
556 |
|
54355
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
557 def test_recursive_tuple(self): |
|
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
558 t = ([],) |
|
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
559 t[0].append(t) |
|
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
560 for proto in protocols: |
|
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
561 s = self.dumps(t, proto) |
|
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
562 x = self.loads(s) |
|
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
563 self.assertEqual(len(x), 1) |
|
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
564 self.assertEqual(len(x[0]), 1) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
565 self.assertTrue(x is x[0][0]) |
|
54355
9012ff7d75a2
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
53694
diff
changeset
|
566 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
567 def test_recursive_dict(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
568 d = {} |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
569 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
|
570 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
|
571 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
|
572 x = self.loads(s) |
|
40809
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40644
diff
changeset
|
573 self.assertEqual(list(x.keys()), [1]) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
574 self.assertTrue(x[1] is x) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
575 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
576 def test_recursive_inst(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
577 i = C() |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 x = self.loads(s) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
582 self.assertEqual(dir(x), dir(i)) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
583 self.assertTrue(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
|
584 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
585 def test_recursive_multi(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
586 l = [] |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
587 d = {1:l} |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
588 i = C() |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
589 i.attr = d |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
590 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
|
591 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
|
592 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
|
593 x = self.loads(s) |
|
30801
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
594 self.assertEqual(len(x), 1) |
|
c42c40034536
Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents:
28135
diff
changeset
|
595 self.assertEqual(dir(x[0]), dir(i)) |
|
40809
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40644
diff
changeset
|
596 self.assertEqual(list(x[0].attr.keys()), [1]) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
597 self.assertTrue(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
|
598 |
|
47645
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
599 def test_get(self): |
|
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
600 self.assertRaises(KeyError, self.loads, b'g0\np0') |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63062
diff
changeset
|
601 self.assertEqual(self.loads(b'((Kdtp0\nh\x00l.))'), [(100,), (100,)]) |
|
16133
d48018b33e35
Reorganize pickle/cPickle testing so the tests pass regardless of the order
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
602 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
603 def test_insecure_strings(self): |
|
42902
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
604 # XXX Some of these tests are temporarily disabled |
|
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
605 insecure = [b"abc", b"2 + 2", # not quoted |
|
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
606 ## b"'abc' + 'def'", # not a single quoted string |
|
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
607 b"'abc", # quote is not closed |
|
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
608 b"'abc\"", # open quote and close quote don't match |
|
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
609 b"'abc' ?", # junk after close quote |
|
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
610 b"'\\'", # trailing backslash |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
611 # some tests of the quoting rules |
|
42902
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
612 ## b"'abc\"\''", |
|
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
613 ## b"'\\\\a\'\'\'\\\'\\\\\''", |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
614 ] |
|
42902
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
615 for b in insecure: |
|
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
616 buf = b"S" + b + b"\012p0\012." |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
617 self.assertRaises(ValueError, self.loads, buf) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
618 |
|
41993
0d81a656412a
Rename checks for test_support.have_unicode (we always
Walter Dörwald <walter@livinglogic.de>
parents:
41651
diff
changeset
|
619 def test_unicode(self): |
| 50303 | 620 endcases = ['', '<\\u>', '<\\\u1234>', '<\n>', |
|
60578
b8f297cdfade
Merged revisions 80031 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58187
diff
changeset
|
621 '<\\>', '<\\\U00012345>', |
|
b8f297cdfade
Merged revisions 80031 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58187
diff
changeset
|
622 # surrogates |
|
b8f297cdfade
Merged revisions 80031 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58187
diff
changeset
|
623 '<\udc80>'] |
|
41993
0d81a656412a
Rename checks for test_support.have_unicode (we always
Walter Dörwald <walter@livinglogic.de>
parents:
41651
diff
changeset
|
624 for proto in protocols: |
|
0d81a656412a
Rename checks for test_support.have_unicode (we always
Walter Dörwald <walter@livinglogic.de>
parents:
41651
diff
changeset
|
625 for u in endcases: |
|
0d81a656412a
Rename checks for test_support.have_unicode (we always
Walter Dörwald <walter@livinglogic.de>
parents:
41651
diff
changeset
|
626 p = self.dumps(u, proto) |
|
0d81a656412a
Rename checks for test_support.have_unicode (we always
Walter Dörwald <walter@livinglogic.de>
parents:
41651
diff
changeset
|
627 u2 = self.loads(p) |
|
0d81a656412a
Rename checks for test_support.have_unicode (we always
Walter Dörwald <walter@livinglogic.de>
parents:
41651
diff
changeset
|
628 self.assertEqual(u2, u) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
629 |
|
50291
303ad45a967f
Update copy of PyUnicode_EncodeRawUnicodeEscape in _pickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49705
diff
changeset
|
630 def test_unicode_high_plane(self): |
|
303ad45a967f
Update copy of PyUnicode_EncodeRawUnicodeEscape in _pickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49705
diff
changeset
|
631 t = '\U00012345' |
|
303ad45a967f
Update copy of PyUnicode_EncodeRawUnicodeEscape in _pickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49705
diff
changeset
|
632 for proto in protocols: |
|
303ad45a967f
Update copy of PyUnicode_EncodeRawUnicodeEscape in _pickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49705
diff
changeset
|
633 p = self.dumps(t, proto) |
|
303ad45a967f
Update copy of PyUnicode_EncodeRawUnicodeEscape in _pickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49705
diff
changeset
|
634 t2 = self.loads(p) |
|
303ad45a967f
Update copy of PyUnicode_EncodeRawUnicodeEscape in _pickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49705
diff
changeset
|
635 self.assertEqual(t2, t) |
|
303ad45a967f
Update copy of PyUnicode_EncodeRawUnicodeEscape in _pickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49705
diff
changeset
|
636 |
|
45812
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
637 def test_bytes(self): |
|
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
638 for proto in protocols: |
|
73957
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
639 for s in b'', b'xyz', b'xyz'*100: |
|
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
640 p = self.dumps(s) |
|
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
641 self.assertEqual(self.loads(p), s) |
|
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
642 for s in [bytes([i]) for i in range(256)]: |
|
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
643 p = self.dumps(s) |
|
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
644 self.assertEqual(self.loads(p), s) |
|
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
645 for s in [bytes([i, i]) for i in range(256)]: |
|
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
646 p = self.dumps(s) |
|
14695b4825dc
Issue #13505: Make pickling of bytes object compatible with Python 2.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
72642
diff
changeset
|
647 self.assertEqual(self.loads(p), s) |
|
45812
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
648 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
649 def test_ints(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
650 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
|
651 for proto in protocols: |
|
44160
9d152530910a
Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
652 n = sys.maxsize |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27573
diff
changeset
|
653 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
|
654 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
|
655 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
|
656 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
|
657 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
|
658 n = n >> 1 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
659 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
660 def test_maxint64(self): |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
661 maxint64 = (1 << 63) - 1 |
|
42902
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
662 data = b'I' + str(maxint64).encode("ascii") + b'\n.' |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
663 got = self.loads(data) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
664 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
|
665 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
666 # Try too with a bogus literal. |
|
42902
62874b34d95d
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42501
diff
changeset
|
667 data = b'I' + str(maxint64).encode("ascii") + b'JUNK\n.' |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
668 self.assertRaises(ValueError, self.loads, data) |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
669 |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27573
diff
changeset
|
670 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
|
671 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
|
672 # 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
|
673 for nbits in 1, 8, 8*254, 8*255, 8*256, 8*257: |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
674 nbase = 1 << nbits |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27573
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 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
|
679 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
|
680 # 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
|
681 # bother with those. |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
682 nbase = int("deadbeeffeedface", 16) |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27573
diff
changeset
|
683 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
|
684 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
|
685 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
|
686 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
|
687 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
|
688 |
|
51021
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
689 def test_float(self): |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
690 test_values = [0.0, 4.94e-324, 1e-310, 7e-308, 6.626e-34, 0.1, 0.5, |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
691 3.14, 263.44582062374053, 6.022e23, 1e30] |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
692 test_values = test_values + [-x for x in test_values] |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
693 for proto in protocols: |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
694 for value in test_values: |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
695 pickle = self.dumps(value, proto) |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
696 got = self.loads(pickle) |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
697 self.assertEqual(value, got) |
|
9a45e2cad6a1
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50944
diff
changeset
|
698 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
32829
diff
changeset
|
699 @run_with_locale('LC_ALL', 'de_DE', 'fr_FR') |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
32829
diff
changeset
|
700 def test_float_format(self): |
|
45812
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
701 # make sure that floats are formatted locale independent with proto 0 |
|
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
702 self.assertEqual(self.dumps(1.2, 0)[0:3], b'F1.') |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
32829
diff
changeset
|
703 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
704 def test_reduce(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
705 pass |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
706 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
707 def test_getinitargs(self): |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
708 pass |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
709 |
|
77811
5881a58c5425
Issue #15079: make a test applicable to both C and Python versions of the pickle module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73957
diff
changeset
|
710 def test_pop_empty_stack(self): |
|
5881a58c5425
Issue #15079: make a test applicable to both C and Python versions of the pickle module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73957
diff
changeset
|
711 # Test issue7455 |
|
5881a58c5425
Issue #15079: make a test applicable to both C and Python versions of the pickle module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73957
diff
changeset
|
712 s = b'0' |
|
5881a58c5425
Issue #15079: make a test applicable to both C and Python versions of the pickle module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73957
diff
changeset
|
713 self.assertRaises((pickle.UnpicklingError, IndexError), self.loads, s) |
|
5881a58c5425
Issue #15079: make a test applicable to both C and Python versions of the pickle module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73957
diff
changeset
|
714 |
|
21488
bb168de50a03
Add test for pickling new-style class with custom metaclass.
Guido van Rossum <guido@python.org>
parents:
21481
diff
changeset
|
715 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
|
716 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
|
717 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
|
718 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
|
719 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
|
720 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
|
721 |
|
72639
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
722 def test_dynamic_class(self): |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
723 a = create_dynamic_class("my_dynamic_class", (object,)) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
724 copyreg.pickle(pickling_metaclass, pickling_metaclass.__reduce__) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
725 for proto in protocols: |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
726 s = self.dumps(a, proto) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
727 b = self.loads(s) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
728 self.assertEqual(a, b) |
|
760ac320fa3d
Issue #7689: Allow pickling of dynamically created classes when their
Antoine Pitrou <solipsis@pitrou.net>
parents:
72143
diff
changeset
|
729 |
|
22138
ed2a17a376d0
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21488
diff
changeset
|
730 def test_structseq(self): |
|
ed2a17a376d0
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21488
diff
changeset
|
731 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
|
732 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
|
733 |
|
22138
ed2a17a376d0
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21488
diff
changeset
|
734 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
|
735 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
|
736 s = self.dumps(t, proto) |
|
22165
22c66587c452
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22138
diff
changeset
|
737 u = self.loads(s) |
|
22c66587c452
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22138
diff
changeset
|
738 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
|
739 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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 self.assertEqual(t, u) |
|
22138
ed2a17a376d0
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21488
diff
changeset
|
749 |
|
27456
115ee40518a8
First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents:
26202
diff
changeset
|
750 # 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
|
751 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
752 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
|
753 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
|
754 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
|
755 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
|
756 if proto >= 2: |
|
41651
44ebae4f61c4
Got test_pickletools and test_pickle working.
Guido van Rossum <guido@python.org>
parents:
41642
diff
changeset
|
757 expected = pickle.PROTO + bytes([proto]) + expected |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
758 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
|
759 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
|
760 |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
761 oob = protocols[-1] + 1 # a future protocol |
|
41651
44ebae4f61c4
Got test_pickletools and test_pickle working.
Guido van Rossum <guido@python.org>
parents:
41642
diff
changeset
|
762 badpickle = pickle.PROTO + bytes([oob]) + build_none |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
763 try: |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
764 self.loads(badpickle) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
765 except ValueError as detail: |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
766 self.assertTrue(str(detail).startswith( |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
767 "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
|
768 else: |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
769 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
|
770 |
|
27456
115ee40518a8
First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents:
26202
diff
changeset
|
771 def test_long1(self): |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
772 x = 12345678910111213141516178920 |
|
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
|
773 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
|
774 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
|
775 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
|
776 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
|
777 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
|
778 |
|
115ee40518a8
First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.
Guido van Rossum <guido@python.org>
parents:
26202
diff
changeset
|
779 def test_long4(self): |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
780 x = 12345678910111213141516178920 << (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
|
781 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
|
782 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
|
783 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
|
784 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
|
785 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
|
786 |
|
27459
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
787 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
|
788 # 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
|
789 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
|
790 (0, 1): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
791 (0, 2): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
792 (0, 3): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
793 (0, 4): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
794 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
795 (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
|
796 (1, 1): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
797 (1, 2): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
798 (1, 3): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
799 (1, 4): pickle.TUPLE, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
800 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
801 (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
|
802 (2, 1): pickle.TUPLE1, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
803 (2, 2): pickle.TUPLE2, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
804 (2, 3): pickle.TUPLE3, |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
805 (2, 4): pickle.TUPLE, |
|
45812
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
806 |
|
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
807 (3, 0): pickle.EMPTY_TUPLE, |
|
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
808 (3, 1): pickle.TUPLE1, |
|
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
809 (3, 2): pickle.TUPLE2, |
|
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
810 (3, 3): pickle.TUPLE3, |
|
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
811 (3, 4): pickle.TUPLE, |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
812 } |
|
27459
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
813 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
|
814 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
|
815 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
|
816 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
|
817 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
|
818 for proto in protocols: |
|
27459
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
819 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
|
820 s = self.dumps(x, proto) |
|
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
821 y = self.loads(s) |
|
ea480406cc65
More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Guido van Rossum <guido@python.org>
parents:
27456
diff
changeset
|
822 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
|
823 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
|
824 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
|
825 |
|
27461
883af28b9a0d
OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents:
27460
diff
changeset
|
826 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
|
827 # 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
|
828 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
|
829 (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
|
830 (2, None): pickle.NONE, |
|
45812
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
831 (3, None): pickle.NONE, |
|
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
|
832 |
|
e11e976fee78
Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents:
27645
diff
changeset
|
833 (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
|
834 (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
|
835 (2, True): pickle.NEWTRUE, |
|
45812
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
836 (3, True): pickle.NEWTRUE, |
|
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
|
837 |
|
e11e976fee78
Do a better job of testing that opcodes aren't generated under protocols
Tim Peters <tim.peters@gmail.com>
parents:
27645
diff
changeset
|
838 (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
|
839 (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
|
840 (2, False): pickle.NEWFALSE, |
|
45812
322693bf10ca
- A new pickle protocol (protocol 3) is added with explicit support
Guido van Rossum <guido@python.org>
parents:
44160
diff
changeset
|
841 (3, False): pickle.NEWFALSE, |
|
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
|
842 } |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27587
diff
changeset
|
843 for proto in protocols: |
|
27461
883af28b9a0d
OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents:
27460
diff
changeset
|
844 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
|
845 s = self.dumps(x, proto) |
|
883af28b9a0d
OK, this is really the last one tonight!
Guido van Rossum <guido@python.org>
parents:
27460
diff
changeset
|
846 y = self.loads(s) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
847 self.assertTrue(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
|
848 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
|
849 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
|
850 |
|
27482
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
851 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
|
852 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
|
853 x.foo = 42 |
|
e9578747f43d
The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents:
27482
diff
changeset
|
854 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
|
855 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
|
856 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
|
857 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
|
858 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
|
859 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
|
860 |
|
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
861 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
|
862 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
|
863 x.foo = 42 |
|
e9578747f43d
The default __reduce__ on the base object type obscured any
Guido van Rossum <guido@python.org>
parents:
27482
diff
changeset
|
864 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
|
865 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
871 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
|
872 for proto in protocols: |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
873 for C in myclasses: |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
874 B = C.__base__ |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
875 x = C(C.sample) |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
876 x.foo = 42 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
877 s = self.dumps(x, proto) |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
878 y = self.loads(s) |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
879 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
|
880 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
|
881 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
|
882 |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
883 # Register a type with copyreg, 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
|
884 # 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
|
885 # (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
|
886 |
|
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
|
887 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
|
888 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
|
889 try: |
|
46867
dd5513b472dc
Rename copy_reg module to copyreg.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45812
diff
changeset
|
890 copyreg.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
|
891 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
|
892 x.foo = 42 |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
893 x.bar = "hello" |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
894 |
|
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
|
895 # 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
|
896 s1 = self.dumps(x, 1) |
|
58456
f0f221e1a7c0
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58186
diff
changeset
|
897 self.assertIn(__name__.encode("utf-8"), s1) |
|
f0f221e1a7c0
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58186
diff
changeset
|
898 self.assertIn(b"MyList", s1) |
|
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
|
899 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
|
900 |
|
27510
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
901 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
|
902 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
|
903 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
|
904 |
|
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
|
905 # 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
|
906 s2 = self.dumps(x, 2) |
|
58456
f0f221e1a7c0
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58186
diff
changeset
|
907 self.assertNotIn(__name__.encode("utf-8"), s2) |
|
f0f221e1a7c0
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58186
diff
changeset
|
908 self.assertNotIn(b"MyList", s2) |
|
41651
44ebae4f61c4
Got test_pickletools and test_pickle working.
Guido van Rossum <guido@python.org>
parents:
41642
diff
changeset
|
909 self.assertEqual(opcode_in_pickle(opcode, s2), True, repr(s2)) |
|
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
|
910 |
|
27510
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
911 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
|
912 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
|
913 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
|
914 |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
915 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
|
916 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
|
917 |
|
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
|
918 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
|
919 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
|
920 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
|
921 |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
922 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
|
923 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
|
924 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
|
925 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
|
926 |
|
20c581c23bce
Test all three EXT opcodes, and move these tests into
Guido van Rossum <guido@python.org>
parents:
27500
diff
changeset
|
927 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
|
928 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
|
929 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
|
930 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
|
931 |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
932 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
|
933 n = 10 # too small to chunk |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
934 x = list(range(n)) |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
935 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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 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
|
941 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
942 n = 2500 # expect at least two chunks when proto > 0 |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
943 x = list(range(n)) |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
944 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
|
945 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
|
946 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
|
947 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
|
948 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
|
949 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
|
950 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
|
951 else: |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
952 self.assertTrue(num_appends >= 2) |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
953 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
954 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
|
955 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
|
956 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
|
957 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
|
958 s = self.dumps(x, proto) |
|
58473
71acd4482e65
Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58456
diff
changeset
|
959 self.assertIsInstance(s, bytes_types) |
|
27813
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
960 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
|
961 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
|
962 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
|
963 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
|
964 |
|
f6c95f9138ad
Added tests to ensure that list and dict "chunking" are actually
Tim Peters <tim.peters@gmail.com>
parents:
27686
diff
changeset
|
965 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
|
966 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
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 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
|
973 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
|
974 else: |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54584
diff
changeset
|
975 self.assertTrue(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
|
976 |
|
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
|
977 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
|
978 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
|
979 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
|
980 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
|
981 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
|
982 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
|
983 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
|
984 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
|
985 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
|
986 |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
987 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
|
988 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
|
989 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
|
990 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
|
991 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
|
992 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
|
993 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
|
994 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
|
995 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
|
996 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
|
997 |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
998 def test_reduce_overrides_default_reduce_ex(self): |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
999 for proto in protocols: |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1000 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
|
1001 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
|
1002 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
|
1003 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
|
1004 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
|
1005 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
|
1006 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1007 def test_reduce_ex_called(self): |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1008 for proto in protocols: |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1009 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
|
1010 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
|
1011 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
|
1012 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
|
1013 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
|
1014 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
|
1015 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1016 def test_reduce_ex_overrides_reduce(self): |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1017 for proto in protocols: |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1018 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
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1025 def test_reduce_ex_calls_base(self): |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1026 for proto in protocols: |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1027 x = REX_four() |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1028 self.assertEqual(x._proto, None) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1029 s = self.dumps(x, proto) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1030 self.assertEqual(x._proto, proto) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1031 y = self.loads(s) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1032 self.assertEqual(y._proto, proto) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1033 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1034 def test_reduce_calls_base(self): |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1035 for proto in protocols: |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1036 x = REX_five() |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1037 self.assertEqual(x._reduce_called, 0) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1038 s = self.dumps(x, proto) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1039 self.assertEqual(x._reduce_called, 1) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1040 y = self.loads(s) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1041 self.assertEqual(y._reduce_called, 1) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1042 |
|
48696
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1043 def test_bad_getattr(self): |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1044 x = BadGetattr() |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1045 for proto in 0, 1: |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1046 self.assertRaises(RuntimeError, self.dumps, x, proto) |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1047 # protocol 2 don't raise a RuntimeError. |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1048 d = self.dumps(x, 2) |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1049 self.assertRaises(RuntimeError, self.loads, d) |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1050 |
|
49615
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1051 def test_reduce_bad_iterator(self): |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1052 # Issue4176: crash when 4th and 5th items of __reduce__() |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1053 # are not iterators |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1054 class C(object): |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1055 def __reduce__(self): |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1056 # 4th item is not an iterator |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1057 return list, (), None, [], None |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1058 class D(object): |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1059 def __reduce__(self): |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1060 # 5th item is not an iterator |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1061 return dict, (), None, None, [] |
|
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1062 |
|
49625
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1063 # Protocol 0 is less strict and also accept iterables. |
|
49615
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1064 for proto in protocols: |
|
49625
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1065 try: |
|
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1066 self.dumps(C(), proto) |
|
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1067 except (pickle.PickleError): |
|
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1068 pass |
|
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1069 try: |
|
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1070 self.dumps(D(), proto) |
|
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1071 except (pickle.PickleError): |
|
9906f696b941
Correct the pickle test, broken since r67059:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49615
diff
changeset
|
1072 pass |
|
49615
a5ca8951bef1
Merged revisions 67049 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49546
diff
changeset
|
1073 |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1074 def test_many_puts_and_gets(self): |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1075 # Test that internal data structures correctly deal with lots of |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1076 # puts/gets. |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1077 keys = ("aaa" + str(i) for i in range(100)) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1078 large_dict = dict((k, [4, 5, 6]) for k in keys) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1079 obj = [dict(large_dict), dict(large_dict), dict(large_dict)] |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1080 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1081 for proto in protocols: |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1082 dumped = self.dumps(obj, proto) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1083 loaded = self.loads(dumped) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1084 self.assertEqual(loaded, obj, |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1085 "Failed protocol %d: %r != %r" |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1086 % (proto, obj, loaded)) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1087 |
|
53694
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1088 def test_attribute_name_interning(self): |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1089 # Test that attribute names of pickled objects are interned when |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1090 # unpickling. |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1091 for proto in protocols: |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1092 x = C() |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1093 x.foo = 42 |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1094 x.bar = "hello" |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1095 s = self.dumps(x, proto) |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1096 y = self.loads(s) |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1097 x_keys = sorted(x.__dict__) |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1098 y_keys = sorted(y.__dict__) |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1099 for x_key, y_key in zip(x_keys, y_keys): |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1100 self.assertIs(x_key, y_key) |
|
64d9a9e7f68e
Merged revisions 72223 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53169
diff
changeset
|
1101 |
|
54584
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1102 def test_unpickle_from_2x(self): |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1103 # Unpickle non-trivial data from Python 2.x. |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1104 loaded = self.loads(DATA3) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1105 self.assertEqual(loaded, set([1, 2])) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1106 loaded = self.loads(DATA4) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1107 self.assertEqual(type(loaded), type(range(0))) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1108 self.assertEqual(list(loaded), list(range(5))) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1109 loaded = self.loads(DATA5) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1110 self.assertEqual(type(loaded), SimpleCookie) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1111 self.assertEqual(list(loaded.keys()), ["key"]) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1112 self.assertEqual(loaded["key"].value, "Set-Cookie: key=value") |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1113 |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1114 def test_pickle_to_2x(self): |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1115 # Pickle non-trivial data with protocol 2, expecting that it yields |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1116 # the same result as Python 2.x did. |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1117 # NOTE: this test is a bit too strong since we can produce different |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1118 # bytecode that 2.x will still understand. |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1119 dumped = self.dumps(range(5), 2) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1120 self.assertEqual(dumped, DATA4) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1121 dumped = self.dumps(set([3]), 2) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1122 self.assertEqual(dumped, DATA6) |
|
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1123 |
|
64588
027f81579b4a
Issue #9410: Various optimizations to the pickle module, leading to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63061
diff
changeset
|
1124 def test_large_pickles(self): |
|
027f81579b4a
Issue #9410: Various optimizations to the pickle module, leading to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63061
diff
changeset
|
1125 # Test the correctness of internal buffering routines when handling |
|
027f81579b4a
Issue #9410: Various optimizations to the pickle module, leading to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63061
diff
changeset
|
1126 # large data. |
|
027f81579b4a
Issue #9410: Various optimizations to the pickle module, leading to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63061
diff
changeset
|
1127 for proto in protocols: |
|
65224
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1128 data = (1, min, b'xy' * (30 * 1024), len) |
|
64588
027f81579b4a
Issue #9410: Various optimizations to the pickle module, leading to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63061
diff
changeset
|
1129 dumped = self.dumps(data, proto) |
|
027f81579b4a
Issue #9410: Various optimizations to the pickle module, leading to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63061
diff
changeset
|
1130 loaded = self.loads(dumped) |
|
65224
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1131 self.assertEqual(len(loaded), len(data)) |
|
64588
027f81579b4a
Issue #9410: Various optimizations to the pickle module, leading to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63061
diff
changeset
|
1132 self.assertEqual(loaded, data) |
|
027f81579b4a
Issue #9410: Various optimizations to the pickle module, leading to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63061
diff
changeset
|
1133 |
|
68003
cc3c3a438398
Merged revisions 88546 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66310
diff
changeset
|
1134 def test_empty_bytestring(self): |
|
cc3c3a438398
Merged revisions 88546 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66310
diff
changeset
|
1135 # issue 11286 |
|
cc3c3a438398
Merged revisions 88546 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66310
diff
changeset
|
1136 empty = self.loads(b'\x80\x03U\x00q\x00.', encoding='koi8-r') |
|
cc3c3a438398
Merged revisions 88546 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66310
diff
changeset
|
1137 self.assertEqual(empty, '') |
|
54584
0805ea211122
Issue #6137: The pickle module now translates module names when loading
Antoine Pitrou <solipsis@pitrou.net>
parents:
54355
diff
changeset
|
1138 |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1139 def check_negative_32b_binXXX(self, dumped): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1140 if sys.maxsize > 2**32: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1141 self.skipTest("test is only meaningful on 32-bit builds") |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1142 # XXX Pure Python pickle reads lengths as signed and passes |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1143 # them directly to read() (hence the EOFError) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1144 with self.assertRaises((pickle.UnpicklingError, EOFError, |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1145 ValueError, OverflowError)): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1146 self.loads(dumped) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1147 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1148 def test_negative_32b_binbytes(self): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1149 # On 32-bit builds, a BINBYTES of 2**31 or more is refused |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1150 self.check_negative_32b_binXXX(b'\x80\x03B\xff\xff\xff\xffxyzq\x00.') |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1151 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1152 def test_negative_32b_binunicode(self): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1153 # On 32-bit builds, a BINUNICODE of 2**31 or more is refused |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1154 self.check_negative_32b_binXXX(b'\x80\x03X\xff\xff\xff\xffxyzq\x00.') |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1155 |
|
72121
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1156 def test_negative_put(self): |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1157 # Issue #12847 |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1158 dumped = b'Va\np-1\n.' |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1159 self.assertRaises(ValueError, self.loads, dumped) |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1160 |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1161 def test_negative_32b_binput(self): |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1162 # Issue #12847 |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1163 if sys.maxsize > 2**32: |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1164 self.skipTest("test is only meaningful on 32-bit builds") |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1165 dumped = b'\x80\x03X\x01\x00\x00\x00ar\xff\xff\xff\xff.' |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1166 self.assertRaises(ValueError, self.loads, dumped) |
|
0d9e4ce1c010
Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
Antoine Pitrou <solipsis@pitrou.net>
parents:
72119
diff
changeset
|
1167 |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1168 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1169 class BigmemPickleTests(unittest.TestCase): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1170 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1171 # Binary protocols can serialize longs of up to 2GB-1 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1172 |
|
72642
bf39434dd506
Start fixing test_bigmem:
Antoine Pitrou <solipsis@pitrou.net>
parents:
72639
diff
changeset
|
1173 @bigmemtest(size=_2G, memuse=1 + 1, dry_run=False) |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1174 def test_huge_long_32b(self, size): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1175 data = 1 << (8 * size) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1176 try: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1177 for proto in protocols: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1178 if proto < 2: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1179 continue |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1180 with self.assertRaises((ValueError, OverflowError)): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1181 self.dumps(data, protocol=proto) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1182 finally: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1183 data = None |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1184 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1185 # Protocol 3 can serialize up to 4GB-1 as a bytes object |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1186 # (older protocols don't have a dedicated opcode for bytes and are |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1187 # too inefficient) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1188 |
|
72642
bf39434dd506
Start fixing test_bigmem:
Antoine Pitrou <solipsis@pitrou.net>
parents:
72639
diff
changeset
|
1189 @bigmemtest(size=_2G, memuse=1 + 1, dry_run=False) |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1190 def test_huge_bytes_32b(self, size): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1191 data = b"abcd" * (size // 4) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1192 try: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1193 for proto in protocols: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1194 if proto < 3: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1195 continue |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1196 try: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1197 pickled = self.dumps(data, protocol=proto) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1198 self.assertTrue(b"abcd" in pickled[:15]) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1199 self.assertTrue(b"abcd" in pickled[-15:]) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1200 finally: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1201 pickled = None |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1202 finally: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1203 data = None |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1204 |
|
72642
bf39434dd506
Start fixing test_bigmem:
Antoine Pitrou <solipsis@pitrou.net>
parents:
72639
diff
changeset
|
1205 @bigmemtest(size=_4G, memuse=1 + 1, dry_run=False) |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1206 def test_huge_bytes_64b(self, size): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1207 data = b"a" * size |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1208 try: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1209 for proto in protocols: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1210 if proto < 3: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1211 continue |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1212 with self.assertRaises((ValueError, OverflowError)): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1213 self.dumps(data, protocol=proto) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1214 finally: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1215 data = None |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1216 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1217 # All protocols use 1-byte per printable ASCII character; we add another |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1218 # byte because the encoded form has to be copied into the internal buffer. |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1219 |
|
72642
bf39434dd506
Start fixing test_bigmem:
Antoine Pitrou <solipsis@pitrou.net>
parents:
72639
diff
changeset
|
1220 @bigmemtest(size=_2G, memuse=2 + character_size, dry_run=False) |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1221 def test_huge_str_32b(self, size): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1222 data = "abcd" * (size // 4) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1223 try: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1224 for proto in protocols: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1225 try: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1226 pickled = self.dumps(data, protocol=proto) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1227 self.assertTrue(b"abcd" in pickled[:15]) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1228 self.assertTrue(b"abcd" in pickled[-15:]) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1229 finally: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1230 pickled = None |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1231 finally: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1232 data = None |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1233 |
|
72143
942729c61684
Try to fix one of the bigmem tests in test_pickle
Antoine Pitrou <solipsis@pitrou.net>
parents:
72121
diff
changeset
|
1234 # BINUNICODE (protocols 1, 2 and 3) cannot carry more than |
|
942729c61684
Try to fix one of the bigmem tests in test_pickle
Antoine Pitrou <solipsis@pitrou.net>
parents:
72121
diff
changeset
|
1235 # 2**32 - 1 bytes of utf-8 encoded unicode. |
|
942729c61684
Try to fix one of the bigmem tests in test_pickle
Antoine Pitrou <solipsis@pitrou.net>
parents:
72121
diff
changeset
|
1236 |
|
72642
bf39434dd506
Start fixing test_bigmem:
Antoine Pitrou <solipsis@pitrou.net>
parents:
72639
diff
changeset
|
1237 @bigmemtest(size=_4G, memuse=1 + character_size, dry_run=False) |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1238 def test_huge_str_64b(self, size): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1239 data = "a" * size |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1240 try: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1241 for proto in protocols: |
|
72143
942729c61684
Try to fix one of the bigmem tests in test_pickle
Antoine Pitrou <solipsis@pitrou.net>
parents:
72121
diff
changeset
|
1242 if proto == 0: |
|
942729c61684
Try to fix one of the bigmem tests in test_pickle
Antoine Pitrou <solipsis@pitrou.net>
parents:
72121
diff
changeset
|
1243 continue |
|
72119
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1244 with self.assertRaises((ValueError, OverflowError)): |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1245 self.dumps(data, protocol=proto) |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1246 finally: |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1247 data = None |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1248 |
|
babc90f3cbf4
Issue #11564: Avoid crashes when trying to pickle huge objects or containers
Antoine Pitrou <solipsis@pitrou.net>
parents:
71817
diff
changeset
|
1249 |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1250 # 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
|
1251 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1252 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
|
1253 _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
|
1254 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
|
1255 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
|
1256 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
|
1257 # 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
|
1258 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1259 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
|
1260 _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
|
1261 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
|
1262 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
|
1263 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
|
1264 # 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
|
1265 |
|
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1266 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
|
1267 _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
|
1268 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
|
1269 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
|
1270 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
|
1271 def __reduce__(self): |
|
43014
9834301a2fd3
Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents:
42902
diff
changeset
|
1272 raise TestFailed("This __reduce__ shouldn't be called") |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1273 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1274 class REX_four(object): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1275 _proto = None |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1276 def __reduce_ex__(self, proto): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1277 self._proto = proto |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1278 return object.__reduce_ex__(self, proto) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1279 # Calling base class method should succeed |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1280 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1281 class REX_five(object): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1282 _reduce_called = 0 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1283 def __reduce__(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1284 self._reduce_called = 1 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1285 return object.__reduce__(self) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1286 # This one used to fail with infinite recursion |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1287 |
|
27951
b540e608bb8a
Three test cases for __reduce_ex__. This fails for cPickle, until Tim
Guido van Rossum <guido@python.org>
parents:
27901
diff
changeset
|
1288 # 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
|
1289 |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1290 class MyInt(int): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1291 sample = 1 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1292 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1293 class MyFloat(float): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1294 sample = 1.0 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1295 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1296 class MyComplex(complex): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1297 sample = 1.0 + 0.0j |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1298 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1299 class MyStr(str): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1300 sample = "hello" |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1301 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1302 class MyUnicode(str): |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
1303 sample = "hello \u1234" |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1304 |
|
27482
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
1305 class MyTuple(tuple): |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1306 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
|
1307 |
|
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
1308 class MyList(list): |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1309 sample = [1, 2, 3] |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1310 |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1311 class MyDict(dict): |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1312 sample = {"a": 1, "b": 2} |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1313 |
|
57582
1c92fbb3baf2
Issue #7435: Remove duplicate int/long tests, and other
Mark Dickinson <dickinsm@gmail.com>
parents:
55593
diff
changeset
|
1314 myclasses = [MyInt, MyFloat, |
| 28135 | 1315 MyComplex, |
|
27521
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1316 MyStr, MyUnicode, |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1317 MyTuple, MyList, MyDict] |
|
17bfd5dbc0f1
Implement appropriate __getnewargs__ for all immutable subclassable builtin
Guido van Rossum <guido@python.org>
parents:
27510
diff
changeset
|
1318 |
|
27482
7c8dfd3f4ae9
Some experimental support for generating NEWOBJ with proto=2, and
Guido van Rossum <guido@python.org>
parents:
27461
diff
changeset
|
1319 |
|
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
|
1320 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
|
1321 __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
|
1322 |
|
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
|
1323 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
|
1324 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
|
1325 # 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
|
1326 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
|
1327 |
|
48696
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1328 class BadGetattr: |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1329 def __getattr__(self, key): |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1330 self.foo |
|
e961cc014619
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47645
diff
changeset
|
1331 |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1332 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
1333 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
|
1334 |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
1335 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
|
1336 import os |
|
42121
1f06d5ee40bd
Open files in binary mode.
Walter Dörwald <walter@livinglogic.de>
parents:
41993
diff
changeset
|
1337 f = open(TESTFN, "wb") |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1338 try: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1339 f.close() |
|
47645
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1340 self.assertRaises(ValueError, pickle.dump, 123, f) |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1341 finally: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1342 os.remove(TESTFN) |
|
20444
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
1343 |
|
bc905a11c148
Covert pickle tests to use unittest.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19544
diff
changeset
|
1344 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
|
1345 import os |
|
42121
1f06d5ee40bd
Open files in binary mode.
Walter Dörwald <walter@livinglogic.de>
parents:
41993
diff
changeset
|
1346 f = open(TESTFN, "wb") |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1347 try: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1348 f.close() |
|
47645
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1349 self.assertRaises(ValueError, pickle.dump, 123, f) |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1350 finally: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24442
diff
changeset
|
1351 os.remove(TESTFN) |
|
26202
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1352 |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1353 def test_load_from_and_dump_to_file(self): |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1354 stream = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1355 data = [123, {}, 124] |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1356 pickle.dump(data, stream) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1357 stream.seek(0) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1358 unpickled = pickle.load(stream) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1359 self.assertEqual(unpickled, data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1360 |
|
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
|
1361 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
|
1362 # Of course this needs to be changed when HIGHEST_PROTOCOL changes. |
|
47645
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1363 self.assertEqual(pickle.HIGHEST_PROTOCOL, 3) |
|
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
|
1364 |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
30801
diff
changeset
|
1365 def test_callapi(self): |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1366 f = io.BytesIO() |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
30801
diff
changeset
|
1367 # With and without keyword arguments |
|
47645
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1368 pickle.dump(123, f, -1) |
|
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1369 pickle.dump(123, file=f, protocol=-1) |
|
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1370 pickle.dumps(123, -1) |
|
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1371 pickle.dumps(123, protocol=-1) |
|
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1372 pickle.Pickler(f, -1) |
|
0ae50aa7d97c
Restore _pickle module accelerator module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47634
diff
changeset
|
1373 pickle.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
|
1374 |
|
49546
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1375 def test_bad_init(self): |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1376 # Test issue3664 (pickle can segfault from a badly initialized Pickler). |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1377 # Override initialization without calling __init__() of the superclass. |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1378 class BadPickler(pickle.Pickler): |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1379 def __init__(self): pass |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1380 |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1381 class BadUnpickler(pickle.Unpickler): |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1382 def __init__(self): pass |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1383 |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1384 self.assertRaises(pickle.PicklingError, BadPickler().dump, 0) |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1385 self.assertRaises(pickle.UnpicklingError, BadUnpickler().load) |
|
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1386 |
|
49705
218a98981183
#4298: pickle.load() can segfault on invalid or truncated input.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49625
diff
changeset
|
1387 def test_bad_input(self): |
|
218a98981183
#4298: pickle.load() can segfault on invalid or truncated input.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49625
diff
changeset
|
1388 # Test issue4298 |
|
218a98981183
#4298: pickle.load() can segfault on invalid or truncated input.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49625
diff
changeset
|
1389 s = bytes([0x58, 0, 0, 0, 0x54]) |
|
218a98981183
#4298: pickle.load() can segfault on invalid or truncated input.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49625
diff
changeset
|
1390 self.assertRaises(EOFError, pickle.loads, s) |
|
218a98981183
#4298: pickle.load() can segfault on invalid or truncated input.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49625
diff
changeset
|
1391 |
|
49546
bc1f43252c92
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48696
diff
changeset
|
1392 |
|
26202
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1393 class AbstractPersistentPicklerTests(unittest.TestCase): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1394 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1395 # 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
|
1396 # 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
|
1397 # are pickled using persistent ids. |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1398 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1399 def persistent_id(self, object): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1400 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
|
1401 self.id_count += 1 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1402 return str(object) |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1403 else: |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1404 return None |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1405 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1406 def persistent_load(self, oid): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1407 self.load_count += 1 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1408 object = int(oid) |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1409 assert object % 2 == 0 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1410 return object |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1411 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1412 def test_persistence(self): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1413 self.id_count = 0 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1414 self.load_count = 0 |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
1415 L = list(range(10)) |
|
26202
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1416 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
|
1417 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
|
1418 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
|
1419 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1420 def test_bin_persistence(self): |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1421 self.id_count = 0 |
|
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1422 self.load_count = 0 |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
1423 L = list(range(10)) |
|
26202
1cd8106bcd20
Add some simple tests of the persistence hooks.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24809
diff
changeset
|
1424 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
|
1425 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
|
1426 self.assertEqual(self.load_count, 5) |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1427 |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1428 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1429 class AbstractPicklerUnpicklerObjectTests(unittest.TestCase): |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1430 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1431 pickler_class = None |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1432 unpickler_class = None |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1433 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1434 def setUp(self): |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1435 assert self.pickler_class |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1436 assert self.unpickler_class |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1437 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1438 def test_clear_pickler_memo(self): |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1439 # To test whether clear_memo() has any effect, we pickle an object, |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1440 # then pickle it again without clearing the memo; the two serialized |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1441 # forms should be different. If we clear_memo() and then pickle the |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1442 # object again, the third serialized form should be identical to the |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1443 # first one we obtained. |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1444 data = ["abcdefg", "abcdefg", 44] |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1445 f = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1446 pickler = self.pickler_class(f) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1447 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1448 pickler.dump(data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1449 first_pickled = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1450 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1451 # Reset StringIO object. |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1452 f.seek(0) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1453 f.truncate() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1454 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1455 pickler.dump(data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1456 second_pickled = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1457 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1458 # Reset the Pickler and StringIO objects. |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1459 pickler.clear_memo() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1460 f.seek(0) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1461 f.truncate() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1462 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1463 pickler.dump(data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1464 third_pickled = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1465 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1466 self.assertNotEqual(first_pickled, second_pickled) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1467 self.assertEqual(first_pickled, third_pickled) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1468 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1469 def test_priming_pickler_memo(self): |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1470 # Verify that we can set the Pickler's memo attribute. |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1471 data = ["abcdefg", "abcdefg", 44] |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1472 f = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1473 pickler = self.pickler_class(f) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1474 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1475 pickler.dump(data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1476 first_pickled = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1477 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1478 f = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1479 primed = self.pickler_class(f) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1480 primed.memo = pickler.memo |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1481 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1482 primed.dump(data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1483 primed_pickled = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1484 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1485 self.assertNotEqual(first_pickled, primed_pickled) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1486 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1487 def test_priming_unpickler_memo(self): |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1488 # Verify that we can set the Unpickler's memo attribute. |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1489 data = ["abcdefg", "abcdefg", 44] |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1490 f = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1491 pickler = self.pickler_class(f) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1492 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1493 pickler.dump(data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1494 first_pickled = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1495 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1496 f = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1497 primed = self.pickler_class(f) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1498 primed.memo = pickler.memo |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1499 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1500 primed.dump(data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1501 primed_pickled = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1502 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1503 unpickler = self.unpickler_class(io.BytesIO(first_pickled)) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1504 unpickled_data1 = unpickler.load() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1505 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1506 self.assertEqual(unpickled_data1, data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1507 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1508 primed = self.unpickler_class(io.BytesIO(primed_pickled)) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1509 primed.memo = unpickler.memo |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1510 unpickled_data2 = primed.load() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1511 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1512 primed.memo.clear() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1513 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1514 self.assertEqual(unpickled_data2, data) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1515 self.assertTrue(unpickled_data2 is unpickled_data1) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1516 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1517 def test_reusing_unpickler_objects(self): |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1518 data1 = ["abcdefg", "abcdefg", 44] |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1519 f = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1520 pickler = self.pickler_class(f) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1521 pickler.dump(data1) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1522 pickled1 = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1523 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1524 data2 = ["abcdefg", 44, 44] |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1525 f = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1526 pickler = self.pickler_class(f) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1527 pickler.dump(data2) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1528 pickled2 = f.getvalue() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1529 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1530 f = io.BytesIO() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1531 f.write(pickled1) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1532 f.seek(0) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1533 unpickler = self.unpickler_class(f) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1534 self.assertEqual(unpickler.load(), data1) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1535 |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1536 f.seek(0) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1537 f.truncate() |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1538 f.write(pickled2) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1539 f.seek(0) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1540 self.assertEqual(unpickler.load(), data2) |
|
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1541 |
|
65224
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1542 def _check_multiple_unpicklings(self, ioclass): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1543 for proto in protocols: |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1544 data1 = [(x, str(x)) for x in range(2000)] + [b"abcde", len] |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1545 f = ioclass() |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1546 pickler = self.pickler_class(f, protocol=proto) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1547 pickler.dump(data1) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1548 pickled = f.getvalue() |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1549 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1550 N = 5 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1551 f = ioclass(pickled * N) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1552 unpickler = self.unpickler_class(f) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1553 for i in range(N): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1554 if f.seekable(): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1555 pos = f.tell() |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1556 self.assertEqual(unpickler.load(), data1) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1557 if f.seekable(): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1558 self.assertEqual(f.tell(), pos + len(pickled)) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1559 self.assertRaises(EOFError, unpickler.load) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1560 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1561 def test_multiple_unpicklings_seekable(self): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1562 self._check_multiple_unpicklings(io.BytesIO) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1563 |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1564 def test_multiple_unpicklings_unseekable(self): |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1565 self._check_multiple_unpicklings(UnseekableIO) |
|
4613e1449000
Issue #3873: Speed up unpickling from file objects which have a peek()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64588
diff
changeset
|
1566 |
|
71817
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1567 def test_unpickling_buffering_readline(self): |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1568 # Issue #12687: the unpickler's buffering logic could fail with |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1569 # text mode opcodes. |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1570 data = list(range(10)) |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1571 for proto in protocols: |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1572 for buf_size in range(1, 11): |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1573 f = io.BufferedRandom(io.BytesIO(), buffer_size=buf_size) |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1574 pickler = self.pickler_class(f, protocol=proto) |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1575 pickler.dump(data) |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1576 f.seek(0) |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1577 unpickler = self.unpickler_class(f) |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1578 self.assertEqual(unpickler.load(), data) |
|
c47bc1349e61
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
1579 |
|
53169
43ef74bfc569
Port r71408 to py3k: issue 5665, add more pickling tests.
Collin Winter <collinw@gmail.com>
parents:
51021
diff
changeset
|
1580 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1581 if __name__ == "__main__": |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1582 # Print some stuff that can be used to rewrite DATA{0,1,2} |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1583 from pickletools import dis |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1584 x = create_data() |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1585 for i in range(3): |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1586 p = pickle.dumps(x, i) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1587 print("DATA{0} = (".format(i)) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1588 for j in range(0, len(p), 20): |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1589 b = bytes(p[j:j+20]) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1590 print(" {0!r}".format(b)) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1591 print(")") |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1592 print() |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1593 print("# Disassembly of DATA{0}".format(i)) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1594 print("DATA{0}_DIS = \"\"\"\\".format(i)) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1595 dis(p) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1596 print("\"\"\"") |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43014
diff
changeset
|
1597 print() |
