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
aabafe7b
Commit
aabafe7b
authored
Mar 06, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26015: Added new tests for pickling iterators of mutable sequences.
parent
d5516251
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
216 additions
and
50 deletions
+216
-50
Lib/test/test_array.py
Lib/test/test_array.py
+35
-12
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+39
-3
Lib/test/test_deque.py
Lib/test/test_deque.py
+38
-11
Lib/test/test_iter.py
Lib/test/test_iter.py
+36
-0
Lib/test/test_list.py
Lib/test/test_list.py
+66
-24
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_array.py
View file @
aabafe7b
...
...
@@ -284,19 +284,42 @@ class BaseTest:
self
.
assertEqual
(
type
(
a
),
type
(
b
))
def
test_iterator_pickle
(
self
):
data
=
array
.
array
(
self
.
typecode
,
self
.
example
)
orig
=
array
.
array
(
self
.
typecode
,
self
.
example
)
data
=
list
(
orig
)
data2
=
data
[::
-
1
]
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
orgit
=
iter
(
data
)
d
=
pickle
.
dumps
(
orgit
,
proto
)
it
=
pickle
.
loads
(
d
)
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
:])
# initial iterator
itorig
=
iter
(
orig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
.
fromlist
(
data2
)
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data
+
data2
)
# running iterator
next
(
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
.
fromlist
(
data2
)
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data
[
1
:]
+
data2
)
# empty iterator
for
i
in
range
(
1
,
len
(
data
)):
next
(
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
.
fromlist
(
data2
)
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data2
)
# exhausted iterator
self
.
assertRaises
(
StopIteration
,
next
,
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
.
fromlist
(
data2
)
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data2
)
def
test_insert
(
self
):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
...
...
Lib/test/test_bytes.py
View file @
aabafe7b
...
...
@@ -595,10 +595,9 @@ class BaseBytesTest:
self.assertEqual(list(it), data)
it = pickle.loads(d)
try:
next(it)
except StopIteration:
if not b:
continue
next(it)
d = pickle.dumps(it, proto)
it = pickle.loads(d)
self.assertEqual(list(it), data[1:])
...
...
@@ -1284,6 +1283,43 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
from _testcapi import getbuffer_with_null_view
self.assertRaises(BufferError, getbuffer_with_null_view, bytearray())
def test_iterator_pickling2(self):
orig = bytearray(b'abc')
data = list(b'qwerty')
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
# initial iterator
itorig = iter(orig)
d = pickle.dumps((itorig, orig), proto)
it, b = pickle.loads(d)
b[:] = data
self.assertEqual(type(it), type(itorig))
self.assertEqual(list(it), data)
# running iterator
next(itorig)
d = pickle.dumps((itorig, orig), proto)
it, b = pickle.loads(d)
b[:] = data
self.assertEqual(type(it), type(itorig))
self.assertEqual(list(it), data[1:])
# empty iterator
for i in range(1, len(orig)):
next(itorig)
d = pickle.dumps((itorig, orig), proto)
it, b = pickle.loads(d)
b[:] = data
self.assertEqual(type(it), type(itorig))
self.assertEqual(list(it), data[len(orig):])
# exhausted iterator
self.assertRaises(StopIteration, next, itorig)
d = pickle.dumps((itorig, orig), proto)
it, b = pickle.loads(d)
b[:] = data
self.assertEqual(list(it), [])
class AssortedBytesTest(unittest.TestCase):
#
# Test various combinations of bytes and bytearray
...
...
Lib/test/test_deque.py
View file @
aabafe7b
...
...
@@ -638,18 +638,45 @@ class TestBasic(unittest.TestCase):
## self.assertEqual(id(e), id(e[-1]))
def
test_iterator_pickle
(
self
):
data
=
deque
(
range
(
200
))
orig
=
deque
(
range
(
200
))
data
=
[
i
*
1.01
for
i
in
orig
]
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
:])
# initial iterator
itorg
=
iter
(
orig
)
dump
=
pickle
.
dumps
((
itorg
,
orig
),
proto
)
it
,
d
=
pickle
.
loads
(
dump
)
for
i
,
x
in
enumerate
(
data
):
d
[
i
]
=
x
self
.
assertEqual
(
type
(
it
),
type
(
itorg
))
self
.
assertEqual
(
list
(
it
),
data
)
# running iterator
next
(
itorg
)
dump
=
pickle
.
dumps
((
itorg
,
orig
),
proto
)
it
,
d
=
pickle
.
loads
(
dump
)
for
i
,
x
in
enumerate
(
data
):
d
[
i
]
=
x
self
.
assertEqual
(
type
(
it
),
type
(
itorg
))
self
.
assertEqual
(
list
(
it
),
data
[
1
:])
# empty iterator
for
i
in
range
(
1
,
len
(
data
)):
next
(
itorg
)
dump
=
pickle
.
dumps
((
itorg
,
orig
),
proto
)
it
,
d
=
pickle
.
loads
(
dump
)
for
i
,
x
in
enumerate
(
data
):
d
[
i
]
=
x
self
.
assertEqual
(
type
(
it
),
type
(
itorg
))
self
.
assertEqual
(
list
(
it
),
[])
# exhausted iterator
self
.
assertRaises
(
StopIteration
,
next
,
itorg
)
dump
=
pickle
.
dumps
((
itorg
,
orig
),
proto
)
it
,
d
=
pickle
.
loads
(
dump
)
for
i
,
x
in
enumerate
(
data
):
d
[
i
]
=
x
self
.
assertEqual
(
type
(
it
),
type
(
itorg
))
self
.
assertEqual
(
list
(
it
),
[])
def
test_deepcopy
(
self
):
mut
=
[
10
]
...
...
Lib/test/test_iter.py
View file @
aabafe7b
...
...
@@ -153,6 +153,42 @@ class TestCase(unittest.TestCase):
def
test_seq_class_iter
(
self
):
self
.
check_iterator
(
iter
(
SequenceClass
(
10
)),
list
(
range
(
10
)))
def
test_mutating_seq_class_iter_pickle
(
self
):
orig
=
SequenceClass
(
5
)
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
# initial iterator
itorig
=
iter
(
orig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
seq
=
pickle
.
loads
(
d
)
seq
.
n
=
7
self
.
assertIs
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
list
(
range
(
7
)))
# running iterator
next
(
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
seq
=
pickle
.
loads
(
d
)
seq
.
n
=
7
self
.
assertIs
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
list
(
range
(
1
,
7
)))
# empty iterator
for
i
in
range
(
1
,
5
):
next
(
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
seq
=
pickle
.
loads
(
d
)
seq
.
n
=
7
self
.
assertIs
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
list
(
range
(
5
,
7
)))
# exhausted iterator
self
.
assertRaises
(
StopIteration
,
next
,
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
seq
=
pickle
.
loads
(
d
)
seq
.
n
=
7
self
.
assertTrue
(
isinstance
(
it
,
collections
.
abc
.
Iterator
))
self
.
assertEqual
(
list
(
it
),
[])
# Test a new_style class with __iter__ but no next() method
def
test_new_style_iter_class
(
self
):
class
IterClass
(
object
):
...
...
Lib/test/test_list.py
View file @
aabafe7b
...
...
@@ -72,34 +72,76 @@ class ListTest(list_tests.CommonTest):
check
(
1000000
)
def
test_iterator_pickle
(
self
):
# Userlist iterators don't support pickling yet since
# they are based on generators.
data
=
self
.
type2test
([
4
,
5
,
6
,
7
])
orig
=
self
.
type2test
([
4
,
5
,
6
,
7
])
data
=
[
10
,
11
,
12
,
13
,
14
,
15
]
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
:])
# initial iterator
itorig
=
iter
(
orig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
[:]
=
data
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data
)
# running iterator
next
(
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
[:]
=
data
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data
[
1
:])
# empty iterator
for
i
in
range
(
1
,
len
(
orig
)):
next
(
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
[:]
=
data
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data
[
len
(
orig
):])
# exhausted iterator
self
.
assertRaises
(
StopIteration
,
next
,
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
[:]
=
data
self
.
assertEqual
(
list
(
it
),
[])
def
test_reversed_pickle
(
self
):
data
=
self
.
type2test
([
4
,
5
,
6
,
7
])
orig
=
self
.
type2test
([
4
,
5
,
6
,
7
])
data
=
[
10
,
11
,
12
,
13
,
14
,
15
]
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
:])
# initial iterator
itorig
=
reversed
(
orig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
[:]
=
data
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data
[
len
(
orig
)
-
1
::
-
1
])
# running iterator
next
(
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
[:]
=
data
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
data
[
len
(
orig
)
-
2
::
-
1
])
# empty iterator
for
i
in
range
(
1
,
len
(
orig
)):
next
(
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
[:]
=
data
self
.
assertEqual
(
type
(
it
),
type
(
itorig
))
self
.
assertEqual
(
list
(
it
),
[])
# exhausted iterator
self
.
assertRaises
(
StopIteration
,
next
,
itorig
)
d
=
pickle
.
dumps
((
itorig
,
orig
),
proto
)
it
,
a
=
pickle
.
loads
(
d
)
a
[:]
=
data
self
.
assertEqual
(
list
(
it
),
[])
def
test_no_comdat_folding
(
self
):
# Issue 8847: In the PGO build, the MSVC linker's COMDAT folding
...
...
Misc/NEWS
View file @
aabafe7b
...
...
@@ -274,6 +274,8 @@ Documentation
Tests
-----
-
Issue
#
26015
:
Added
new
tests
for
pickling
iterators
of
mutable
sequences
.
-
Issue
#
26325
:
Added
test
.
support
.
check_no_resource_warning
()
to
check
that
no
ResourceWarning
is
emitted
.
...
...
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