summaryrefslogtreecommitdiff
path: root/Lib/test/test_enumerate.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-10 10:10:42 +0000
committerRaymond Hettinger <python@rcn.com>2004-03-10 10:10:42 +0000
commit6c7797f7e8aa281ba99c2bfd2450a5f3d0ac7e2a (patch)
treeadbdfd32baf7294f005bc5c0d40acc47f0e8e04f /Lib/test/test_enumerate.py
parent984ebf985e9a9d9934b36b387b18de5c4383c634 (diff)
downloadcpython-6c7797f7e8aa281ba99c2bfd2450a5f3d0ac7e2a.tar.gz
Tidied up the implementations of reversed (including the custom ones
for xrange and list objects). * list.__reversed__ now checks the length of the sequence object before calling PyList_GET_ITEM() because the mutable could have changed length. * all three implementations are now tranparent with respect to length and maintain the invariant len(it) == len(list(it)) even when the underlying sequence mutates. * __builtin__.reversed() now frees the underlying sequence as soon as the iterator is exhausted. * the code paths were rearranged so that the most common paths do not require a jump.
Diffstat (limited to 'Lib/test/test_enumerate.py')
-rw-r--r--Lib/test/test_enumerate.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/test/test_enumerate.py b/Lib/test/test_enumerate.py
index 34bc71db24..200779fb98 100644
--- a/Lib/test/test_enumerate.py
+++ b/Lib/test/test_enumerate.py
@@ -143,8 +143,8 @@ class TestReversed(unittest.TestCase):
def test_len(self):
# This is an implementation detail, not an interface requirement
- s = 'hello'
- self.assertEqual(len(reversed(s)), len(s))
+ for s in ('hello', tuple('hello'), list('hello'), xrange(5)):
+ self.assertEqual(len(reversed(s)), len(s))
def test_main(verbose=None):
testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig,