[Python-checkins] r76018 - in python/branches/release26-maint: Lib/test/test_itertools.py Modules/itertoolsmodule.c

raymond.hettinger python-checkins at python.org
Sun Nov 1 19:43:32 CET 2009


Author: raymond.hettinger
Date: Sun Nov  1 19:43:31 2009
New Revision: 76018

Log:
Issue 7244:  Fix indentation in C code.  Fix test to not sent output to stdout.

Modified:
   python/branches/release26-maint/Lib/test/test_itertools.py
   python/branches/release26-maint/Modules/itertoolsmodule.c

Modified: python/branches/release26-maint/Lib/test/test_itertools.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_itertools.py	(original)
+++ python/branches/release26-maint/Lib/test/test_itertools.py	Sun Nov  1 19:43:31 2009
@@ -422,7 +422,8 @@
         def run(r1, r2):
             result = []
             for i, j in izip_longest(r1, r2, fillvalue=0):
-                print(i, j)
+                with test_support.captured_output('stdout'):
+                    print (i, j)
                 result.append((i, j))
             return result
         self.assertEqual(run(r1, r2), [(1,2), (1,2), (1,2), (0,2)])
@@ -431,8 +432,11 @@
         # and StopIteration would stop as expected
         r1 = Repeater(1, 3, RuntimeError)
         r2 = Repeater(2, 4, StopIteration)
-        mylist = lambda it: [v for v in it]
-        self.assertRaises(RuntimeError, mylist, izip_longest(r1, r2, fillvalue=0))
+        it = izip_longest(r1, r2, fillvalue=0)
+        self.assertEqual(next(it), (1, 2))
+        self.assertEqual(next(it), (1, 2))
+        self.assertEqual(next(it), (1, 2))
+        self.assertRaises(RuntimeError, next, it)
 
     def test_product(self):
         for args, result in [
@@ -723,7 +727,6 @@
             self.assertRaises(StopIteration, f(lambda x:x, []).next)
             self.assertRaises(StopIteration, f(lambda x:x, StopNow()).next)
 
-
 class TestExamples(unittest.TestCase):
 
     def test_chain(self):

Modified: python/branches/release26-maint/Modules/itertoolsmodule.c
==============================================================================
--- python/branches/release26-maint/Modules/itertoolsmodule.c	(original)
+++ python/branches/release26-maint/Modules/itertoolsmodule.c	Sun Nov  1 19:43:31 2009
@@ -3407,26 +3407,26 @@
 		Py_INCREF(result);
 		for (i=0 ; i < tuplesize ; i++) {
 			it = PyTuple_GET_ITEM(lz->ittuple, i);
-                        if (it == NULL) {
-                                Py_INCREF(lz->fillvalue);
-                                item = lz->fillvalue;
+            if (it == NULL) {
+                Py_INCREF(lz->fillvalue);
+                item = lz->fillvalue;
+            } else {
+                assert(PyIter_Check(it));
+                item = PyIter_Next(it);
+                if (item == NULL) {
+                    lz->numactive -= 1;
+                    if (lz->numactive == 0 || PyErr_Occurred()) {
+							lz->numactive = 0;
+                            Py_DECREF(result);
+                            return NULL;
                         } else {
-                                assert(PyIter_Check(it));
-                                item = PyIter_Next(it);
-                                if (item == NULL) {
-                                        lz->numactive -= 1;
-                                        if (lz->numactive == 0 || PyErr_Occurred()) {
-												lz->numactive = 0;
-                                                Py_DECREF(result);
-                                                return NULL;
-                                        } else {
-                                                Py_INCREF(lz->fillvalue);
-                                                item = lz->fillvalue;                                        
-                                                PyTuple_SET_ITEM(lz->ittuple, i, NULL);
-                                                Py_DECREF(it);
-                                        }
-                                }
+                            Py_INCREF(lz->fillvalue);
+                            item = lz->fillvalue;                                        
+                            PyTuple_SET_ITEM(lz->ittuple, i, NULL);
+                            Py_DECREF(it);
                         }
+                }
+            }
 			olditem = PyTuple_GET_ITEM(result, i);
 			PyTuple_SET_ITEM(result, i, item);
 			Py_DECREF(olditem);
@@ -3437,26 +3437,26 @@
 			return NULL;
 		for (i=0 ; i < tuplesize ; i++) {
 			it = PyTuple_GET_ITEM(lz->ittuple, i);
-                        if (it == NULL) {
-                                Py_INCREF(lz->fillvalue);
-                                item = lz->fillvalue;
-                        } else {
-                                assert(PyIter_Check(it));
-                                item = PyIter_Next(it);
-                                if (item == NULL) {
-                                        lz->numactive -= 1;      
-                                        if (lz->numactive == 0 || PyErr_Occurred()) {
-												lz->numactive = 0;
-                                                Py_DECREF(result);
-                                                return NULL;
-                                        } else {
-                                                Py_INCREF(lz->fillvalue);
-                                                item = lz->fillvalue;                                        
-                                                PyTuple_SET_ITEM(lz->ittuple, i, NULL);
-                                                Py_DECREF(it);
-                                        }
-                                }
-                        }
+            if (it == NULL) {
+                Py_INCREF(lz->fillvalue);
+                item = lz->fillvalue;
+            } else {
+                assert(PyIter_Check(it));
+                item = PyIter_Next(it);
+                if (item == NULL) {
+                    lz->numactive -= 1;
+                    if (lz->numactive == 0 || PyErr_Occurred()) {
+						lz->numactive = 0;
+                        Py_DECREF(result);
+                        return NULL;
+                    } else {
+                        Py_INCREF(lz->fillvalue);
+                        item = lz->fillvalue;                                        
+                        PyTuple_SET_ITEM(lz->ittuple, i, NULL);
+                        Py_DECREF(it);
+                    }
+                }
+            }
 			PyTuple_SET_ITEM(result, i, item);
 		}
 	}


More information about the Python-checkins mailing list