Show More
@@ -1,72 +1,73 b'' | |||
|
1 | 1 | """ |
|
2 | 2 | Module with tests for the coalescestreams preprocessor |
|
3 | 3 | """ |
|
4 | 4 | |
|
5 | 5 | #----------------------------------------------------------------------------- |
|
6 | 6 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | 7 | # |
|
8 | 8 | # Distributed under the terms of the Modified BSD License. |
|
9 | 9 | # |
|
10 | 10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | 11 | #----------------------------------------------------------------------------- |
|
12 | 12 | |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | from IPython.nbformat import current as nbformat |
|
17 | 17 | |
|
18 | 18 | from .base import PreprocessorTestsBase |
|
19 | 19 | from ..coalescestreams import coalesce_streams |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | #----------------------------------------------------------------------------- |
|
23 | 23 | # Class |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | class TestCoalesceStreams(PreprocessorTestsBase): |
|
26 | 26 | """Contains test functions for coalescestreams.py""" |
|
27 | 27 | |
|
28 | 28 | def test_coalesce_streams(self): |
|
29 | 29 | """coalesce_streams preprocessor output test""" |
|
30 | 30 | nb = self.build_notebook() |
|
31 | 31 | res = self.build_resources() |
|
32 | 32 | nb, res = coalesce_streams(nb, res) |
|
33 | 33 | outputs = nb.worksheets[0].cells[0].outputs |
|
34 | 34 | self.assertEqual(outputs[0].text, "a") |
|
35 | 35 | self.assertEqual(outputs[1].output_type, "text") |
|
36 | 36 | self.assertEqual(outputs[2].text, "cd") |
|
37 | 37 | self.assertEqual(outputs[3].text, "ef") |
|
38 | 38 | |
|
39 | 39 | def test_coalesce_sequenced_streams(self): |
|
40 | 40 | """Can the coalesce streams preprocessor merge a sequence of streams?""" |
|
41 | 41 | outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="0"), |
|
42 | 42 | nbformat.new_output(output_type="stream", stream="stdout", output_text="1"), |
|
43 | 43 | nbformat.new_output(output_type="stream", stream="stdout", output_text="2"), |
|
44 | 44 | nbformat.new_output(output_type="stream", stream="stdout", output_text="3"), |
|
45 | 45 | nbformat.new_output(output_type="stream", stream="stdout", output_text="4"), |
|
46 | 46 | nbformat.new_output(output_type="stream", stream="stdout", output_text="5"), |
|
47 | 47 | nbformat.new_output(output_type="stream", stream="stdout", output_text="6"), |
|
48 | 48 | nbformat.new_output(output_type="stream", stream="stdout", output_text="7")] |
|
49 | 49 | cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)] |
|
50 | 50 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] |
|
51 | 51 | |
|
52 | 52 | nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets) |
|
53 | 53 | res = self.build_resources() |
|
54 | 54 | nb, res = coalesce_streams(nb, res) |
|
55 | 55 | outputs = nb.worksheets[0].cells[0].outputs |
|
56 | 56 | self.assertEqual(outputs[0].text, u'01234567') |
|
57 | 57 | |
|
58 | 58 | def test_coalesce_replace_streams(self): |
|
59 | 59 | """Are \\r characters handled?""" |
|
60 | 60 | outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="z"), |
|
61 | 61 | nbformat.new_output(output_type="stream", stream="stdout", output_text="\ra"), |
|
62 | 62 | nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz\rb"), |
|
63 | 63 | nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz"), |
|
64 |
nbformat.new_output(output_type="stream", stream="stdout", output_text="\rc") |
|
|
64 | nbformat.new_output(output_type="stream", stream="stdout", output_text="\rc\n"), | |
|
65 | nbformat.new_output(output_type="stream", stream="stdout", output_text="z\rz\rd")] | |
|
65 | 66 | cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)] |
|
66 | 67 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] |
|
67 | 68 | |
|
68 | 69 | nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets) |
|
69 | 70 | res = self.build_resources() |
|
70 | 71 | nb, res = coalesce_streams(nb, res) |
|
71 | 72 | outputs = nb.worksheets[0].cells[0].outputs |
|
72 | self.assertEqual(outputs[0].text, u'a\nb\nc') | |
|
73 | self.assertEqual(outputs[0].text, u'a\nb\nc\nd') |
General Comments 0
You need to be logged in to leave comments.
Login now