Kaydet (Commit) 4da5faae authored tarafından Raymond Hettinger's avatar Raymond Hettinger

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

üst 6da85f94
...@@ -422,7 +422,8 @@ class TestBasicOps(unittest.TestCase): ...@@ -422,7 +422,8 @@ class TestBasicOps(unittest.TestCase):
def run(r1, r2): def run(r1, r2):
result = [] result = []
for i, j in izip_longest(r1, r2, fillvalue=0): 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)) result.append((i, j))
return result return result
self.assertEqual(run(r1, r2), [(1,2), (1,2), (1,2), (0,2)]) self.assertEqual(run(r1, r2), [(1,2), (1,2), (1,2), (0,2)])
...@@ -431,8 +432,11 @@ class TestBasicOps(unittest.TestCase): ...@@ -431,8 +432,11 @@ class TestBasicOps(unittest.TestCase):
# and StopIteration would stop as expected # and StopIteration would stop as expected
r1 = Repeater(1, 3, RuntimeError) r1 = Repeater(1, 3, RuntimeError)
r2 = Repeater(2, 4, StopIteration) r2 = Repeater(2, 4, StopIteration)
mylist = lambda it: [v for v in it] it = izip_longest(r1, r2, fillvalue=0)
self.assertRaises(RuntimeError, mylist, 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): def test_product(self):
for args, result in [ for args, result in [
...@@ -723,7 +727,6 @@ class TestBasicOps(unittest.TestCase): ...@@ -723,7 +727,6 @@ class TestBasicOps(unittest.TestCase):
self.assertRaises(StopIteration, f(lambda x:x, []).next) self.assertRaises(StopIteration, f(lambda x:x, []).next)
self.assertRaises(StopIteration, f(lambda x:x, StopNow()).next) self.assertRaises(StopIteration, f(lambda x:x, StopNow()).next)
class TestExamples(unittest.TestCase): class TestExamples(unittest.TestCase):
def test_chain(self): def test_chain(self):
......
...@@ -3407,26 +3407,26 @@ izip_longest_next(iziplongestobject *lz) ...@@ -3407,26 +3407,26 @@ izip_longest_next(iziplongestobject *lz)
Py_INCREF(result); Py_INCREF(result);
for (i=0 ; i < tuplesize ; i++) { for (i=0 ; i < tuplesize ; i++) {
it = PyTuple_GET_ITEM(lz->ittuple, i); it = PyTuple_GET_ITEM(lz->ittuple, i);
if (it == NULL) { if (it == NULL) {
Py_INCREF(lz->fillvalue); Py_INCREF(lz->fillvalue);
item = 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 { } else {
assert(PyIter_Check(it)); Py_INCREF(lz->fillvalue);
item = PyIter_Next(it); item = lz->fillvalue;
if (item == NULL) { PyTuple_SET_ITEM(lz->ittuple, i, NULL);
lz->numactive -= 1; Py_DECREF(it);
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);
}
}
} }
}
}
olditem = PyTuple_GET_ITEM(result, i); olditem = PyTuple_GET_ITEM(result, i);
PyTuple_SET_ITEM(result, i, item); PyTuple_SET_ITEM(result, i, item);
Py_DECREF(olditem); Py_DECREF(olditem);
...@@ -3437,26 +3437,26 @@ izip_longest_next(iziplongestobject *lz) ...@@ -3437,26 +3437,26 @@ izip_longest_next(iziplongestobject *lz)
return NULL; return NULL;
for (i=0 ; i < tuplesize ; i++) { for (i=0 ; i < tuplesize ; i++) {
it = PyTuple_GET_ITEM(lz->ittuple, i); it = PyTuple_GET_ITEM(lz->ittuple, i);
if (it == NULL) { if (it == NULL) {
Py_INCREF(lz->fillvalue); Py_INCREF(lz->fillvalue);
item = lz->fillvalue; item = lz->fillvalue;
} else { } else {
assert(PyIter_Check(it)); assert(PyIter_Check(it));
item = PyIter_Next(it); item = PyIter_Next(it);
if (item == NULL) { if (item == NULL) {
lz->numactive -= 1; lz->numactive -= 1;
if (lz->numactive == 0 || PyErr_Occurred()) { if (lz->numactive == 0 || PyErr_Occurred()) {
lz->numactive = 0; lz->numactive = 0;
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} else { } else {
Py_INCREF(lz->fillvalue); Py_INCREF(lz->fillvalue);
item = lz->fillvalue; item = lz->fillvalue;
PyTuple_SET_ITEM(lz->ittuple, i, NULL); PyTuple_SET_ITEM(lz->ittuple, i, NULL);
Py_DECREF(it); Py_DECREF(it);
} }
} }
} }
PyTuple_SET_ITEM(result, i, item); PyTuple_SET_ITEM(result, i, item);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment