##// END OF EJS Templates
Added test
Jonathan Frederic -
Show More
@@ -1,60 +1,72 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
17 16 from IPython.nbformat import current as nbformat
18 17
19 18 from .base import PreprocessorTestsBase
20 19 from ..coalescestreams import coalesce_streams
21 20
22 21
23 22 #-----------------------------------------------------------------------------
24 23 # Class
25 24 #-----------------------------------------------------------------------------
26
27 25 class TestCoalesceStreams(PreprocessorTestsBase):
28 26 """Contains test functions for coalescestreams.py"""
29 27
30 28 def test_coalesce_streams(self):
31 29 """coalesce_streams preprocessor output test"""
32 30 nb = self.build_notebook()
33 31 res = self.build_resources()
34 32 nb, res = coalesce_streams(nb, res)
35 33 outputs = nb.worksheets[0].cells[0].outputs
36 34 self.assertEqual(outputs[0].text, "a")
37 35 self.assertEqual(outputs[1].output_type, "text")
38 36 self.assertEqual(outputs[2].text, "cd")
39 37 self.assertEqual(outputs[3].text, "ef")
40 38
41
42 39 def test_coalesce_sequenced_streams(self):
43 40 """Can the coalesce streams preprocessor merge a sequence of streams?"""
44
45 41 outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="0"),
46 42 nbformat.new_output(output_type="stream", stream="stdout", output_text="1"),
47 43 nbformat.new_output(output_type="stream", stream="stdout", output_text="2"),
48 44 nbformat.new_output(output_type="stream", stream="stdout", output_text="3"),
49 45 nbformat.new_output(output_type="stream", stream="stdout", output_text="4"),
50 46 nbformat.new_output(output_type="stream", stream="stdout", output_text="5"),
51 47 nbformat.new_output(output_type="stream", stream="stdout", output_text="6"),
52 48 nbformat.new_output(output_type="stream", stream="stdout", output_text="7")]
53 49 cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)]
54 50 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
55 51
56 52 nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets)
57 53 res = self.build_resources()
58 54 nb, res = coalesce_streams(nb, res)
59 55 outputs = nb.worksheets[0].cells[0].outputs
60 56 self.assertEqual(outputs[0].text, u'01234567')
57
58 def test_coalesce_replace_streams(self):
59 """Are \\r characters handled?"""
60 outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="z"),
61 nbformat.new_output(output_type="stream", stream="stdout", output_text="\ra"),
62 nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz\rb"),
63 nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz"),
64 nbformat.new_output(output_type="stream", stream="stdout", output_text="\rc")]
65 cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)]
66 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
67
68 nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets)
69 res = self.build_resources()
70 nb, res = coalesce_streams(nb, res)
71 outputs = nb.worksheets[0].cells[0].outputs
72 self.assertEqual(outputs[0].text, u'a\nb\nc')
General Comments 0
You need to be logged in to leave comments. Login now