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
655720e2
Commit
655720e2
authored
Dec 15, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #22777: Test pickling with all protocols.
parent
c3741a06
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
253 additions
and
228 deletions
+253
-228
Lib/ctypes/test/test_pickling.py
Lib/ctypes/test/test_pickling.py
+9
-11
Lib/test/audiotests.py
Lib/test/audiotests.py
+3
-2
Lib/test/test_bool.py
Lib/test/test_bool.py
+23
-25
Lib/test/test_cfgparser.py
Lib/test/test_cfgparser.py
+77
-67
Lib/test/test_datetime.py
Lib/test/test_datetime.py
+6
-5
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+11
-9
Lib/test/test_deque.py
Lib/test/test_deque.py
+12
-10
Lib/test/test_descr.py
Lib/test/test_descr.py
+48
-43
Lib/test/test_functools.py
Lib/test/test_functools.py
+3
-2
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+2
-1
Lib/test/test_memoryio.py
Lib/test/test_memoryio.py
+2
-1
Lib/test/test_minidom.py
Lib/test/test_minidom.py
+38
-37
Lib/test/test_random.py
Lib/test/test_random.py
+8
-6
Lib/test/test_set.py
Lib/test/test_set.py
+6
-5
Lib/test/test_sets.py
Lib/test/test_sets.py
+5
-4
No files found.
Lib/ctypes/test/test_pickling.py
View file @
655720e2
...
...
@@ -14,9 +14,9 @@ class X(Structure):
class
Y
(
X
):
_fields_
=
[(
"str"
,
c_char_p
)]
class
PickleTest
(
unittest
.
TestCase
)
:
class
PickleTest
:
def
dumps
(
self
,
item
):
return
pickle
.
dumps
(
item
)
return
pickle
.
dumps
(
item
,
self
.
proto
)
def
loads
(
self
,
item
):
return
pickle
.
loads
(
item
)
...
...
@@ -67,17 +67,15 @@ class PickleTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
lambda
:
self
.
dumps
(
item
))
def
test_wchar
(
self
):
pickle
.
dumps
(
c_char
(
"x"
))
self
.
dumps
(
c_char
(
b
"x"
))
# Issue 5049
pickle
.
dumps
(
c_wchar
(
u"x"
))
self
.
dumps
(
c_wchar
(
u"x"
))
class
PickleTest_1
(
PickleTest
):
def
dumps
(
self
,
item
):
return
pickle
.
dumps
(
item
,
1
)
class
PickleTest_2
(
PickleTest
):
def
dumps
(
self
,
item
):
return
pickle
.
dumps
(
item
,
2
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
name
=
'PickleTest_%s'
%
proto
globals
()[
name
]
=
type
(
name
,
(
PickleTest
,
unittest
.
TestCase
),
{
'proto'
:
proto
})
if
__name__
==
"__main__"
:
unittest
.
main
()
Lib/test/audiotests.py
View file @
655720e2
...
...
@@ -61,8 +61,9 @@ class AudioTests:
self
.
assertEqual
(
params
,
(
nchannels
,
sampwidth
,
framerate
,
nframes
,
comptype
,
compname
))
dump
=
pickle
.
dumps
(
params
)
self
.
assertEqual
(
pickle
.
loads
(
dump
),
params
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
dump
=
pickle
.
dumps
(
params
,
proto
)
self
.
assertEqual
(
pickle
.
loads
(
dump
),
params
)
class
AudioWriteTests
(
AudioTests
):
...
...
Lib/test/test_bool.py
View file @
655720e2
...
...
@@ -305,42 +305,40 @@ class BoolTest(unittest.TestCase):
def
test_pickle
(
self
):
import
pickle
self
.
assertIs
(
pickle
.
loads
(
pickle
.
dumps
(
True
)),
True
)
self
.
assertIs
(
pickle
.
loads
(
pickle
.
dumps
(
False
)),
False
)
self
.
assertIs
(
pickle
.
loads
(
pickle
.
dumps
(
True
,
True
)),
True
)
self
.
assertIs
(
pickle
.
loads
(
pickle
.
dumps
(
False
,
True
)),
False
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
self
.
assertIs
(
pickle
.
loads
(
pickle
.
dumps
(
True
,
proto
)),
True
)
self
.
assertIs
(
pickle
.
loads
(
pickle
.
dumps
(
False
,
proto
)),
False
)
def
test_cpickle
(
self
):
import
cPickle
self
.
assertIs
(
cPickle
.
loads
(
cPickle
.
dumps
(
True
)),
True
)
self
.
assertIs
(
cPickle
.
loads
(
cPickle
.
dumps
(
False
)),
False
)
self
.
assertIs
(
cPickle
.
loads
(
cPickle
.
dumps
(
True
,
True
)),
True
)
self
.
assertIs
(
cPickle
.
loads
(
cPickle
.
dumps
(
False
,
True
)),
False
)
for
proto
in
range
(
cPickle
.
HIGHEST_PROTOCOL
+
1
):
self
.
assertIs
(
cPickle
.
loads
(
cPickle
.
dumps
(
True
,
proto
)),
True
)
self
.
assertIs
(
cPickle
.
loads
(
cPickle
.
dumps
(
False
,
proto
)),
False
)
def
test_mixedpickle
(
self
):
import
pickle
,
cPickle
self
.
assertIs
(
pickle
.
loads
(
cPickle
.
dumps
(
True
)),
True
)
self
.
assertIs
(
pickle
.
loads
(
cPickle
.
dumps
(
False
)),
False
)
self
.
assertIs
(
pickle
.
loads
(
cPickle
.
dumps
(
True
,
True
)),
True
)
self
.
assertIs
(
pickle
.
loads
(
cPickle
.
dumps
(
False
,
True
)),
False
)
self
.
assertIs
(
cPickle
.
loads
(
pickle
.
dumps
(
True
)),
True
)
self
.
assertIs
(
cPickle
.
loads
(
pickle
.
dumps
(
False
)),
False
)
self
.
assertIs
(
cPickle
.
loads
(
pickle
.
dumps
(
True
,
True
)),
True
)
self
.
assertIs
(
cPickle
.
loads
(
pickle
.
dumps
(
False
,
True
)),
False
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
self
.
assertIs
(
pickle
.
loads
(
cPickle
.
dumps
(
True
,
proto
)),
True
)
self
.
assertIs
(
pickle
.
loads
(
cPickle
.
dumps
(
False
,
proto
)),
False
)
self
.
assertIs
(
cPickle
.
loads
(
pickle
.
dumps
(
True
,
proto
)),
True
)
self
.
assertIs
(
cPickle
.
loads
(
pickle
.
dumps
(
False
,
proto
)),
False
)
def
test_picklevalues
(
self
):
import
pickle
,
cPickle
# Test for specific backwards-compatible pickle values
self
.
assertEqual
(
pickle
.
dumps
(
True
),
"I01
\
n
."
)
self
.
assertEqual
(
pickle
.
dumps
(
False
),
"I00
\
n
."
)
self
.
assertEqual
(
cPickle
.
dumps
(
True
),
"I01
\
n
."
)
self
.
assertEqual
(
cPickle
.
dumps
(
False
),
"I00
\
n
."
)
self
.
assertEqual
(
pickle
.
dumps
(
True
,
True
),
"I01
\
n
."
)
self
.
assertEqual
(
pickle
.
dumps
(
False
,
True
),
"I00
\
n
."
)
self
.
assertEqual
(
cPickle
.
dumps
(
True
,
True
),
"I01
\
n
."
)
self
.
assertEqual
(
cPickle
.
dumps
(
False
,
True
),
"I00
\
n
."
)
self
.
assertEqual
(
pickle
.
dumps
(
True
,
protocol
=
0
),
"I01
\
n
."
)
self
.
assertEqual
(
pickle
.
dumps
(
False
,
protocol
=
0
),
"I00
\
n
."
)
self
.
assertEqual
(
cPickle
.
dumps
(
True
,
protocol
=
0
),
"I01
\
n
."
)
self
.
assertEqual
(
cPickle
.
dumps
(
False
,
protocol
=
0
),
"I00
\
n
."
)
self
.
assertEqual
(
pickle
.
dumps
(
True
,
protocol
=
1
),
"I01
\
n
."
)
self
.
assertEqual
(
pickle
.
dumps
(
False
,
protocol
=
1
),
"I00
\
n
."
)
self
.
assertEqual
(
cPickle
.
dumps
(
True
,
protocol
=
1
),
"I01
\
n
."
)
self
.
assertEqual
(
cPickle
.
dumps
(
False
,
protocol
=
1
),
"I00
\
n
."
)
self
.
assertEqual
(
pickle
.
dumps
(
True
,
protocol
=
2
),
b'
\
x80
\
x02
\
x88
.'
)
self
.
assertEqual
(
pickle
.
dumps
(
False
,
protocol
=
2
),
b'
\
x80
\
x02
\
x89
.'
)
self
.
assertEqual
(
cPickle
.
dumps
(
True
,
protocol
=
2
),
b'
\
x80
\
x02
\
x88
.'
)
self
.
assertEqual
(
cPickle
.
dumps
(
False
,
protocol
=
2
),
b'
\
x80
\
x02
\
x89
.'
)
def
test_convert_to_bool
(
self
):
# Verify that TypeError occurs when bad things are returned
...
...
Lib/test/test_cfgparser.py
View file @
655720e2
...
...
@@ -614,88 +614,96 @@ class ExceptionPicklingTestCase(unittest.TestCase):
def
test_error
(
self
):
import
pickle
e1
=
ConfigParser
.
Error
(
'value'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_nosectionerror
(
self
):
import
pickle
e1
=
ConfigParser
.
NoSectionError
(
'section'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_nooptionerror
(
self
):
import
pickle
e1
=
ConfigParser
.
NoOptionError
(
'option'
,
'section'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_duplicatesectionerror
(
self
):
import
pickle
e1
=
ConfigParser
.
DuplicateSectionError
(
'section'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_interpolationerror
(
self
):
import
pickle
e1
=
ConfigParser
.
InterpolationError
(
'option'
,
'section'
,
'msg'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_interpolationmissingoptionerror
(
self
):
import
pickle
e1
=
ConfigParser
.
InterpolationMissingOptionError
(
'option'
,
'section'
,
'rawval'
,
'reference'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
e1
.
reference
,
e2
.
reference
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
e1
.
reference
,
e2
.
reference
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_interpolationsyntaxerror
(
self
):
import
pickle
e1
=
ConfigParser
.
InterpolationSyntaxError
(
'option'
,
'section'
,
'msg'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_interpolationdeptherror
(
self
):
import
pickle
e1
=
ConfigParser
.
InterpolationDepthError
(
'option'
,
'section'
,
'rawval'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
section
,
e2
.
section
)
self
.
assertEqual
(
e1
.
option
,
e2
.
option
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_parsingerror
(
self
):
import
pickle
...
...
@@ -703,25 +711,27 @@ class ExceptionPicklingTestCase(unittest.TestCase):
e1
.
append
(
1
,
'line1'
)
e1
.
append
(
2
,
'line2'
)
e1
.
append
(
3
,
'line3'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
filename
,
e2
.
filename
)
self
.
assertEqual
(
e1
.
errors
,
e2
.
errors
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
filename
,
e2
.
filename
)
self
.
assertEqual
(
e1
.
errors
,
e2
.
errors
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_missingsectionheadererror
(
self
):
import
pickle
e1
=
ConfigParser
.
MissingSectionHeaderError
(
'filename'
,
123
,
'line'
)
pickled
=
pickle
.
dumps
(
e1
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
line
,
e2
.
line
)
self
.
assertEqual
(
e1
.
filename
,
e2
.
filename
)
self
.
assertEqual
(
e1
.
lineno
,
e2
.
lineno
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
pickled
=
pickle
.
dumps
(
e1
,
proto
)
e2
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
e1
.
message
,
e2
.
message
)
self
.
assertEqual
(
e1
.
args
,
e2
.
args
)
self
.
assertEqual
(
e1
.
line
,
e2
.
line
)
self
.
assertEqual
(
e1
.
filename
,
e2
.
filename
)
self
.
assertEqual
(
e1
.
lineno
,
e2
.
lineno
)
self
.
assertEqual
(
repr
(
e1
),
repr
(
e2
))
def
test_main
():
...
...
Lib/test/test_datetime.py
View file @
655720e2
...
...
@@ -1421,11 +1421,12 @@ class TestDateTime(TestDate):
def
test_more_pickling
(
self
):
a
=
self
.
theclass
(
2003
,
2
,
7
,
16
,
48
,
37
,
444116
)
s
=
pickle
.
dumps
(
a
)
b
=
pickle
.
loads
(
s
)
self
.
assertEqual
(
b
.
year
,
2003
)
self
.
assertEqual
(
b
.
month
,
2
)
self
.
assertEqual
(
b
.
day
,
7
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
s
=
pickle
.
dumps
(
a
,
proto
)
b
=
pickle
.
loads
(
s
)
self
.
assertEqual
(
b
.
year
,
2003
)
self
.
assertEqual
(
b
.
month
,
2
)
self
.
assertEqual
(
b
.
day
,
7
)
def
test_pickling_subclass_datetime
(
self
):
args
=
6
,
7
,
23
,
20
,
59
,
1
,
64
**
2
...
...
Lib/test/test_decimal.py
View file @
655720e2
...
...
@@ -1664,9 +1664,10 @@ class DecimalPythonAPItests(unittest.TestCase):
def
test_pickle
(
self
):
d
=
Decimal
(
'-3.141590000'
)
p
=
pickle
.
dumps
(
d
)
e
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
d
,
e
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
p
=
pickle
.
dumps
(
d
,
proto
)
e
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
d
,
e
)
def
test_int
(
self
):
for
x
in
range
(
-
250
,
250
):
...
...
@@ -1750,12 +1751,13 @@ class DecimalPythonAPItests(unittest.TestCase):
class
ContextAPItests
(
unittest
.
TestCase
):
def
test_pickle
(
self
):
c
=
Context
()
e
=
pickle
.
loads
(
pickle
.
dumps
(
c
))
for
k
in
vars
(
c
):
v1
=
vars
(
c
)[
k
]
v2
=
vars
(
e
)[
k
]
self
.
assertEqual
(
v1
,
v2
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
c
=
Context
()
e
=
pickle
.
loads
(
pickle
.
dumps
(
c
,
proto
))
for
k
in
vars
(
c
):
v1
=
vars
(
c
)[
k
]
v2
=
vars
(
e
)[
k
]
self
.
assertEqual
(
v1
,
v2
)
def
test_equality_with_other_types
(
self
):
self
.
assertIn
(
Decimal
(
10
),
[
'a'
,
1.0
,
Decimal
(
10
),
(
1
,
2
),
{}])
...
...
Lib/test/test_deque.py
View file @
655720e2
...
...
@@ -600,11 +600,12 @@ class TestSubclass(unittest.TestCase):
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
s
=
pickle
.
dumps
(
d
)
e
=
pickle
.
loads
(
s
)
self
.
assertNotEqual
(
id
(
d
),
id
(
e
))
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
s
=
pickle
.
dumps
(
d
,
proto
)
e
=
pickle
.
loads
(
s
)
self
.
assertNotEqual
(
id
(
d
),
id
(
e
))
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
d
=
Deque
(
'abcde'
,
maxlen
=
4
)
...
...
@@ -616,11 +617,12 @@ class TestSubclass(unittest.TestCase):
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
s
=
pickle
.
dumps
(
d
)
e
=
pickle
.
loads
(
s
)
self
.
assertNotEqual
(
id
(
d
),
id
(
e
))
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
s
=
pickle
.
dumps
(
d
,
proto
)
e
=
pickle
.
loads
(
s
)
self
.
assertNotEqual
(
id
(
d
),
id
(
e
))
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
## def test_pickle(self):
## d = Deque('abc')
...
...
Lib/test/test_descr.py
View file @
655720e2
...
...
@@ -3300,7 +3300,7 @@ order (MRO) for bases """
pass
for
p
in
pickle
,
cPickle
:
for
bin
in
0
,
1
:
for
bin
in
range
(
p
.
HIGHEST_PROTOCOL
+
1
)
:
for
cls
in
C
,
C1
,
C2
:
s
=
p
.
dumps
(
cls
,
bin
)
cls2
=
p
.
loads
(
s
)
...
...
@@ -3358,30 +3358,31 @@ order (MRO) for bases """
__slots__
=
[
'a'
]
class
D
(
C
):
pass
try
:
pickle
.
dumps
(
C
())
except
TypeError
:
pass
else
:
self
.
fail
(
"should fail: pickle C instance - %s"
%
base
)
try
:
cPickle
.
dumps
(
C
())
except
TypeError
:
pass
else
:
self
.
fail
(
"should fail: cPickle C instance - %s"
%
base
)
try
:
pickle
.
dumps
(
C
())
except
TypeError
:
pass
else
:
self
.
fail
(
"should fail: pickle D instance - %s"
%
base
)
try
:
cPickle
.
dumps
(
D
())
except
TypeError
:
pass
else
:
self
.
fail
(
"should fail: cPickle D instance - %s"
%
base
)
for
proto
in
range
(
2
):
try
:
pickle
.
dumps
(
C
(),
proto
)
except
TypeError
:
pass
else
:
self
.
fail
(
"should fail: pickle C instance - %s"
%
base
)
try
:
cPickle
.
dumps
(
C
(),
proto
)
except
TypeError
:
pass
else
:
self
.
fail
(
"should fail: cPickle C instance - %s"
%
base
)
try
:
pickle
.
dumps
(
C
(),
proto
)
except
TypeError
:
pass
else
:
self
.
fail
(
"should fail: pickle D instance - %s"
%
base
)
try
:
cPickle
.
dumps
(
D
(),
proto
)
except
TypeError
:
pass
else
:
self
.
fail
(
"should fail: cPickle D instance - %s"
%
base
)
# Give C a nice generic __getstate__ and __setstate__
class
C
(
base
):
__slots__
=
[
'a'
]
...
...
@@ -3404,34 +3405,38 @@ order (MRO) for bases """
pass
# Now it should work
x
=
C
()
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
))
self
.
assertNotHasAttr
(
y
,
'a'
)
y
=
cPickle
.
loads
(
cPickle
.
dumps
(
x
))
self
.
assertNotHasAttr
(
y
,
'a'
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
,
proto
))
self
.
assertNotHasAttr
(
y
,
'a'
)
y
=
cPickle
.
loads
(
cPickle
.
dumps
(
x
,
proto
))
self
.
assertNotHasAttr
(
y
,
'a'
)
x
.
a
=
42
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
))
self
.
assertEqual
(
y
.
a
,
42
)
y
=
cPickle
.
loads
(
cPickle
.
dumps
(
x
))
self
.
assertEqual
(
y
.
a
,
42
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
,
proto
))
self
.
assertEqual
(
y
.
a
,
42
)
y
=
cPickle
.
loads
(
cPickle
.
dumps
(
x
,
proto
))
self
.
assertEqual
(
y
.
a
,
42
)
x
=
D
()
x
.
a
=
42
x
.
b
=
100
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
))
self
.
assertEqual
(
y
.
a
+
y
.
b
,
142
)
y
=
cPickle
.
loads
(
cPickle
.
dumps
(
x
))
self
.
assertEqual
(
y
.
a
+
y
.
b
,
142
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
,
proto
))
self
.
assertEqual
(
y
.
a
+
y
.
b
,
142
)
y
=
cPickle
.
loads
(
cPickle
.
dumps
(
x
,
proto
))
self
.
assertEqual
(
y
.
a
+
y
.
b
,
142
)
# A subclass that adds a slot should also work
class
E
(
C
):
__slots__
=
[
'b'
]
x
=
E
()
x
.
a
=
42
x
.
b
=
"foo"
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
))
self
.
assertEqual
(
y
.
a
,
x
.
a
)
self
.
assertEqual
(
y
.
b
,
x
.
b
)
y
=
cPickle
.
loads
(
cPickle
.
dumps
(
x
))
self
.
assertEqual
(
y
.
a
,
x
.
a
)
self
.
assertEqual
(
y
.
b
,
x
.
b
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
,
proto
))
self
.
assertEqual
(
y
.
a
,
x
.
a
)
self
.
assertEqual
(
y
.
b
,
x
.
b
)
y
=
cPickle
.
loads
(
cPickle
.
dumps
(
x
,
proto
))
self
.
assertEqual
(
y
.
a
,
x
.
a
)
self
.
assertEqual
(
y
.
b
,
x
.
b
)
def
test_binary_operator_override
(
self
):
# Testing overrides of binary operations...
...
...
Lib/test/test_functools.py
View file @
655720e2
...
...
@@ -146,8 +146,9 @@ class TestPartial(unittest.TestCase):
def
test_pickle
(
self
):
f
=
self
.
thetype
(
signature
,
'asdf'
,
bar
=
True
)
f
.
add_something_to__dict__
=
True
f_copy
=
pickle
.
loads
(
pickle
.
dumps
(
f
))
self
.
assertEqual
(
signature
(
f
),
signature
(
f_copy
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
f_copy
=
pickle
.
loads
(
pickle
.
dumps
(
f
,
proto
))
self
.
assertEqual
(
signature
(
f
),
signature
(
f_copy
))
# Issue 6083: Reference counting bug
def
test_setstate_refcount
(
self
):
...
...
Lib/test/test_itertools.py
View file @
655720e2
...
...
@@ -358,7 +358,8 @@ class TestBasicOps(unittest.TestCase):
c
=
count
(
value
)
self
.
assertEqual
(
next
(
copy
.
copy
(
c
)),
value
)
self
.
assertEqual
(
next
(
copy
.
deepcopy
(
c
)),
value
)
self
.
assertEqual
(
next
(
pickle
.
loads
(
pickle
.
dumps
(
c
))),
value
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
self
.
assertEqual
(
next
(
pickle
.
loads
(
pickle
.
dumps
(
c
,
proto
))),
value
)
def
test_count_with_stride
(
self
):
self
.
assertEqual
(
zip
(
'abc'
,
count
(
2
,
3
)),
[(
'a'
,
2
),
(
'b'
,
5
),
(
'c'
,
8
)])
...
...
Lib/test/test_memoryio.py
View file @
655720e2
...
...
@@ -376,13 +376,14 @@ class MemoryTestMixin:
# the module-level.
import
__main__
PickleTestMemIO
.
__module__
=
'__main__'
PickleTestMemIO
.
__qualname__
=
PickleTestMemIO
.
__name__
__main__
.
PickleTestMemIO
=
PickleTestMemIO
submemio
=
PickleTestMemIO
(
buf
,
80
)
submemio
.
seek
(
2
)
# We only support pickle protocol 2 and onward since we use extended
# __reduce__ API of PEP 307 to provide pickling support.
for
proto
in
range
(
2
,
pickle
.
HIGHEST_PROTOCOL
):
for
proto
in
range
(
2
,
pickle
.
HIGHEST_PROTOCOL
+
1
):
for
obj
in
(
memio
,
submemio
):
obj2
=
pickle
.
loads
(
pickle
.
dumps
(
obj
,
protocol
=
proto
))
self
.
assertEqual
(
obj
.
getvalue
(),
obj2
.
getvalue
())
...
...
Lib/test/test_minidom.py
View file @
655720e2
...
...
@@ -1385,43 +1385,44 @@ class MinidomTest(unittest.TestCase):
" <!ENTITY ent SYSTEM 'http://xml.python.org/entity'>
\
n
"
"]><doc attr='value'> text
\
n
"
"<?pi sample?> <!-- comment --> <e/> </doc>"
)
s
=
pickle
.
dumps
(
doc
)
doc2
=
pickle
.
loads
(
s
)
stack
=
[(
doc
,
doc2
)]
while
stack
:
n1
,
n2
=
stack
.
pop
()
self
.
confirm
(
n1
.
nodeType
==
n2
.
nodeType
and
len
(
n1
.
childNodes
)
==
len
(
n2
.
childNodes
)
and
n1
.
nodeName
==
n2
.
nodeName
and
not
n1
.
isSameNode
(
n2
)
and
not
n2
.
isSameNode
(
n1
))
if
n1
.
nodeType
==
Node
.
DOCUMENT_TYPE_NODE
:
len
(
n1
.
entities
)
len
(
n2
.
entities
)
len
(
n1
.
notations
)
len
(
n2
.
notations
)
self
.
confirm
(
len
(
n1
.
entities
)
==
len
(
n2
.
entities
)
and
len
(
n1
.
notations
)
==
len
(
n2
.
notations
))
for
i
in
range
(
len
(
n1
.
notations
)):
# XXX this loop body doesn't seem to be executed?
no1
=
n1
.
notations
.
item
(
i
)
no2
=
n1
.
notations
.
item
(
i
)
self
.
confirm
(
no1
.
name
==
no2
.
name
and
no1
.
publicId
==
no2
.
publicId
and
no1
.
systemId
==
no2
.
systemId
)
stack
.
append
((
no1
,
no2
))
for
i
in
range
(
len
(
n1
.
entities
)):
e1
=
n1
.
entities
.
item
(
i
)
e2
=
n2
.
entities
.
item
(
i
)
self
.
confirm
(
e1
.
notationName
==
e2
.
notationName
and
e1
.
publicId
==
e2
.
publicId
and
e1
.
systemId
==
e2
.
systemId
)
stack
.
append
((
e1
,
e2
))
if
n1
.
nodeType
!=
Node
.
DOCUMENT_NODE
:
self
.
confirm
(
n1
.
ownerDocument
.
isSameNode
(
doc
)
and
n2
.
ownerDocument
.
isSameNode
(
doc2
))
for
i
in
range
(
len
(
n1
.
childNodes
)):
stack
.
append
((
n1
.
childNodes
[
i
],
n2
.
childNodes
[
i
]))
for
proto
in
range
(
2
,
pickle
.
HIGHEST_PROTOCOL
+
1
):
s
=
pickle
.
dumps
(
doc
,
proto
)
doc2
=
pickle
.
loads
(
s
)
stack
=
[(
doc
,
doc2
)]
while
stack
:
n1
,
n2
=
stack
.
pop
()
self
.
confirm
(
n1
.
nodeType
==
n2
.
nodeType
and
len
(
n1
.
childNodes
)
==
len
(
n2
.
childNodes
)
and
n1
.
nodeName
==
n2
.
nodeName
and
not
n1
.
isSameNode
(
n2
)
and
not
n2
.
isSameNode
(
n1
))
if
n1
.
nodeType
==
Node
.
DOCUMENT_TYPE_NODE
:
len
(
n1
.
entities
)
len
(
n2
.
entities
)
len
(
n1
.
notations
)
len
(
n2
.
notations
)
self
.
confirm
(
len
(
n1
.
entities
)
==
len
(
n2
.
entities
)
and
len
(
n1
.
notations
)
==
len
(
n2
.
notations
))
for
i
in
range
(
len
(
n1
.
notations
)):
# XXX this loop body doesn't seem to be executed?
no1
=
n1
.
notations
.
item
(
i
)
no2
=
n1
.
notations
.
item
(
i
)
self
.
confirm
(
no1
.
name
==
no2
.
name
and
no1
.
publicId
==
no2
.
publicId
and
no1
.
systemId
==
no2
.
systemId
)
stack
.
append
((
no1
,
no2
))
for
i
in
range
(
len
(
n1
.
entities
)):
e1
=
n1
.
entities
.
item
(
i
)
e2
=
n2
.
entities
.
item
(
i
)
self
.
confirm
(
e1
.
notationName
==
e2
.
notationName
and
e1
.
publicId
==
e2
.
publicId
and
e1
.
systemId
==
e2
.
systemId
)
stack
.
append
((
e1
,
e2
))
if
n1
.
nodeType
!=
Node
.
DOCUMENT_NODE
:
self
.
confirm
(
n1
.
ownerDocument
.
isSameNode
(
doc
)
and
n2
.
ownerDocument
.
isSameNode
(
doc2
))
for
i
in
range
(
len
(
n1
.
childNodes
)):
stack
.
append
((
n1
.
childNodes
[
i
],
n2
.
childNodes
[
i
]))
def
testSerializeCommentNodeWithDoubleHyphen
(
self
):
doc
=
create_doc_without_doctype
()
...
...
Lib/test/test_random.py
View file @
655720e2
...
...
@@ -140,11 +140,12 @@ class TestBasicOps(unittest.TestCase):
self
.
assertEqual
(
y1
,
y2
)
def
test_pickling
(
self
):
state
=
pickle
.
dumps
(
self
.
gen
)
origseq
=
[
self
.
gen
.
random
()
for
i
in
xrange
(
10
)]
newgen
=
pickle
.
loads
(
state
)
restoredseq
=
[
newgen
.
random
()
for
i
in
xrange
(
10
)]
self
.
assertEqual
(
origseq
,
restoredseq
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
state
=
pickle
.
dumps
(
self
.
gen
,
proto
)
origseq
=
[
self
.
gen
.
random
()
for
i
in
xrange
(
10
)]
newgen
=
pickle
.
loads
(
state
)
restoredseq
=
[
newgen
.
random
()
for
i
in
xrange
(
10
)]
self
.
assertEqual
(
origseq
,
restoredseq
)
def
test_bug_1727780
(
self
):
# verify that version-2-pickles can be loaded
...
...
@@ -226,7 +227,8 @@ class SystemRandom_TestBasicOps(TestBasicOps):
self
.
assertEqual
(
self
.
gen
.
gauss_next
,
None
)
def
test_pickling
(
self
):
self
.
assertRaises
(
NotImplementedError
,
pickle
.
dumps
,
self
.
gen
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
self
.
assertRaises
(
NotImplementedError
,
pickle
.
dumps
,
self
.
gen
,
proto
)
def
test_53_bits_per_float
(
self
):
# This should pass whenever a C double has 53 bit precision.
...
...
Lib/test/test_set.py
View file @
655720e2
...
...
@@ -233,7 +233,7 @@ class TestJointOps(unittest.TestCase):
self
.
assertEqual
(
self
.
s
,
dup
,
"%s != %s"
%
(
self
.
s
,
dup
))
if
type
(
self
.
s
)
not
in
(
set
,
frozenset
):
self
.
s
.
x
=
10
p
=
pickle
.
dumps
(
self
.
s
)
p
=
pickle
.
dumps
(
self
.
s
,
i
)
dup
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
self
.
s
.
x
,
dup
.
x
)
...
...
@@ -786,10 +786,11 @@ class TestBasicOps(unittest.TestCase):
self
.
assertEqual
(
setiter
.
__length_hint__
(),
len
(
self
.
set
))
def
test_pickling
(
self
):
p
=
pickle
.
dumps
(
self
.
set
)
copy
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
self
.
set
,
copy
,
"%s != %s"
%
(
self
.
set
,
copy
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
p
=
pickle
.
dumps
(
self
.
set
,
proto
)
copy
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
self
.
set
,
copy
,
"%s != %s"
%
(
self
.
set
,
copy
))
#------------------------------------------------------------------------------
...
...
Lib/test/test_sets.py
View file @
655720e2
...
...
@@ -75,10 +75,11 @@ class TestBasicOps(unittest.TestCase):
self
.
assertIn
(
v
,
self
.
values
)
def
test_pickling
(
self
):
p
=
pickle
.
dumps
(
self
.
set
)
copy
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
self
.
set
,
copy
,
"%s != %s"
%
(
self
.
set
,
copy
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
p
=
pickle
.
dumps
(
self
.
set
,
proto
)
copy
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
self
.
set
,
copy
,
"%s != %s"
%
(
self
.
set
,
copy
))
#------------------------------------------------------------------------------
...
...
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