test_coalescestreams.py
60 lines
| 3.2 KiB
| text/x-python
|
PythonLexer
MinRK
|
r18244 | """Tests for the coalescestreams preprocessor""" | ||
Jonathan Frederic
|
r12021 | |||
MinRK
|
r18244 | # Copyright (c) IPython Development Team. | ||
Jonathan Frederic
|
r12021 | # Distributed under the terms of the Modified BSD License. | ||
Jonathan Frederic
|
r12296 | from IPython.nbformat import current as nbformat | ||
Paul Ivanov
|
r12219 | from .base import PreprocessorTestsBase | ||
Jonathan Frederic
|
r12021 | from ..coalescestreams import coalesce_streams | ||
Paul Ivanov
|
r12219 | class TestCoalesceStreams(PreprocessorTestsBase): | ||
Jonathan Frederic
|
r12021 | """Contains test functions for coalescestreams.py""" | ||
def test_coalesce_streams(self): | ||||
Paul Ivanov
|
r12219 | """coalesce_streams preprocessor output test""" | ||
Jonathan Frederic
|
r12039 | nb = self.build_notebook() | ||
res = self.build_resources() | ||||
nb, res = coalesce_streams(nb, res) | ||||
Jonathan Frederic
|
r12035 | outputs = nb.worksheets[0].cells[0].outputs | ||
self.assertEqual(outputs[0].text, "a") | ||||
self.assertEqual(outputs[1].output_type, "text") | ||||
self.assertEqual(outputs[2].text, "cd") | ||||
self.assertEqual(outputs[3].text, "ef") | ||||
Jonathan Frederic
|
r12296 | |||
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)] | ||||
MinRK
|
r18244 | worksheets = [nbformat.new_worksheet(cells=cells)] | ||
Jonathan Frederic
|
r12296 | |||
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') | ||||
Jonathan Frederic
|
r15867 | |||
def test_coalesce_replace_streams(self): | ||||
"""Are \\r characters handled?""" | ||||
outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="z"), | ||||
nbformat.new_output(output_type="stream", stream="stdout", output_text="\ra"), | ||||
nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz\rb"), | ||||
nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz"), | ||||
Jonathan Frederic
|
r15870 | nbformat.new_output(output_type="stream", stream="stdout", output_text="\rc\n"), | ||
nbformat.new_output(output_type="stream", stream="stdout", output_text="z\rz\rd")] | ||||
Jonathan Frederic
|
r15867 | cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)] | ||
MinRK
|
r18244 | worksheets = [nbformat.new_worksheet(cells=cells)] | ||
Jonathan Frederic
|
r15867 | |||
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 | ||||
Jonathan Frederic
|
r15870 | self.assertEqual(outputs[0].text, u'a\nb\nc\nd') | ||