Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc27375

Browse files
committed
test_load_from_canned_string(): Created a DATA2 string to test a canned
proto 2 pickle too.
1 parent 563389f commit fc27375

1 file changed

Lines changed: 66 additions & 2 deletions

File tree

Lib/test/pickletester.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class use_metaclass(object):
8888

8989
# DATA0 .. DATA2 are the pickles we expect under the various protocols, for
9090
# the object returned by create_data().
91-
# XXX DATA2 doesn't exist yet, as it's not fully implemented in cPickle.
9291

9392
# break into multiple strings to avoid confusing font-lock-mode
9493
DATA0 = """(lp1
@@ -276,6 +275,71 @@ class use_metaclass(object):
276275
highest protocol among opcodes = 1
277276
"""
278277

278+
DATA2 = ('\x80\x02]q\x01(K\x00\x8a\x01\x01G@\x00\x00\x00\x00\x00\x00\x00'
279+
'c__builtin__\ncomplex\nq\x02G@\x08\x00\x00\x00\x00\x00\x00G\x00'
280+
'\x00\x00\x00\x00\x00\x00\x00\x86Rq\x03K\x01J\xff\xff\xff\xffK'
281+
'\xffJ\x01\xff\xff\xffJ\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xff'
282+
'J\x00\x00\xff\xffJ\xff\xff\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00'
283+
'\x80(U\x03abcq\x04h\x04(c__main__\nC\nq\x05oq\x06}q\x07(U\x03foo'
284+
'q\x08K\x01U\x03barq\tK\x02ubh\x06tq\nh\nK\x05e.')
285+
286+
# Disassembly of DATA2.
287+
DATA2_DIS = """\
288+
0: \x80 PROTO 2
289+
2: ] EMPTY_LIST
290+
3: q BINPUT 1
291+
5: ( MARK
292+
6: K BININT1 0
293+
8: \x8a LONG1 1L
294+
11: G BINFLOAT 2.0
295+
20: c GLOBAL '__builtin__ complex'
296+
41: q BINPUT 2
297+
43: G BINFLOAT 3.0
298+
52: G BINFLOAT 0.0
299+
61: \x86 TUPLE2
300+
62: R REDUCE
301+
63: q BINPUT 3
302+
65: K BININT1 1
303+
67: J BININT -1
304+
72: K BININT1 255
305+
74: J BININT -255
306+
79: J BININT -256
307+
84: M BININT2 65535
308+
87: J BININT -65535
309+
92: J BININT -65536
310+
97: J BININT 2147483647
311+
102: J BININT -2147483647
312+
107: J BININT -2147483648
313+
112: ( MARK
314+
113: U SHORT_BINSTRING 'abc'
315+
118: q BINPUT 4
316+
120: h BINGET 4
317+
122: ( MARK
318+
123: c GLOBAL '__main__ C'
319+
135: q BINPUT 5
320+
137: o OBJ (MARK at 122)
321+
138: q BINPUT 6
322+
140: } EMPTY_DICT
323+
141: q BINPUT 7
324+
143: ( MARK
325+
144: U SHORT_BINSTRING 'foo'
326+
149: q BINPUT 8
327+
151: K BININT1 1
328+
153: U SHORT_BINSTRING 'bar'
329+
158: q BINPUT 9
330+
160: K BININT1 2
331+
162: u SETITEMS (MARK at 143)
332+
163: b BUILD
333+
164: h BINGET 6
334+
166: t TUPLE (MARK at 112)
335+
167: q BINPUT 10
336+
169: h BINGET 10
337+
171: K BININT1 5
338+
173: e APPENDS (MARK at 5)
339+
174: . STOP
340+
highest protocol among opcodes = 2
341+
"""
342+
279343
def create_data():
280344
c = C()
281345
c.foo = 1
@@ -333,7 +397,7 @@ def test_roundtrip_equality(self):
333397

334398
def test_load_from_canned_string(self):
335399
expected = self._testdata
336-
for canned in DATA0, DATA1:
400+
for canned in DATA0, DATA1, DATA2:
337401
got = self.loads(canned)
338402
self.assertEqual(expected, got)
339403

0 commit comments

Comments
 (0)