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
65ee4674
Commit
65ee4674
authored
Dec 15, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #22777: Test pickling with all protocols.
parents
0e32ea10
bad1257c
Changes
31
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
728 additions
and
647 deletions
+728
-647
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/datetimetester.py
Lib/test/datetimetester.py
+6
-5
Lib/test/seq_tests.py
Lib/test/seq_tests.py
+4
-3
Lib/test/test_array.py
Lib/test/test_array.py
+11
-10
Lib/test/test_bool.py
Lib/test/test_bool.py
+3
-4
Lib/test/test_builtin.py
Lib/test/test_builtin.py
+14
-11
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+17
-16
Lib/test/test_bz2.py
Lib/test/test_bz2.py
+6
-4
Lib/test/test_collections.py
Lib/test/test_collections.py
+36
-45
Lib/test/test_configparser.py
Lib/test/test_configparser.py
+97
-85
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+98
-96
Lib/test/test_deque.py
Lib/test/test_deque.py
+23
-20
Lib/test/test_dict.py
Lib/test/test_dict.py
+50
-47
Lib/test/test_email/test_pickleable.py
Lib/test/test_email/test_pickleable.py
+8
-6
Lib/test/test_enumerate.py
Lib/test/test_enumerate.py
+15
-14
Lib/test/test_functools.py
Lib/test/test_functools.py
+3
-2
Lib/test/test_iter.py
Lib/test/test_iter.py
+17
-16
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+102
-68
Lib/test/test_list.py
Lib/test/test_list.py
+22
-20
Lib/test/test_lzma.py
Lib/test/test_lzma.py
+5
-4
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_os.py
Lib/test/test_os.py
+14
-8
Lib/test/test_random.py
Lib/test/test_random.py
+8
-6
Lib/test/test_range.py
Lib/test/test_range.py
+24
-22
Lib/test/test_set.py
Lib/test/test_set.py
+25
-23
Lib/test/test_sndhdr.py
Lib/test/test_sndhdr.py
+3
-2
Lib/test/test_tuple.py
Lib/test/test_tuple.py
+22
-20
Lib/test/test_xml_dom_minicompat.py
Lib/test/test_xml_dom_minicompat.py
+13
-12
Lib/test/test_xml_etree.py
Lib/test/test_xml_etree.py
+30
-27
No files found.
Lib/ctypes/test/test_pickling.py
View file @
65ee4674
...
...
@@ -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
(
b"x"
))
self
.
dumps
(
c_char
(
b"x"
))
# Issue 5049
pickle
.
dumps
(
c_wchar
(
"x"
))
self
.
dumps
(
c_wchar
(
"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 @
65ee4674
...
...
@@ -45,8 +45,9 @@ class AudioTests:
self
.
assertEqual
(
params
.
comptype
,
comptype
)
self
.
assertEqual
(
params
.
compname
,
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/datetimetester.py
View file @
65ee4674
...
...
@@ -1704,11 +1704,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/seq_tests.py
View file @
65ee4674
...
...
@@ -392,6 +392,7 @@ class CommonTest(unittest.TestCase):
def
test_pickle
(
self
):
lst
=
self
.
type2test
([
4
,
5
,
6
,
7
])
lst2
=
pickle
.
loads
(
pickle
.
dumps
(
lst
))
self
.
assertEqual
(
lst2
,
lst
)
self
.
assertNotEqual
(
id
(
lst2
),
id
(
lst
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
lst2
=
pickle
.
loads
(
pickle
.
dumps
(
lst
,
proto
))
self
.
assertEqual
(
lst2
,
lst
)
self
.
assertNotEqual
(
id
(
lst2
),
id
(
lst
))
Lib/test/test_array.py
View file @
65ee4674
...
...
@@ -285,17 +285,18 @@ class BaseTest:
def
test_iterator_pickle
(
self
):
data
=
array
.
array
(
self
.
typecode
,
self
.
example
)
orgit
=
iter
(
data
)
d
=
pickle
.
dumps
(
orgit
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
orgit
),
type
(
it
))
self
.
assertEqual
(
list
(
it
),
list
(
data
))
if
len
(
data
):
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
orgit
=
iter
(
data
)
d
=
pickle
.
dumps
(
orgit
,
proto
)
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
)
self
.
assertEqual
(
list
(
it
),
list
(
data
)[
1
:])
self
.
assertEqual
(
type
(
orgit
),
type
(
it
))
self
.
assertEqual
(
list
(
it
),
list
(
data
))
if
len
(
data
):
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
self
.
assertEqual
(
list
(
it
),
list
(
data
)[
1
:])
def
test_insert
(
self
):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
...
...
Lib/test/test_bool.py
View file @
65ee4674
...
...
@@ -269,10 +269,9 @@ 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_picklevalues
(
self
):
# Test for specific backwards-compatible pickle values
...
...
Lib/test/test_builtin.py
View file @
65ee4674
...
...
@@ -121,9 +121,9 @@ def map_char(arg):
class
BuiltinTest
(
unittest
.
TestCase
):
# Helper to check picklability
def
check_iter_pickle
(
self
,
it
,
seq
):
def
check_iter_pickle
(
self
,
it
,
seq
,
proto
):
itorg
=
it
d
=
pickle
.
dumps
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
list
(
it
),
seq
)
...
...
@@ -134,7 +134,7 @@ class BuiltinTest(unittest.TestCase):
next
(
it
)
except
StopIteration
:
return
d
=
pickle
.
dumps
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
it
),
seq
[
1
:])
...
...
@@ -636,9 +636,10 @@ class BuiltinTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
list
,
filter
(
42
,
(
1
,
2
)))
def
test_filter_pickle
(
self
):
f1
=
filter
(
filter_char
,
"abcdeabcde"
)
f2
=
filter
(
filter_char
,
"abcdeabcde"
)
self
.
check_iter_pickle
(
f1
,
list
(
f2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
f1
=
filter
(
filter_char
,
"abcdeabcde"
)
f2
=
filter
(
filter_char
,
"abcdeabcde"
)
self
.
check_iter_pickle
(
f1
,
list
(
f2
),
proto
)
def
test_getattr
(
self
):
self
.
assertTrue
(
getattr
(
sys
,
'stdout'
)
is
sys
.
stdout
)
...
...
@@ -834,9 +835,10 @@ class BuiltinTest(unittest.TestCase):
self
.
assertRaises
(
RuntimeError
,
list
,
map
(
badfunc
,
range
(
5
)))
def
test_map_pickle
(
self
):
m1
=
map
(
map_char
,
"Is this the real life?"
)
m2
=
map
(
map_char
,
"Is this the real life?"
)
self
.
check_iter_pickle
(
m1
,
list
(
m2
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
m1
=
map
(
map_char
,
"Is this the real life?"
)
m2
=
map
(
map_char
,
"Is this the real life?"
)
self
.
check_iter_pickle
(
m1
,
list
(
m2
),
proto
)
def
test_max
(
self
):
self
.
assertEqual
(
max
(
'123123'
),
'3'
)
...
...
@@ -1433,8 +1435,9 @@ class BuiltinTest(unittest.TestCase):
a
=
(
1
,
2
,
3
)
b
=
(
4
,
5
,
6
)
t
=
[(
1
,
4
),
(
2
,
5
),
(
3
,
6
)]
z1
=
zip
(
a
,
b
)
self
.
check_iter_pickle
(
z1
,
t
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
z1
=
zip
(
a
,
b
)
self
.
check_iter_pickle
(
z1
,
t
,
proto
)
def
test_format
(
self
):
# Test the basic machinery of the format() builtin. Don't test
...
...
Lib/test/test_bytes.py
View file @
65ee4674
...
...
@@ -555,22 +555,23 @@ class BaseBytesTest:
self.assertEqual(b, q)
def test_iterator_pickling(self):
for b in b"", b"a", b"abc", b"
\
xff
ab
\
x80
", b"
\
0
\
0
\
377
\
0
\
0
":
it = itorg = iter(self.type2test(b))
data = list(self.type2test(b))
d = pickle.dumps(it)
it = pickle.loads(d)
self.assertEqual(type(itorg), type(it))
self.assertEqual(list(it), data)
it = pickle.loads(d)
try:
next(it)
except StopIteration:
continue
d = pickle.dumps(it)
it = pickle.loads(d)
self.assertEqual(list(it), data[1:])
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
for b in b"", b"a", b"abc", b"
\
xff
ab
\
x80
", b"
\
0
\
0
\
377
\
0
\
0
":
it = itorg = iter(self.type2test(b))
data = list(self.type2test(b))
d = pickle.dumps(it, proto)
it = pickle.loads(d)
self.assertEqual(type(itorg), type(it))
self.assertEqual(list(it), data)
it = pickle.loads(d)
try:
next(it)
except StopIteration:
continue
d = pickle.dumps(it, proto)
it = pickle.loads(d)
self.assertEqual(list(it), data[1:])
def test_strip(self):
b = self.type2test(b'
mississippi
')
...
...
Lib/test/test_bz2.py
View file @
65ee4674
...
...
@@ -646,8 +646,9 @@ class BZ2CompressorTest(BaseTest):
data
=
None
def
testPickle
(
self
):
with
self
.
assertRaises
(
TypeError
):
pickle
.
dumps
(
BZ2Compressor
())
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
with
self
.
assertRaises
(
TypeError
):
pickle
.
dumps
(
BZ2Compressor
(),
proto
)
class
BZ2DecompressorTest
(
BaseTest
):
...
...
@@ -702,8 +703,9 @@ class BZ2DecompressorTest(BaseTest):
decompressed
=
None
def
testPickle
(
self
):
with
self
.
assertRaises
(
TypeError
):
pickle
.
dumps
(
BZ2Decompressor
())
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
with
self
.
assertRaises
(
TypeError
):
pickle
.
dumps
(
BZ2Decompressor
(),
proto
)
class
CompressDecompressTest
(
BaseTest
):
...
...
Lib/test/test_collections.py
View file @
65ee4674
...
...
@@ -63,10 +63,17 @@ class TestChainMap(unittest.TestCase):
for
m1
,
m2
in
zip
(
d
.
maps
[
1
:],
e
.
maps
[
1
:]):
self
.
assertIs
(
m1
,
m2
)
for
e
in
[
pickle
.
loads
(
pickle
.
dumps
(
d
)),
copy
.
deepcopy
(
d
),
# check deep copies
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
e
=
pickle
.
loads
(
pickle
.
dumps
(
d
,
proto
))
self
.
assertEqual
(
d
,
e
)
self
.
assertEqual
(
d
.
maps
,
e
.
maps
)
self
.
assertIsNot
(
d
,
e
)
for
m1
,
m2
in
zip
(
d
.
maps
,
e
.
maps
):
self
.
assertIsNot
(
m1
,
m2
,
e
)
for
e
in
[
copy
.
deepcopy
(
d
),
eval
(
repr
(
d
))
]:
# check deep copies
]:
self
.
assertEqual
(
d
,
e
)
self
.
assertEqual
(
d
.
maps
,
e
.
maps
)
self
.
assertIsNot
(
d
,
e
)
...
...
@@ -1163,28 +1170,21 @@ class TestCounter(unittest.TestCase):
# Check that counters are copyable, deepcopyable, picklable, and
#have a repr/eval round-trip
words
=
Counter
(
'which witch had which witches wrist watch'
.
split
())
def
check
(
dup
):
msg
=
"
\
n
copy: %s
\
n
words: %s"
%
(
dup
,
words
)
self
.
assertIsNot
(
dup
,
words
,
msg
)
self
.
assertEqual
(
dup
,
words
)
check
(
words
.
copy
())
check
(
copy
.
copy
(
words
))
check
(
copy
.
deepcopy
(
words
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
with
self
.
subTest
(
proto
=
proto
):
check
(
pickle
.
loads
(
pickle
.
dumps
(
words
,
proto
)))
check
(
eval
(
repr
(
words
)))
update_test
=
Counter
()
update_test
.
update
(
words
)
for
label
,
dup
in
[
(
'words.copy()'
,
words
.
copy
()),
(
'copy.copy(words)'
,
copy
.
copy
(
words
)),
(
'copy.deepcopy(words)'
,
copy
.
deepcopy
(
words
)),
(
'pickle.loads(pickle.dumps(words, 0))'
,
pickle
.
loads
(
pickle
.
dumps
(
words
,
0
))),
(
'pickle.loads(pickle.dumps(words, 1))'
,
pickle
.
loads
(
pickle
.
dumps
(
words
,
1
))),
(
'pickle.loads(pickle.dumps(words, 2))'
,
pickle
.
loads
(
pickle
.
dumps
(
words
,
2
))),
(
'pickle.loads(pickle.dumps(words, -1))'
,
pickle
.
loads
(
pickle
.
dumps
(
words
,
-
1
))),
(
'eval(repr(words))'
,
eval
(
repr
(
words
))),
(
'update_test'
,
update_test
),
(
'Counter(words)'
,
Counter
(
words
)),
]:
with
self
.
subTest
(
label
=
label
):
msg
=
"
\
n
copy: %s
\
n
words: %s"
%
(
dup
,
words
)
self
.
assertIsNot
(
dup
,
words
,
msg
)
self
.
assertEqual
(
dup
,
words
)
check
(
update_test
)
check
(
Counter
(
words
))
def
test_copy_subclass
(
self
):
class
MyCounter
(
Counter
):
...
...
@@ -1501,30 +1501,21 @@ class TestOrderedDict(unittest.TestCase):
# and have a repr/eval round-trip
pairs
=
[(
'c'
,
1
),
(
'b'
,
2
),
(
'a'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
)]
od
=
OrderedDict
(
pairs
)
def
check
(
dup
):
msg
=
"
\
n
copy: %s
\
n
od: %s"
%
(
dup
,
od
)
self
.
assertIsNot
(
dup
,
od
,
msg
)
self
.
assertEqual
(
dup
,
od
)
check
(
od
.
copy
())
check
(
copy
.
copy
(
od
))
check
(
copy
.
deepcopy
(
od
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
with
self
.
subTest
(
proto
=
proto
):
check
(
pickle
.
loads
(
pickle
.
dumps
(
od
,
proto
)))
check
(
eval
(
repr
(
od
)))
update_test
=
OrderedDict
()
update_test
.
update
(
od
)
for
label
,
dup
in
[
(
'od.copy()'
,
od
.
copy
()),
(
'copy.copy(od)'
,
copy
.
copy
(
od
)),
(
'copy.deepcopy(od)'
,
copy
.
deepcopy
(
od
)),
(
'pickle.loads(pickle.dumps(od, 0))'
,
pickle
.
loads
(
pickle
.
dumps
(
od
,
0
))),
(
'pickle.loads(pickle.dumps(od, 1))'
,
pickle
.
loads
(
pickle
.
dumps
(
od
,
1
))),
(
'pickle.loads(pickle.dumps(od, 2))'
,
pickle
.
loads
(
pickle
.
dumps
(
od
,
2
))),
(
'pickle.loads(pickle.dumps(od, 3))'
,
pickle
.
loads
(
pickle
.
dumps
(
od
,
3
))),
(
'pickle.loads(pickle.dumps(od, -1))'
,
pickle
.
loads
(
pickle
.
dumps
(
od
,
-
1
))),
(
'eval(repr(od))'
,
eval
(
repr
(
od
))),
(
'update_test'
,
update_test
),
(
'OrderedDict(od)'
,
OrderedDict
(
od
)),
]:
with
self
.
subTest
(
label
=
label
):
msg
=
"
\
n
copy: %s
\
n
od: %s"
%
(
dup
,
od
)
self
.
assertIsNot
(
dup
,
od
,
msg
)
self
.
assertEqual
(
dup
,
od
)
check
(
update_test
)
check
(
OrderedDict
(
od
))
def
test_yaml_linkage
(
self
):
# Verify that __reduce__ is setup in a way that supports PyYAML's dump() feature.
...
...
Lib/test/test_configparser.py
View file @
65ee4674
This diff is collapsed.
Click to expand it.
Lib/test/test_decimal.py
View file @
65ee4674
...
...
@@ -2407,54 +2407,55 @@ class PythonAPItests(unittest.TestCase):
self
.
assertNotIsInstance
(
Decimal
(
0
),
numbers
.
Real
)
def
test_pickle
(
self
):
Decimal
=
self
.
decimal
.
Decimal
savedecimal
=
sys
.
modules
[
'decimal'
]
# Round trip
sys
.
modules
[
'decimal'
]
=
self
.
decimal
d
=
Decimal
(
'-3.141590000'
)
p
=
pickle
.
dumps
(
d
)
e
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
d
,
e
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
Decimal
=
self
.
decimal
.
Decimal
if
C
:
# Test interchangeability
x
=
C
.
Decimal
(
'-3.123e81723'
)
y
=
P
.
Decimal
(
'-3.123e81723'
)
savedecimal
=
sys
.
modules
[
'decimal'
]
sys
.
modules
[
'decimal'
]
=
C
s
x
=
pickle
.
dumps
(
x
)
sys
.
modules
[
'decimal'
]
=
P
r
=
pickle
.
loads
(
sx
)
self
.
assertIsInstance
(
r
,
P
.
Decimal
)
self
.
assertEqual
(
r
,
y
)
# Round trip
s
ys
.
modules
[
'decimal'
]
=
self
.
decimal
d
=
Decimal
(
'-3.141590000'
)
p
=
pickle
.
dumps
(
d
,
proto
)
e
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
d
,
e
)
sys
.
modules
[
'decimal'
]
=
P
sy
=
pickle
.
dumps
(
y
)
sys
.
modules
[
'decimal'
]
=
C
r
=
pickle
.
loads
(
sy
)
self
.
assertIsInstance
(
r
,
C
.
Decimal
)
self
.
assertEqual
(
r
,
x
)
if
C
:
# Test interchangeability
x
=
C
.
Decimal
(
'-3.123e81723'
)
y
=
P
.
Decimal
(
'-3.123e81723'
)
x
=
C
.
Decimal
(
'-3.123e81723'
).
as_tuple
()
y
=
P
.
Decimal
(
'-3.123e81723'
).
as_tuple
()
sys
.
modules
[
'decimal'
]
=
C
sx
=
pickle
.
dumps
(
x
,
proto
)
sys
.
modules
[
'decimal'
]
=
P
r
=
pickle
.
loads
(
sx
)
self
.
assertIsInstance
(
r
,
P
.
Decimal
)
self
.
assertEqual
(
r
,
y
)
sys
.
modules
[
'decimal'
]
=
P
sy
=
pickle
.
dumps
(
y
,
proto
)
sys
.
modules
[
'decimal'
]
=
C
r
=
pickle
.
loads
(
sy
)
self
.
assertIsInstance
(
r
,
C
.
Decimal
)
self
.
assertEqual
(
r
,
x
)
sys
.
modules
[
'decimal'
]
=
C
sx
=
pickle
.
dumps
(
x
)
sys
.
modules
[
'decimal'
]
=
P
r
=
pickle
.
loads
(
sx
)
self
.
assertIsInstance
(
r
,
P
.
DecimalTuple
)
self
.
assertEqual
(
r
,
y
)
x
=
C
.
Decimal
(
'-3.123e81723'
).
as_tuple
()
y
=
P
.
Decimal
(
'-3.123e81723'
).
as_tuple
()
sys
.
modules
[
'decimal'
]
=
P
sy
=
pickle
.
dumps
(
y
)
sys
.
modules
[
'decimal'
]
=
C
r
=
pickle
.
loads
(
sy
)
self
.
assertIsInstance
(
r
,
C
.
DecimalTuple
)
self
.
assertEqual
(
r
,
x
)
sys
.
modules
[
'decimal'
]
=
C
sx
=
pickle
.
dumps
(
x
,
proto
)
sys
.
modules
[
'decimal'
]
=
P
r
=
pickle
.
loads
(
sx
)
self
.
assertIsInstance
(
r
,
P
.
DecimalTuple
)
self
.
assertEqual
(
r
,
y
)
sys
.
modules
[
'decimal'
]
=
P
sy
=
pickle
.
dumps
(
y
,
proto
)
sys
.
modules
[
'decimal'
]
=
C
r
=
pickle
.
loads
(
sy
)
self
.
assertIsInstance
(
r
,
C
.
DecimalTuple
)
self
.
assertEqual
(
r
,
x
)
sys
.
modules
[
'decimal'
]
=
savedecimal
sys
.
modules
[
'decimal'
]
=
savedecimal
def
test_int
(
self
):
Decimal
=
self
.
decimal
.
Decimal
...
...
@@ -2778,63 +2779,64 @@ class ContextAPItests(unittest.TestCase):
def
test_pickle
(
self
):
Context
=
self
.
decimal
.
Context
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
Context
=
self
.
decimal
.
Context
savedecimal
=
sys
.
modules
[
'decimal'
]
savedecimal
=
sys
.
modules
[
'decimal'
]
# Round trip
sys
.
modules
[
'decimal'
]
=
self
.
decimal
c
=
Context
()
e
=
pickle
.
loads
(
pickle
.
dumps
(
c
))
self
.
assertEqual
(
c
.
prec
,
e
.
prec
)
self
.
assertEqual
(
c
.
Emin
,
e
.
Emin
)
self
.
assertEqual
(
c
.
Emax
,
e
.
Emax
)
self
.
assertEqual
(
c
.
rounding
,
e
.
rounding
)
self
.
assertEqual
(
c
.
capitals
,
e
.
capitals
)
self
.
assertEqual
(
c
.
clamp
,
e
.
clamp
)
self
.
assertEqual
(
c
.
flags
,
e
.
flags
)
self
.
assertEqual
(
c
.
traps
,
e
.
traps
)
# Test interchangeability
combinations
=
[(
C
,
P
),
(
P
,
C
)]
if
C
else
[(
P
,
P
)]
for
dumper
,
loader
in
combinations
:
for
ri
,
_
in
enumerate
(
RoundingModes
):
for
fi
,
_
in
enumerate
(
OrderedSignals
[
dumper
]):
for
ti
,
_
in
enumerate
(
OrderedSignals
[
dumper
]):
prec
=
random
.
randrange
(
1
,
100
)
emin
=
random
.
randrange
(
-
100
,
0
)
emax
=
random
.
randrange
(
1
,
100
)
caps
=
random
.
randrange
(
2
)
clamp
=
random
.
randrange
(
2
)
# One module dumps
sys
.
modules
[
'decimal'
]
=
dumper
c
=
dumper
.
Context
(
prec
=
prec
,
Emin
=
emin
,
Emax
=
emax
,
rounding
=
RoundingModes
[
ri
],
capitals
=
caps
,
clamp
=
clamp
,
flags
=
OrderedSignals
[
dumper
][:
fi
],
traps
=
OrderedSignals
[
dumper
][:
ti
]
)
s
=
pickle
.
dumps
(
c
)
# The other module loads
sys
.
modules
[
'decimal'
]
=
loader
d
=
pickle
.
loads
(
s
)
self
.
assertIsInstance
(
d
,
loader
.
Context
)
self
.
assertEqual
(
d
.
prec
,
prec
)
self
.
assertEqual
(
d
.
Emin
,
emin
)
self
.
assertEqual
(
d
.
Emax
,
emax
)
self
.
assertEqual
(
d
.
rounding
,
RoundingModes
[
ri
])
self
.
assertEqual
(
d
.
capitals
,
caps
)
self
.
assertEqual
(
d
.
clamp
,
clamp
)
assert_signals
(
self
,
d
,
'flags'
,
OrderedSignals
[
loader
][:
fi
])
assert_signals
(
self
,
d
,
'traps'
,
OrderedSignals
[
loader
][:
ti
])
sys
.
modules
[
'decimal'
]
=
savedecimal
# Round trip
sys
.
modules
[
'decimal'
]
=
self
.
decimal
c
=
Context
()
e
=
pickle
.
loads
(
pickle
.
dumps
(
c
,
proto
))
self
.
assertEqual
(
c
.
prec
,
e
.
prec
)
self
.
assertEqual
(
c
.
Emin
,
e
.
Emin
)
self
.
assertEqual
(
c
.
Emax
,
e
.
Emax
)
self
.
assertEqual
(
c
.
rounding
,
e
.
rounding
)
self
.
assertEqual
(
c
.
capitals
,
e
.
capitals
)
self
.
assertEqual
(
c
.
clamp
,
e
.
clamp
)
self
.
assertEqual
(
c
.
flags
,
e
.
flags
)
self
.
assertEqual
(
c
.
traps
,
e
.
traps
)
# Test interchangeability
combinations
=
[(
C
,
P
),
(
P
,
C
)]
if
C
else
[(
P
,
P
)]
for
dumper
,
loader
in
combinations
:
for
ri
,
_
in
enumerate
(
RoundingModes
):
for
fi
,
_
in
enumerate
(
OrderedSignals
[
dumper
]):
for
ti
,
_
in
enumerate
(
OrderedSignals
[
dumper
]):
prec
=
random
.
randrange
(
1
,
100
)
emin
=
random
.
randrange
(
-
100
,
0
)
emax
=
random
.
randrange
(
1
,
100
)
caps
=
random
.
randrange
(
2
)
clamp
=
random
.
randrange
(
2
)
# One module dumps
sys
.
modules
[
'decimal'
]
=
dumper
c
=
dumper
.
Context
(
prec
=
prec
,
Emin
=
emin
,
Emax
=
emax
,
rounding
=
RoundingModes
[
ri
],
capitals
=
caps
,
clamp
=
clamp
,
flags
=
OrderedSignals
[
dumper
][:
fi
],
traps
=
OrderedSignals
[
dumper
][:
ti
]
)
s
=
pickle
.
dumps
(
c
,
proto
)
# The other module loads
sys
.
modules
[
'decimal'
]
=
loader
d
=
pickle
.
loads
(
s
)
self
.
assertIsInstance
(
d
,
loader
.
Context
)
self
.
assertEqual
(
d
.
prec
,
prec
)
self
.
assertEqual
(
d
.
Emin
,
emin
)
self
.
assertEqual
(
d
.
Emax
,
emax
)
self
.
assertEqual
(
d
.
rounding
,
RoundingModes
[
ri
])
self
.
assertEqual
(
d
.
capitals
,
caps
)
self
.
assertEqual
(
d
.
clamp
,
clamp
)
assert_signals
(
self
,
d
,
'flags'
,
OrderedSignals
[
loader
][:
fi
])
assert_signals
(
self
,
d
,
'traps'
,
OrderedSignals
[
loader
][:
ti
])
sys
.
modules
[
'decimal'
]
=
savedecimal
def
test_equality_with_other_types
(
self
):
Decimal
=
self
.
decimal
.
Decimal
...
...
Lib/test/test_deque.py
View file @
65ee4674
...
...
@@ -474,16 +474,17 @@ class TestBasic(unittest.TestCase):
def
test_iterator_pickle
(
self
):
data
=
deque
(
range
(
200
))
it
=
itorg
=
iter
(
data
)
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
list
(
it
),
list
(
data
))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
)
self
.
assertEqual
(
list
(
it
),
list
(
data
)[
1
:])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
it
=
itorg
=
iter
(
data
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
list
(
it
),
list
(
data
))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
self
.
assertEqual
(
list
(
it
),
list
(
data
)[
1
:])
def
test_deepcopy
(
self
):
mut
=
[
10
]
...
...
@@ -619,11 +620,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
)
...
...
@@ -635,11 +637,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_dict.py
View file @
65ee4674
...
...
@@ -837,57 +837,60 @@ class DictTest(unittest.TestCase):
self
.
_tracked
(
MyDict
())
def
test_iterator_pickling
(
self
):
data
=
{
1
:
"a"
,
2
:
"b"
,
3
:
"c"
}
it
=
iter
(
data
)
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
sorted
(
it
),
sorted
(
data
))
it
=
pickle
.
loads
(
d
)
try
:
drop
=
next
(
it
)
except
StopIteration
:
return
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
del
data
[
drop
]
self
.
assertEqual
(
sorted
(
it
),
sorted
(
data
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
data
=
{
1
:
"a"
,
2
:
"b"
,
3
:
"c"
}
it
=
iter
(
data
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
sorted
(
it
),
sorted
(
data
))
it
=
pickle
.
loads
(
d
)
try
:
drop
=
next
(
it
)
except
StopIteration
:
continue
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
del
data
[
drop
]
self
.
assertEqual
(
sorted
(
it
),
sorted
(
data
))
def
test_itemiterator_pickling
(
self
):
data
=
{
1
:
"a"
,
2
:
"b"
,
3
:
"c"
}
# dictviews aren't picklable, only their iterators
itorg
=
iter
(
data
.
items
())
d
=
pickle
.
dumps
(
itorg
)
it
=
pickle
.
loads
(
d
)
# note that the type of type of the unpickled iterator
# is not necessarily the same as the original. It is
# merely an object supporting the iterator protocol, yielding
# the same objects as the original one.
# self.assertEqual(type(itorg), type(it))
self
.
assertTrue
(
isinstance
(
it
,
collections
.
abc
.
Iterator
))
self
.
assertEqual
(
dict
(
it
),
data
)
it
=
pickle
.
loads
(
d
)
drop
=
next
(
it
)
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
del
data
[
drop
[
0
]]
self
.
assertEqual
(
dict
(
it
),
data
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
data
=
{
1
:
"a"
,
2
:
"b"
,
3
:
"c"
}
# dictviews aren't picklable, only their iterators
itorg
=
iter
(
data
.
items
())
d
=
pickle
.
dumps
(
itorg
,
proto
)
it
=
pickle
.
loads
(
d
)
# note that the type of type of the unpickled iterator
# is not necessarily the same as the original. It is
# merely an object supporting the iterator protocol, yielding
# the same objects as the original one.
# self.assertEqual(type(itorg), type(it))
self
.
assertIsInstance
(
it
,
collections
.
abc
.
Iterator
)
self
.
assertEqual
(
dict
(
it
),
data
)
it
=
pickle
.
loads
(
d
)
drop
=
next
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
del
data
[
drop
[
0
]]
self
.
assertEqual
(
dict
(
it
),
data
)
def
test_valuesiterator_pickling
(
self
):
data
=
{
1
:
"a"
,
2
:
"b"
,
3
:
"c"
}
# data.values() isn't picklable, only its iterator
it
=
iter
(
data
.
values
())
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
sorted
(
list
(
it
)),
sorted
(
list
(
data
.
values
())))
it
=
pickle
.
loads
(
d
)
drop
=
next
(
it
)
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
values
=
list
(
it
)
+
[
drop
]
self
.
assertEqual
(
sorted
(
values
),
sorted
(
list
(
data
.
values
())))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
):
data
=
{
1
:
"a"
,
2
:
"b"
,
3
:
"c"
}
# data.values() isn't picklable, only its iterator
it
=
iter
(
data
.
values
())
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
sorted
(
list
(
it
)),
sorted
(
list
(
data
.
values
())))
it
=
pickle
.
loads
(
d
)
drop
=
next
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
values
=
list
(
it
)
+
[
drop
]
self
.
assertEqual
(
sorted
(
values
),
sorted
(
list
(
data
.
values
())))
def
test_instance_dict_getattr_str_subclass
(
self
):
class
Foo
:
...
...
Lib/test/test_email/test_pickleable.py
View file @
65ee4674
...
...
@@ -30,9 +30,10 @@ class TestPickleCopyHeader(TestEmailBase):
def
header_as_pickle
(
self
,
name
,
value
):
header
=
self
.
header_factory
(
name
,
value
)
p
=
pickle
.
dumps
(
header
)
h
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
str
(
h
),
str
(
header
))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
p
=
pickle
.
dumps
(
header
,
proto
)
h
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
str
(
h
),
str
(
header
))
@
parameterize
...
...
@@ -65,9 +66,10 @@ class TestPickleCopyMessage(TestEmailBase):
self
.
assertEqual
(
msg2
.
as_string
(),
msg
.
as_string
())
def
msg_as_pickle
(
self
,
msg
):
p
=
pickle
.
dumps
(
msg
)
msg2
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
msg2
.
as_string
(),
msg
.
as_string
())
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
p
=
pickle
.
dumps
(
msg
,
proto
)
msg2
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
msg2
.
as_string
(),
msg
.
as_string
())
if
__name__
==
'__main__'
:
...
...
Lib/test/test_enumerate.py
View file @
65ee4674
...
...
@@ -66,20 +66,21 @@ class N:
class
PickleTest
:
# Helper to check picklability
def
check_pickle
(
self
,
itorg
,
seq
):
d
=
pickle
.
dumps
(
itorg
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
list
(
it
),
seq
)
it
=
pickle
.
loads
(
d
)
try
:
next
(
it
)
except
StopIteration
:
self
.
assertFalse
(
seq
[
1
:])
return
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
it
),
seq
[
1
:])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
d
=
pickle
.
dumps
(
itorg
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
list
(
it
),
seq
)
it
=
pickle
.
loads
(
d
)
try
:
next
(
it
)
except
StopIteration
:
self
.
assertFalse
(
seq
[
1
:])
continue
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
it
),
seq
[
1
:])
class
EnumerateTestCase
(
unittest
.
TestCase
,
PickleTest
):
...
...
Lib/test/test_functools.py
View file @
65ee4674
...
...
@@ -182,8 +182,9 @@ class TestPartialC(TestPartial, unittest.TestCase):
def
test_pickle
(
self
):
f
=
self
.
partial
(
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_iter.py
View file @
65ee4674
...
...
@@ -76,22 +76,23 @@ class TestCase(unittest.TestCase):
# Helper to check picklability
def
check_pickle
(
self
,
itorg
,
seq
):
d
=
pickle
.
dumps
(
itorg
)
it
=
pickle
.
loads
(
d
)
# Cannot assert type equality because dict iterators unpickle as list
# iterators.
# self.assertEqual(type(itorg), type(it))
self
.
assertTrue
(
isinstance
(
it
,
collections
.
abc
.
Iterator
))
self
.
assertEqual
(
list
(
it
),
seq
)
it
=
pickle
.
loads
(
d
)
try
:
next
(
it
)
except
StopIteration
:
return
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
it
),
seq
[
1
:])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
d
=
pickle
.
dumps
(
itorg
,
proto
)
it
=
pickle
.
loads
(
d
)
# Cannot assert type equality because dict iterators unpickle as list
# iterators.
# self.assertEqual(type(itorg), type(it))
self
.
assertTrue
(
isinstance
(
it
,
collections
.
abc
.
Iterator
))
self
.
assertEqual
(
list
(
it
),
seq
)
it
=
pickle
.
loads
(
d
)
try
:
next
(
it
)
except
StopIteration
:
continue
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
it
),
seq
[
1
:])
# Test basic use of iter() function
def
test_iter_basic
(
self
):
...
...
Lib/test/test_itertools.py
View file @
65ee4674
This diff is collapsed.
Click to expand it.
Lib/test/test_list.py
View file @
65ee4674
...
...
@@ -74,29 +74,31 @@ class ListTest(list_tests.CommonTest):
# Userlist iterators don't support pickling yet since
# they are based on generators.
data
=
self
.
type2test
([
4
,
5
,
6
,
7
])
it
=
itorg
=
iter
(
data
)
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
data
))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
)
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
data
)[
1
:])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
it
=
itorg
=
iter
(
data
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
data
))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
data
)[
1
:])
def
test_reversed_pickle
(
self
):
data
=
self
.
type2test
([
4
,
5
,
6
,
7
])
it
=
itorg
=
reversed
(
data
)
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
reversed
(
data
)))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
)
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
reversed
(
data
))[
1
:])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
it
=
itorg
=
reversed
(
data
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
reversed
(
data
)))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
reversed
(
data
))[
1
:])
def
test_no_comdat_folding
(
self
):
# Issue 8847: In the PGO build, the MSVC linker's COMDAT folding
...
...
Lib/test/test_lzma.py
View file @
65ee4674
...
...
@@ -220,10 +220,11 @@ class CompressorDecompressorTestCase(unittest.TestCase):
# Pickling raises an exception; there's no way to serialize an lzma_stream.
def
test_pickle
(
self
):
with
self
.
assertRaises
(
TypeError
):
pickle
.
dumps
(
LZMACompressor
())
with
self
.
assertRaises
(
TypeError
):
pickle
.
dumps
(
LZMADecompressor
())
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
with
self
.
assertRaises
(
TypeError
):
pickle
.
dumps
(
LZMACompressor
(),
proto
)
with
self
.
assertRaises
(
TypeError
):
pickle
.
dumps
(
LZMADecompressor
(),
proto
)
class
CompressDecompressFunctionTestCase
(
unittest
.
TestCase
):
...
...
Lib/test/test_memoryio.py
View file @
65ee4674
...
...
@@ -367,13 +367,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 @
65ee4674
...
...
@@ -1468,43 +1468,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_os.py
View file @
65ee4674
...
...
@@ -293,10 +293,13 @@ class StatAttributeTests(unittest.TestCase):
def
test_stat_result_pickle
(
self
):
result
=
os
.
stat
(
self
.
fname
)
p
=
pickle
.
dumps
(
result
)
self
.
assertIn
(
b'
\
x03
cos
\
n
stat_result
\
n
'
,
p
)
unpickled
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
result
,
unpickled
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
p
=
pickle
.
dumps
(
result
,
proto
)
self
.
assertIn
(
b'stat_result'
,
p
)
if
proto
<
4
:
self
.
assertIn
(
b'cos
\
n
stat_result
\
n
'
,
p
)
unpickled
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
result
,
unpickled
)
@
unittest
.
skipUnless
(
hasattr
(
os
,
'statvfs'
),
'test needs os.statvfs()'
)
def
test_statvfs_attributes
(
self
):
...
...
@@ -352,10 +355,13 @@ class StatAttributeTests(unittest.TestCase):
if
e
.
errno
==
errno
.
ENOSYS
:
self
.
skipTest
(
'os.statvfs() failed with ENOSYS'
)
p
=
pickle
.
dumps
(
result
)
self
.
assertIn
(
b'
\
x03
cos
\
n
statvfs_result
\
n
'
,
p
)
unpickled
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
result
,
unpickled
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
p
=
pickle
.
dumps
(
result
,
proto
)
self
.
assertIn
(
b'statvfs_result'
,
p
)
if
proto
<
4
:
self
.
assertIn
(
b'cos
\
n
statvfs_result
\
n
'
,
p
)
unpickled
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
result
,
unpickled
)
def
test_utime_dir
(
self
):
delta
=
1000000
...
...
Lib/test/test_random.py
View file @
65ee4674
...
...
@@ -159,11 +159,12 @@ class TestBasicOps:
self
.
assertEqual
(
y1
,
y2
)
def
test_pickling
(
self
):
state
=
pickle
.
dumps
(
self
.
gen
)
origseq
=
[
self
.
gen
.
random
()
for
i
in
range
(
10
)]
newgen
=
pickle
.
loads
(
state
)
restoredseq
=
[
newgen
.
random
()
for
i
in
range
(
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
range
(
10
)]
newgen
=
pickle
.
loads
(
state
)
restoredseq
=
[
newgen
.
random
()
for
i
in
range
(
10
)]
self
.
assertEqual
(
origseq
,
restoredseq
)
def
test_bug_1727780
(
self
):
# verify that version-2-pickles can be loaded
...
...
@@ -215,7 +216,8 @@ class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase):
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_range.py
View file @
65ee4674
...
...
@@ -366,7 +366,7 @@ class RangeTest(unittest.TestCase):
it
=
itorg
=
iter
(
range
(
*
t
))
data
=
list
(
range
(
*
t
))
d
=
pickle
.
dumps
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
list
(
it
),
data
)
...
...
@@ -376,33 +376,35 @@ class RangeTest(unittest.TestCase):
next
(
it
)
except
StopIteration
:
continue
d
=
pickle
.
dumps
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
it
),
data
[
1
:])
def
test_exhausted_iterator_pickling
(
self
):
r
=
range
(
2
**
65
,
2
**
65
+
2
)
i
=
iter
(
r
)
while
True
:
r
=
next
(
i
)
if
r
==
2
**
65
+
1
:
break
d
=
pickle
.
dumps
(
i
)
i2
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
i
),
[])
self
.
assertEqual
(
list
(
i2
),
[])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
r
=
range
(
2
**
65
,
2
**
65
+
2
)
i
=
iter
(
r
)
while
True
:
r
=
next
(
i
)
if
r
==
2
**
65
+
1
:
break
d
=
pickle
.
dumps
(
i
,
proto
)
i2
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
i
),
[])
self
.
assertEqual
(
list
(
i2
),
[])
def
test_large_exhausted_iterator_pickling
(
self
):
r
=
range
(
20
)
i
=
iter
(
r
)
while
True
:
r
=
next
(
i
)
if
r
==
19
:
break
d
=
pickle
.
dumps
(
i
)
i2
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
i
),
[])
self
.
assertEqual
(
list
(
i2
),
[])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
r
=
range
(
20
)
i
=
iter
(
r
)
while
True
:
r
=
next
(
i
)
if
r
==
19
:
break
d
=
pickle
.
dumps
(
i
,
proto
)
i2
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
list
(
i
),
[])
self
.
assertEqual
(
list
(
i2
),
[])
def
test_odd_bug
(
self
):
# This used to raise a "SystemError: NULL result without error"
...
...
Lib/test/test_set.py
View file @
65ee4674
...
...
@@ -231,29 +231,30 @@ class TestJointOps:
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
)
def
test_iterator_pickling
(
self
):
itorg
=
iter
(
self
.
s
)
data
=
self
.
thetype
(
self
.
s
)
d
=
pickle
.
dumps
(
itorg
)
it
=
pickle
.
loads
(
d
)
# Set iterators unpickle as list iterators due to the
# undefined order of set items.
# self.assertEqual(type(itorg), type(it))
self
.
assertTrue
(
isinstance
(
it
,
collections
.
abc
.
Iterator
))
self
.
assertEqual
(
self
.
thetype
(
it
),
data
)
it
=
pickle
.
loads
(
d
)
try
:
drop
=
next
(
it
)
except
StopIteration
:
return
d
=
pickle
.
dumps
(
it
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
self
.
thetype
(
it
),
data
-
self
.
thetype
((
drop
,)))
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
itorg
=
iter
(
self
.
s
)
data
=
self
.
thetype
(
self
.
s
)
d
=
pickle
.
dumps
(
itorg
,
proto
)
it
=
pickle
.
loads
(
d
)
# Set iterators unpickle as list iterators due to the
# undefined order of set items.
# self.assertEqual(type(itorg), type(it))
self
.
assertIsInstance
(
it
,
collections
.
abc
.
Iterator
)
self
.
assertEqual
(
self
.
thetype
(
it
),
data
)
it
=
pickle
.
loads
(
d
)
try
:
drop
=
next
(
it
)
except
StopIteration
:
continue
d
=
pickle
.
dumps
(
it
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
self
.
thetype
(
it
),
data
-
self
.
thetype
((
drop
,)))
def
test_deepcopy
(
self
):
class
Tracer
:
...
...
@@ -851,10 +852,11 @@ class TestBasicOps:
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_sndhdr.py
View file @
65ee4674
...
...
@@ -28,8 +28,9 @@ class TestFormats(unittest.TestCase):
def
test_pickleable
(
self
):
filename
=
findfile
(
'sndhdr.aifc'
,
subdir
=
"sndhdrdata"
)
what
=
sndhdr
.
what
(
filename
)
dump
=
pickle
.
dumps
(
what
)
self
.
assertEqual
(
pickle
.
loads
(
dump
),
what
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
dump
=
pickle
.
dumps
(
what
,
proto
)
self
.
assertEqual
(
pickle
.
loads
(
dump
),
what
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_tuple.py
View file @
65ee4674
...
...
@@ -174,29 +174,31 @@ class TupleTest(seq_tests.CommonTest):
# Userlist iterators don't support pickling yet since
# they are based on generators.
data
=
self
.
type2test
([
4
,
5
,
6
,
7
])
itorg
=
iter
(
data
)
d
=
pickle
.
dumps
(
itorg
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
data
))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
)
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
data
)[
1
:])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
itorg
=
iter
(
data
)
d
=
pickle
.
dumps
(
itorg
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
data
))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
data
)[
1
:])
def
test_reversed_pickle
(
self
):
data
=
self
.
type2test
([
4
,
5
,
6
,
7
])
itorg
=
reversed
(
data
)
d
=
pickle
.
dumps
(
itorg
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
reversed
(
data
)))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
)
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
reversed
(
data
))[
1
:])
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
itorg
=
reversed
(
data
)
d
=
pickle
.
dumps
(
itorg
,
proto
)
it
=
pickle
.
loads
(
d
)
self
.
assertEqual
(
type
(
itorg
),
type
(
it
))
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
reversed
(
data
)))
it
=
pickle
.
loads
(
d
)
next
(
it
)
d
=
pickle
.
dumps
(
it
,
proto
)
self
.
assertEqual
(
self
.
type2test
(
it
),
self
.
type2test
(
reversed
(
data
))[
1
:])
def
test_no_comdat_folding
(
self
):
# Issue 8847: In the PGO build, the MSVC linker's COMDAT folding
...
...
Lib/test/test_xml_dom_minicompat.py
View file @
65ee4674
...
...
@@ -84,18 +84,19 @@ class NodeListTestCase(unittest.TestCase):
def
test_nodelist_pickle_roundtrip
(
self
):
# Test pickling and unpickling of a NodeList.
# Empty NodeList.
node_list
=
NodeList
()
pickled
=
pickle
.
dumps
(
node_list
)
unpickled
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
unpickled
,
node_list
)
# Non-empty NodeList.
node_list
.
append
(
1
)
node_list
.
append
(
2
)
pickled
=
pickle
.
dumps
(
node_list
)
unpickled
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
unpickled
,
node_list
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
# Empty NodeList.
node_list
=
NodeList
()
pickled
=
pickle
.
dumps
(
node_list
,
proto
)
unpickled
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
unpickled
,
node_list
)
# Non-empty NodeList.
node_list
.
append
(
1
)
node_list
.
append
(
2
)
pickled
=
pickle
.
dumps
(
node_list
,
proto
)
unpickled
=
pickle
.
loads
(
pickled
)
self
.
assertEqual
(
unpickled
,
node_list
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Lib/test/test_xml_etree.py
View file @
65ee4674
...
...
@@ -121,11 +121,11 @@ class ElementTestCase:
def
setUpClass
(
cls
):
cls
.
modules
=
{
pyET
,
ET
}
def
pickleRoundTrip
(
self
,
obj
,
name
,
dumper
,
loader
):
def
pickleRoundTrip
(
self
,
obj
,
name
,
dumper
,
loader
,
proto
):
save_m
=
sys
.
modules
[
name
]
try
:
sys
.
modules
[
name
]
=
dumper
temp
=
pickle
.
dumps
(
obj
)
temp
=
pickle
.
dumps
(
obj
,
proto
)
sys
.
modules
[
name
]
=
loader
result
=
pickle
.
loads
(
temp
)
except
pickle
.
PicklingError
as
pe
:
...
...
@@ -1677,33 +1677,36 @@ class BasicElementTest(ElementTestCase, unittest.TestCase):
def
test_pickle
(
self
):
# issue #16076: the C implementation wasn't pickleable.
for
dumper
,
loader
in
product
(
self
.
modules
,
repeat
=
2
):
e
=
dumper
.
Element
(
'foo'
,
bar
=
42
)
e
.
text
=
"text goes here"
e
.
tail
=
"opposite of head"
dumper
.
SubElement
(
e
,
'child'
).
append
(
dumper
.
Element
(
'grandchild'
))
e
.
append
(
dumper
.
Element
(
'child'
))
e
.
findall
(
'.//grandchild'
)[
0
].
set
(
'attr'
,
'other value'
)
e2
=
self
.
pickleRoundTrip
(
e
,
'xml.etree.ElementTree'
,
dumper
,
loader
)
self
.
assertEqual
(
e2
.
tag
,
'foo'
)
self
.
assertEqual
(
e2
.
attrib
[
'bar'
],
42
)
self
.
assertEqual
(
len
(
e2
),
2
)
self
.
assertEqualElements
(
e
,
e2
)
for
proto
in
range
(
2
,
pickle
.
HIGHEST_PROTOCOL
+
1
):
for
dumper
,
loader
in
product
(
self
.
modules
,
repeat
=
2
):
e
=
dumper
.
Element
(
'foo'
,
bar
=
42
)
e
.
text
=
"text goes here"
e
.
tail
=
"opposite of head"
dumper
.
SubElement
(
e
,
'child'
).
append
(
dumper
.
Element
(
'grandchild'
))
e
.
append
(
dumper
.
Element
(
'child'
))
e
.
findall
(
'.//grandchild'
)[
0
].
set
(
'attr'
,
'other value'
)
e2
=
self
.
pickleRoundTrip
(
e
,
'xml.etree.ElementTree'
,
dumper
,
loader
,
proto
)
self
.
assertEqual
(
e2
.
tag
,
'foo'
)
self
.
assertEqual
(
e2
.
attrib
[
'bar'
],
42
)
self
.
assertEqual
(
len
(
e2
),
2
)
self
.
assertEqualElements
(
e
,
e2
)
def
test_pickle_issue18997
(
self
):
for
dumper
,
loader
in
product
(
self
.
modules
,
repeat
=
2
):
XMLTEXT
=
"""<?xml version="1.0"?>
<group><dogs>4</dogs>
</group>"""
e1
=
dumper
.
fromstring
(
XMLTEXT
)
if
hasattr
(
e1
,
'__getstate__'
):
self
.
assertEqual
(
e1
.
__getstate__
()[
'tag'
],
'group'
)
e2
=
self
.
pickleRoundTrip
(
e1
,
'xml.etree.ElementTree'
,
dumper
,
loader
)
self
.
assertEqual
(
e2
.
tag
,
'group'
)
self
.
assertEqual
(
e2
[
0
].
tag
,
'dogs'
)
for
proto
in
range
(
2
,
pickle
.
HIGHEST_PROTOCOL
+
1
):
for
dumper
,
loader
in
product
(
self
.
modules
,
repeat
=
2
):
XMLTEXT
=
"""<?xml version="1.0"?>
<group><dogs>4</dogs>
</group>"""
e1
=
dumper
.
fromstring
(
XMLTEXT
)
if
hasattr
(
e1
,
'__getstate__'
):
self
.
assertEqual
(
e1
.
__getstate__
()[
'tag'
],
'group'
)
e2
=
self
.
pickleRoundTrip
(
e1
,
'xml.etree.ElementTree'
,
dumper
,
loader
,
proto
)
self
.
assertEqual
(
e2
.
tag
,
'group'
)
self
.
assertEqual
(
e2
[
0
].
tag
,
'dogs'
)
class
ElementTreeTypeTest
(
unittest
.
TestCase
):
...
...
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