summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-05-08 19:49:42 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-05-08 19:49:42 (GMT)
commit9d7c870c6d66c8b2e066001f31ac3037d50f7012 (patch)
treec41da1755bdc2af527581c02cf2fd2ed9781ac38 /Lib
parentffa5a5015a359045d7efb2c4cd0b5738c97b86ce (diff)
downloadcpython-9d7c870c6d66c8b2e066001f31ac3037d50f7012.zip
cpython-9d7c870c6d66c8b2e066001f31ac3037d50f7012.tar.gz
cpython-9d7c870c6d66c8b2e066001f31ac3037d50f7012.tar.bz2
SF #950057: itertools.chain doesn't "process" exceptions as they occur
Both cycle() and chain() were handling exceptions only when switching input sources. The patch makes the handle more immediate. Will backport.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_itertools.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 73e8809..54e46e1 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -644,6 +644,36 @@ class RegressionTests(unittest.TestCase):
self.assertEqual(first, second)
+ def test_sf_950057(self):
+ # Make sure that chain() and cycle() catch exceptions immediately
+ # rather than when shifting between input sources
+
+ def gen1():
+ hist.append(0)
+ yield 1
+ hist.append(1)
+ assert False
+ hist.append(2)
+
+ def gen2(x):
+ hist.append(3)
+ yield 2
+ hist.append(4)
+ if x:
+ raise StopIteration
+
+ hist = []
+ self.assertRaises(AssertionError, list, chain(gen1(), gen2(False)))
+ self.assertEqual(hist, [0,1])
+
+ hist = []
+ self.assertRaises(AssertionError, list, chain(gen1(), gen2(True)))
+ self.assertEqual(hist, [0,1])
+
+ hist = []
+ self.assertRaises(AssertionError, list, cycle(gen1()))
+ self.assertEqual(hist, [0,1])
+
libreftest = """ Doctest for examples in the library reference: libitertools.tex