[Python-checkins] python/dist/src/Lib/test test_itertools.py, 1.15.6.4, 1.15.6.5

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sat May 8 15:52:42 EDT 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3285/Lib/test

Modified Files:
      Tag: release23-maint
	test_itertools.py 
Log Message:
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.



Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_itertools.py,v
retrieving revision 1.15.6.4
retrieving revision 1.15.6.5
diff -C2 -d -r1.15.6.4 -r1.15.6.5
*** test_itertools.py	5 Oct 2003 23:05:55 -0000	1.15.6.4
--- test_itertools.py	8 May 2004 19:52:39 -0000	1.15.6.5
***************
*** 459,462 ****
--- 459,492 ----
  
  
+     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
  




More information about the Python-checkins mailing list