summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-11-06 14:06:48 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-11-06 14:06:48 (GMT)
commit85c20a41dfcec04d161ad7da7260e7b94c62d228 (patch)
tree0d9e5b294ab4890b72ddc61d193036ac1d4b5ca4 /Lib/test
parentf607fc5395883ff924c76739e9b0921953568e54 (diff)
downloadcpython-85c20a41dfcec04d161ad7da7260e7b94c62d228.zip
cpython-85c20a41dfcec04d161ad7da7260e7b94c62d228.tar.gz
cpython-85c20a41dfcec04d161ad7da7260e7b94c62d228.tar.bz2
Implement and apply PEP 322, reverse iteration
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_enumerate.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_enumerate.py b/Lib/test/test_enumerate.py
index 88e24e8..b073606 100644
--- a/Lib/test/test_enumerate.py
+++ b/Lib/test/test_enumerate.py
@@ -124,9 +124,27 @@ class TestBig(EnumerateTestCase):
seq = range(10,20000,2)
res = zip(range(20000), seq)
+class TestReversed(unittest.TestCase):
+
+ def test_simple(self):
+ class A:
+ def __getitem__(self, i):
+ if i < 5:
+ return str(i)
+ raise StopIteration
+ def __len__(self):
+ return 5
+ for data in 'abc', range(5), tuple(enumerate('abc')), A(), xrange(1,17,5):
+ self.assertEqual(list(data)[::-1], list(reversed(data)))
+ self.assertRaises(TypeError, reversed, {})
+
+ def test_xrange_optimization(self):
+ x = xrange(1)
+ self.assertEqual(type(reversed(x)), type(iter(x)))
def test_main(verbose=None):
- testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig)
+ testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig,
+ TestReversed)
test_support.run_unittest(*testclasses)
# verify reference counting