diff options
| author | Raymond Hettinger <python@rcn.com> | 2009-02-02 22:44:06 (GMT) |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2009-02-02 22:44:06 (GMT) |
| commit | 24e2872f0d04c0d7c1745f677aef1a335433b556 (patch) | |
| tree | d11c883d601cda87a46839fbc6ba321089c6cb61 /Lib/test/test_iterlen.py | |
| parent | b2dbd4309aa3d2a8a823d251447b8fd8b4b2d7e3 (diff) | |
| download | cpython-24e2872f0d04c0d7c1745f677aef1a335433b556.zip cpython-24e2872f0d04c0d7c1745f677aef1a335433b556.tar.gz cpython-24e2872f0d04c0d7c1745f677aef1a335433b556.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 | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_iterlen.py b/Lib/test/test_iterlen.py index 2a32512..91873c2 100644 --- a/Lib/test/test_iterlen.py +++ b/Lib/test/test_iterlen.py @@ -195,6 +195,36 @@ class TestListReversed(TestInvariantWithoutMutations): d.extend(xrange(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()) + self.assertRaises(RuntimeError, zip, BadLen()) + self.assertRaises(RuntimeError, zip, BadLengthHint()) + self.assertRaises(RuntimeError, filter, None, BadLen()) + self.assertRaises(RuntimeError, filter, None, BadLengthHint()) + self.assertRaises(RuntimeError, map, chr, BadLen()) + self.assertRaises(RuntimeError, map, chr, BadLengthHint()) + b = bytearray(range(10)) + self.assertRaises(RuntimeError, b.extend, BadLen()) + self.assertRaises(RuntimeError, b.extend, BadLengthHint()) + def test_main(): unittests = [ TestRepeat, @@ -209,6 +239,7 @@ def test_main(): TestSet, TestList, TestListReversed, + TestLengthHintExceptions, ] test_support.run_unittest(*unittests) |
