summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_enumerate.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-09-29 11:40:50 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-09-29 11:40:50 (GMT)
commitff5dc0ee7740feba895e7ddfbdda37d9064c045e (patch)
tree35e5c74f9dbc5a9eadca01bbf6d6e6c29431f648 /Lib/test/test_enumerate.py
parentbcab2b25f9bf4024ed10319cf65394d44aa9b023 (diff)
downloadcpython-ff5dc0ee7740feba895e7ddfbdda37d9064c045e.zip
cpython-ff5dc0ee7740feba895e7ddfbdda37d9064c045e.tar.gz
cpython-ff5dc0ee7740feba895e7ddfbdda37d9064c045e.tar.bz2
Improve test coverage.
Diffstat (limited to 'Lib/test/test_enumerate.py')
-rw-r--r--Lib/test/test_enumerate.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_enumerate.py b/Lib/test/test_enumerate.py
index 18c2bb9..0ed2b4c 100644
--- a/Lib/test/test_enumerate.py
+++ b/Lib/test/test_enumerate.py
@@ -145,6 +145,35 @@ class TestReversed(unittest.TestCase):
# This is an implementation detail, not an interface requirement
for s in ('hello', tuple('hello'), list('hello'), xrange(5)):
self.assertEqual(len(reversed(s)), len(s))
+ r = reversed(s)
+ list(r)
+ self.assertEqual(len(r), 0)
+ class SeqWithWeirdLen:
+ called = False
+ def __len__(self):
+ if not self.called:
+ self.called = True
+ return 10
+ raise ZeroDivisionError
+ def __getitem__(self, index):
+ return index
+ r = reversed(SeqWithWeirdLen())
+ self.assertRaises(ZeroDivisionError, len, r)
+
+
+ def test_gc(self):
+ class Seq:
+ def __len__(self):
+ return 10
+ def __getitem__(self, index):
+ return index
+ s = Seq()
+ r = reversed(s)
+ s.r = r
+
+ def test_args(self):
+ self.assertRaises(TypeError, reversed)
+ self.assertRaises(TypeError, reversed, [], 'extra')
def test_main(verbose=None):
testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig,