Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
61bf2576
Commit
61bf2576
authored
Feb 03, 2003
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do a better job of testing that opcodes aren't generated under protocols
earlier than the ones in which they were introduced.
parent
28d81966
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
18 deletions
+32
-18
Lib/test/pickletester.py
Lib/test/pickletester.py
+32
-18
No files found.
Lib/test/pickletester.py
View file @
61bf2576
...
...
@@ -254,11 +254,12 @@ class AbstractPickleTests(unittest.TestCase):
def
setUp
(
self
):
pass
def
ensure_opcode_in_pickle
(
self
,
code
,
pickle
):
# Return True if opcode code appears in the pickle, else False.
def
opcode_in_pickle
(
self
,
code
,
pickle
):
for
op
,
dummy
,
dummy
in
pickletools
.
genops
(
pickle
):
if
op
.
code
==
code
:
return
self
.
fail
(
"didn't find opcode %r in pickle %r"
%
(
code
,
pickle
))
return
True
return
False
def
test_misc
(
self
):
# test various datatypes not tested by testdata
...
...
@@ -480,17 +481,21 @@ class AbstractPickleTests(unittest.TestCase):
def
test_long1
(
self
):
x
=
12345678910111213141516178920L
s
=
self
.
dumps
(
x
,
2
)
y
=
self
.
loads
(
s
)
self
.
assertEqual
(
x
,
y
)
self
.
ensure_opcode_in_pickle
(
pickle
.
LONG1
,
s
)
for
proto
in
protocols
:
s
=
self
.
dumps
(
x
,
proto
)
y
=
self
.
loads
(
s
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
self
.
opcode_in_pickle
(
pickle
.
LONG1
,
s
),
proto
>=
2
)
def
test_long4
(
self
):
x
=
12345678910111213141516178920L
<<
(
256
*
8
)
s
=
self
.
dumps
(
x
,
2
)
y
=
self
.
loads
(
s
)
self
.
assertEqual
(
x
,
y
)
self
.
ensure_opcode_in_pickle
(
pickle
.
LONG4
,
s
)
for
proto
in
protocols
:
s
=
self
.
dumps
(
x
,
proto
)
y
=
self
.
loads
(
s
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
self
.
opcode_in_pickle
(
pickle
.
LONG4
,
s
),
proto
>=
2
)
def
test_short_tuples
(
self
):
# Map (proto, len(tuple)) to expected opcode.
...
...
@@ -523,20 +528,29 @@ class AbstractPickleTests(unittest.TestCase):
y
=
self
.
loads
(
s
)
self
.
assertEqual
(
x
,
y
,
(
proto
,
x
,
s
,
y
))
expected
=
expected_opcode
[
proto
,
len
(
x
)]
self
.
ensure_opcode_in_pickle
(
expected
,
s
)
self
.
assertEqual
(
self
.
opcode_in_pickle
(
expected
,
s
),
True
)
def
test_singletons
(
self
):
# Map (proto, singleton) to expected opcode.
expected_opcode
=
{(
0
,
None
):
pickle
.
NONE
,
(
1
,
None
):
pickle
.
NONE
,
(
2
,
None
):
pickle
.
NONE
,
(
0
,
True
):
pickle
.
INT
,
(
1
,
True
):
pickle
.
INT
,
(
2
,
True
):
pickle
.
NEWTRUE
,
(
0
,
False
):
pickle
.
INT
,
(
1
,
False
):
pickle
.
INT
,
(
2
,
False
):
pickle
.
NEWFALSE
,
}
for
proto
in
protocols
:
for
x
in
None
,
False
,
True
:
s
=
self
.
dumps
(
x
,
proto
)
y
=
self
.
loads
(
s
)
self
.
assert_
(
x
is
y
,
(
proto
,
x
,
s
,
y
))
# Test that proto >= 2 really uses the bool opcodes.
if
proto
>=
2
and
x
in
(
False
,
True
):
expected
=
x
and
pickle
.
NEWTRUE
or
pickle
.
NEWFALSE
# Skip the PROTO opcode at the start.
self
.
assertEqual
(
s
[
2
],
expected
)
expected
=
expected_opcode
[
proto
,
x
]
self
.
assertEqual
(
self
.
opcode_in_pickle
(
expected
,
s
),
True
)
def
test_newobj_tuple
(
self
):
x
=
MyTuple
([
1
,
2
,
3
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment