diff options
author | Raymond Hettinger <python@rcn.com> | 2009-02-03 02:12:10 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-02-03 02:12:10 (GMT) |
commit | 5d65412d35231ffab837478f575fcd326bbcac80 (patch) | |
tree | 4aaf978cd805db3be557cf407e3c7297481d7f1a /Lib/test/test_iterlen.py | |
parent | 94a45da6be7a1c0ac255741576e7707649a57859 (diff) | |
download | cpython-5d65412d35231ffab837478f575fcd326bbcac80.zip cpython-5d65412d35231ffab837478f575fcd326bbcac80.tar.gz cpython-5d65412d35231ffab837478f575fcd326bbcac80.tar.bz2 |
Validate that __length_hint__ returns a usable result.
Diffstat (limited to 'Lib/test/test_iterlen.py')
-rw-r--r-- | Lib/test/test_iterlen.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_iterlen.py b/Lib/test/test_iterlen.py index 2123501..cd92801 100644 --- a/Lib/test/test_iterlen.py +++ b/Lib/test/test_iterlen.py @@ -208,6 +208,11 @@ class BadLengthHint(object): def __length_hint__(self): raise RuntimeError('hello') +class NoneLengthHint(object): + def __iter__(self): return iter(range(10)) + def __length_hint__(self): + return None + class TestLengthHintExceptions(unittest.TestCase): def test_issue1242657(self): @@ -219,6 +224,11 @@ class TestLengthHintExceptions(unittest.TestCase): self.assertRaises(RuntimeError, b.extend, BadLen()) self.assertRaises(RuntimeError, b.extend, BadLengthHint()) + def test_invalid_hint(self): + # Make sure an invalid result doesn't muck-up the works + self.assertEqual(list(NoneLengthHint()), list(range(10))) + + def test_main(): unittests = [ TestRepeat, |