summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_itertools.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-04-29 10:13:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-04-29 10:13:46 (GMT)
commit3ec903fce4c8f8f97a74b15e8a5f5599da759bc9 (patch)
tree5a71da2c8e804cbaef051fc723dbc0e9967c09df /Lib/test/test_itertools.py
parentf3ae10e7ca9cf14299419c2c07678c7365e4b72e (diff)
downloadcpython-3ec903fce4c8f8f97a74b15e8a5f5599da759bc9.zip
cpython-3ec903fce4c8f8f97a74b15e8a5f5599da759bc9.tar.gz
cpython-3ec903fce4c8f8f97a74b15e8a5f5599da759bc9.tar.bz2
Issue #21321: itertools.islice() now releases the reference to the source iterator when the slice is exhausted.
Patch by Anton Afanasyev.
Diffstat (limited to 'Lib/test/test_itertools.py')
-rw-r--r--Lib/test/test_itertools.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 7233e7c..291aeb0 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -1,7 +1,7 @@
import unittest
from test import test_support
from itertools import *
-from weakref import proxy
+import weakref
from decimal import Decimal
from fractions import Fraction
import sys
@@ -792,6 +792,15 @@ class TestBasicOps(unittest.TestCase):
self.assertEqual(list(islice(c, 1, 3, 50)), [1])
self.assertEqual(next(c), 3)
+ # Issue #21321: check source iterator is not referenced
+ # from islice() after the latter has been exhausted
+ it = (x for x in (1, 2))
+ wr = weakref.ref(it)
+ it = islice(it, 1)
+ self.assertIsNotNone(wr())
+ list(it) # exhaust the iterator
+ self.assertIsNone(wr())
+
def test_takewhile(self):
data = [1, 3, 5, 20, 2, 4, 6, 8]
underten = lambda x: x<10
@@ -901,7 +910,7 @@ class TestBasicOps(unittest.TestCase):
# test that tee objects are weak referencable
a, b = tee(xrange(10))
- p = proxy(a)
+ p = weakref.proxy(a)
self.assertEqual(getattr(p, '__class__'), type(b))
del a
self.assertRaises(ReferenceError, getattr, p, '__class__')