summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-03-10 09:36:07 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-03-10 09:36:07 (GMT)
commit060c7f6bbafdaeb4b73ce34f1bb34e4ac76f2d92 (patch)
treed7472b2a0f931bda82734a36bb45858066560793 /Lib
parent2cf03a820483babd243a48de47865585fa697235 (diff)
downloadcpython-060c7f6bbafdaeb4b73ce34f1bb34e4ac76f2d92.zip
cpython-060c7f6bbafdaeb4b73ce34f1bb34e4ac76f2d92.tar.gz
cpython-060c7f6bbafdaeb4b73ce34f1bb34e4ac76f2d92.tar.bz2
Small optimization for corner case where maxlen==0.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_deque.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 5d975f6..a9e010e 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -51,7 +51,9 @@ class TestBasic(unittest.TestCase):
def test_maxlen(self):
self.assertRaises(ValueError, deque, 'abc', -1)
self.assertRaises(ValueError, deque, 'abc', -2)
- d = deque(range(10), maxlen=3)
+ it = iter(range(10))
+ d = deque(it, maxlen=3)
+ self.assertEqual(list(it), [])
self.assertEqual(repr(d), 'deque([7, 8, 9], maxlen=3)')
self.assertEqual(list(d), [7, 8, 9])
self.assertEqual(d, deque(range(10), 3))
@@ -88,6 +90,21 @@ class TestBasic(unittest.TestCase):
fo.close()
support.unlink(support.TESTFN)
+ def test_maxlen_zero(self):
+ it = iter(range(100))
+ deque(it, maxlen=0)
+ self.assertEqual(list(it), [])
+
+ it = iter(range(100))
+ d = deque(maxlen=0)
+ d.extend(it)
+ self.assertEqual(list(it), [])
+
+ it = iter(range(100))
+ d = deque(maxlen=0)
+ d.extendleft(it)
+ self.assertEqual(list(it), [])
+
def test_comparisons(self):
d = deque('xabc'); d.popleft()
for e in [d, deque('abc'), deque('ab'), deque(), list(d)]: