From 31d73e5c83374f8c4495fc05368996e62c66c621 2013-08-29 21:24:58 From: Min RK Date: 2013-08-29 21:24:58 Subject: [PATCH] Merge pull request #4088 from jdfreder/coalfix nbconvert: Fix coalescestreams line with incorrect nesting causing strange behavior closes #4015 --- diff --git a/IPython/nbconvert/preprocessors/coalescestreams.py b/IPython/nbconvert/preprocessors/coalescestreams.py index 5d906a8..f00c3cf 100644 --- a/IPython/nbconvert/preprocessors/coalescestreams.py +++ b/IPython/nbconvert/preprocessors/coalescestreams.py @@ -69,7 +69,7 @@ def coalesce_streams(cell, resources, index): last.text += output.text else: new_outputs.append(output) - last = output + last = output cell.outputs = new_outputs return cell, resources diff --git a/IPython/nbconvert/preprocessors/tests/test_coalescestreams.py b/IPython/nbconvert/preprocessors/tests/test_coalescestreams.py index ad476d8..fd9c14f 100644 --- a/IPython/nbconvert/preprocessors/tests/test_coalescestreams.py +++ b/IPython/nbconvert/preprocessors/tests/test_coalescestreams.py @@ -14,6 +14,8 @@ Module with tests for the coalescestreams preprocessor # Imports #----------------------------------------------------------------------------- +from IPython.nbformat import current as nbformat + from .base import PreprocessorTestsBase from ..coalescestreams import coalesce_streams @@ -35,4 +37,24 @@ class TestCoalesceStreams(PreprocessorTestsBase): self.assertEqual(outputs[1].output_type, "text") self.assertEqual(outputs[2].text, "cd") self.assertEqual(outputs[3].text, "ef") - + + + def test_coalesce_sequenced_streams(self): + """Can the coalesce streams preprocessor merge a sequence of streams?""" + + outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="0"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="1"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="2"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="3"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="4"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="5"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="6"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="7")] + cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)] + worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] + + nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets) + res = self.build_resources() + nb, res = coalesce_streams(nb, res) + outputs = nb.worksheets[0].cells[0].outputs + self.assertEqual(outputs[0].text, u'01234567')