diff options
author | Raymond Hettinger <python@rcn.com> | 2009-02-02 22:55:09 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-02-02 22:55:09 (GMT) |
commit | e8364233aea88cf68e8f54a515dce10160ead35b (patch) | |
tree | bbe6369d9536d20602676c097b8c60ce8fa325a0 /Lib/test/test_iterlen.py | |
parent | 9f9892648f954e45a628113febb524261075db32 (diff) | |
download | cpython-e8364233aea88cf68e8f54a515dce10160ead35b.zip cpython-e8364233aea88cf68e8f54a515dce10160ead35b.tar.gz cpython-e8364233aea88cf68e8f54a515dce10160ead35b.tar.bz2 |
Issue 1242657: list(obj) can swallow KeyboardInterrupt.
Diffstat (limited to 'Lib/test/test_iterlen.py')
-rw-r--r-- | Lib/test/test_iterlen.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_iterlen.py b/Lib/test/test_iterlen.py index 72e92a5..2123501 100644 --- a/Lib/test/test_iterlen.py +++ b/Lib/test/test_iterlen.py @@ -195,6 +195,29 @@ class TestListReversed(TestInvariantWithoutMutations): d.extend(range(20)) self.assertEqual(len(it), 0) +## -- Check to make sure exceptions are not suppressed by __length_hint__() + + +class BadLen(object): + def __iter__(self): return iter(range(10)) + def __len__(self): + raise RuntimeError('hello') + +class BadLengthHint(object): + def __iter__(self): return iter(range(10)) + def __length_hint__(self): + raise RuntimeError('hello') + +class TestLengthHintExceptions(unittest.TestCase): + + def test_issue1242657(self): + self.assertRaises(RuntimeError, list, BadLen()) + self.assertRaises(RuntimeError, list, BadLengthHint()) + self.assertRaises(RuntimeError, [].extend, BadLen()) + self.assertRaises(RuntimeError, [].extend, BadLengthHint()) + b = bytearray(range(10)) + self.assertRaises(RuntimeError, b.extend, BadLen()) + self.assertRaises(RuntimeError, b.extend, BadLengthHint()) def test_main(): unittests = [ @@ -210,6 +233,7 @@ def test_main(): TestSet, TestList, TestListReversed, + TestLengthHintExceptions, ] support.run_unittest(*unittests) |