##// END OF EJS Templates
update test_extract_output
MinRK -
Show More
@@ -1,53 +1,53 b''
1 """
1 """
2 Module with utility functions for preprocessor tests
2 Module with utility functions for preprocessor tests
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 from IPython.nbformat import current as nbformat
17 from IPython.nbformat import current as nbformat
18
18
19 from ...tests.base import TestsBase
19 from ...tests.base import TestsBase
20 from ...exporters.exporter import ResourcesDict
20 from ...exporters.exporter import ResourcesDict
21
21
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 # Class
23 # Class
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25
25
26 class PreprocessorTestsBase(TestsBase):
26 class PreprocessorTestsBase(TestsBase):
27 """Contains test functions preprocessor tests"""
27 """Contains test functions preprocessor tests"""
28
28
29
29
30 def build_notebook(self):
30 def build_notebook(self):
31 """Build a notebook in memory for use with preprocessor tests"""
31 """Build a notebook in memory for use with preprocessor tests"""
32
32
33 outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a"),
33 outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a"),
34 nbformat.new_output(output_type="text", output_text="b"),
34 nbformat.new_output(output_type="text", output_text="b"),
35 nbformat.new_output(output_type="stream", stream="stdout", output_text="c"),
35 nbformat.new_output(output_type="stream", stream="stdout", output_text="c"),
36 nbformat.new_output(output_type="stream", stream="stdout", output_text="d"),
36 nbformat.new_output(output_type="stream", stream="stdout", output_text="d"),
37 nbformat.new_output(output_type="stream", stream="stderr", output_text="e"),
37 nbformat.new_output(output_type="stream", stream="stderr", output_text="e"),
38 nbformat.new_output(output_type="stream", stream="stderr", output_text="f"),
38 nbformat.new_output(output_type="stream", stream="stderr", output_text="f"),
39 nbformat.new_output(output_type="png", output_png=b'Zw==')] #g
39 nbformat.new_output(output_type="png", output_png='Zw==')] #g
40
40
41 cells=[nbformat.new_code_cell(input="$ e $", prompt_number=1,outputs=outputs),
41 cells=[nbformat.new_code_cell(input="$ e $", prompt_number=1,outputs=outputs),
42 nbformat.new_text_cell('markdown', source="$ e $")]
42 nbformat.new_text_cell('markdown', source="$ e $")]
43 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
43 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
44
44
45 return nbformat.new_notebook(name="notebook1", worksheets=worksheets)
45 return nbformat.new_notebook(name="notebook1", worksheets=worksheets)
46
46
47
47
48 def build_resources(self):
48 def build_resources(self):
49 """Build an empty resources dictionary."""
49 """Build an empty resources dictionary."""
50
50
51 res = ResourcesDict()
51 res = ResourcesDict()
52 res['metadata'] = ResourcesDict()
52 res['metadata'] = ResourcesDict()
53 return res
53 return res
@@ -1,62 +1,64 b''
1 """
1 """
2 Module with tests for the extractoutput preprocessor
2 Module with tests for the extractoutput preprocessor
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 from .base import PreprocessorTestsBase
17 from .base import PreprocessorTestsBase
18 from ..extractoutput import ExtractOutputPreprocessor
18 from ..extractoutput import ExtractOutputPreprocessor
19
19
20
20
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # Class
22 # Class
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 class TestExtractOutput(PreprocessorTestsBase):
25 class TestExtractOutput(PreprocessorTestsBase):
26 """Contains test functions for extractoutput.py"""
26 """Contains test functions for extractoutput.py"""
27
27
28
28
29 def build_preprocessor(self):
29 def build_preprocessor(self):
30 """Make an instance of a preprocessor"""
30 """Make an instance of a preprocessor"""
31 preprocessor = ExtractOutputPreprocessor()
31 preprocessor = ExtractOutputPreprocessor()
32 preprocessor.enabled = True
32 preprocessor.enabled = True
33 return preprocessor
33 return preprocessor
34
34
35
35
36 def test_constructor(self):
36 def test_constructor(self):
37 """Can a ExtractOutputPreprocessor be constructed?"""
37 """Can a ExtractOutputPreprocessor be constructed?"""
38 self.build_preprocessor()
38 self.build_preprocessor()
39
39
40
40
41 def test_output(self):
41 def test_output(self):
42 """Test the output of the ExtractOutputPreprocessor"""
42 """Test the output of the ExtractOutputPreprocessor"""
43 nb = self.build_notebook()
43 nb = self.build_notebook()
44 res = self.build_resources()
44 res = self.build_resources()
45 preprocessor = self.build_preprocessor()
45 preprocessor = self.build_preprocessor()
46 nb, res = preprocessor(nb, res)
46 nb, res = preprocessor(nb, res)
47
47
48 # Check if text was extracted.
48 # Check if text was extracted.
49 assert 'text_filename' in nb.worksheets[0].cells[0].outputs[1]
49 output = nb.worksheets[0].cells[0].outputs[1]
50 text_filename = nb.worksheets[0].cells[0].outputs[1]['text_filename']
50 assert 'text_filename' in output
51 text_filename = output['text_filename']
51
52
52 # Check if png was extracted.
53 # Check if png was extracted.
53 assert 'png_filename' in nb.worksheets[0].cells[0].outputs[6]
54 output = nb.worksheets[0].cells[0].outputs[6]
54 png_filename = nb.worksheets[0].cells[0].outputs[6]['png_filename']
55 assert 'png_filename' in output
56 png_filename = output['png_filename']
55
57
56 # Verify text output
58 # Verify text output
57 assert text_filename in res['outputs']
59 assert text_filename in res['outputs']
58 self.assertEqual(res['outputs'][text_filename], b'b')
60 self.assertEqual(res['outputs'][text_filename], b'b')
59
61
60 # Verify png output
62 # Verify png output
61 assert png_filename in res['outputs']
63 assert png_filename in res['outputs']
62 self.assertEqual(res['outputs'][png_filename], b'g')
64 self.assertEqual(res['outputs'][png_filename], b'g')
General Comments 0
You need to be logged in to leave comments. Login now