Show More
@@ -1,53 +1,53 b'' | |||
|
1 | 1 | """ |
|
2 | 2 | Module with utility functions for preprocessor tests |
|
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 | |
|
17 | 17 | from IPython.nbformat import current as nbformat |
|
18 | 18 | |
|
19 | 19 | from ...tests.base import TestsBase |
|
20 | 20 | from ...exporters.exporter import ResourcesDict |
|
21 | 21 | |
|
22 | 22 | #----------------------------------------------------------------------------- |
|
23 | 23 | # Class |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | class PreprocessorTestsBase(TestsBase): |
|
27 | 27 | """Contains test functions preprocessor tests""" |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | def build_notebook(self): |
|
31 | 31 | """Build a notebook in memory for use with preprocessor tests""" |
|
32 | 32 | |
|
33 | 33 | outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a"), |
|
34 | 34 | nbformat.new_output(output_type="text", output_text="b"), |
|
35 | 35 | nbformat.new_output(output_type="stream", stream="stdout", output_text="c"), |
|
36 | 36 | nbformat.new_output(output_type="stream", stream="stdout", output_text="d"), |
|
37 | 37 | nbformat.new_output(output_type="stream", stream="stderr", output_text="e"), |
|
38 | 38 | nbformat.new_output(output_type="stream", stream="stderr", output_text="f"), |
|
39 |
nbformat.new_output(output_type="png", output_png= |
|
|
39 | nbformat.new_output(output_type="png", output_png='Zw==')] #g | |
|
40 | 40 | |
|
41 | 41 | cells=[nbformat.new_code_cell(input="$ e $", prompt_number=1,outputs=outputs), |
|
42 | 42 | nbformat.new_text_cell('markdown', source="$ e $")] |
|
43 | 43 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] |
|
44 | 44 | |
|
45 | 45 | return nbformat.new_notebook(name="notebook1", worksheets=worksheets) |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | def build_resources(self): |
|
49 | 49 | """Build an empty resources dictionary.""" |
|
50 | 50 | |
|
51 | 51 | res = ResourcesDict() |
|
52 | 52 | res['metadata'] = ResourcesDict() |
|
53 | 53 | return res |
@@ -1,62 +1,64 b'' | |||
|
1 | 1 | """ |
|
2 | 2 | Module with tests for the extractoutput 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 | |
|
17 | 17 | from .base import PreprocessorTestsBase |
|
18 | 18 | from ..extractoutput import ExtractOutputPreprocessor |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | # Class |
|
23 | 23 | #----------------------------------------------------------------------------- |
|
24 | 24 | |
|
25 | 25 | class TestExtractOutput(PreprocessorTestsBase): |
|
26 | 26 | """Contains test functions for extractoutput.py""" |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | def build_preprocessor(self): |
|
30 | 30 | """Make an instance of a preprocessor""" |
|
31 | 31 | preprocessor = ExtractOutputPreprocessor() |
|
32 | 32 | preprocessor.enabled = True |
|
33 | 33 | return preprocessor |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | def test_constructor(self): |
|
37 | 37 | """Can a ExtractOutputPreprocessor be constructed?""" |
|
38 | 38 | self.build_preprocessor() |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | def test_output(self): |
|
42 | 42 | """Test the output of the ExtractOutputPreprocessor""" |
|
43 | 43 | nb = self.build_notebook() |
|
44 | 44 | res = self.build_resources() |
|
45 | 45 | preprocessor = self.build_preprocessor() |
|
46 | 46 | nb, res = preprocessor(nb, res) |
|
47 | 47 | |
|
48 | 48 | # Check if text was extracted. |
|
49 |
|
|
|
50 | text_filename = nb.worksheets[0].cells[0].outputs[1]['text_filename'] | |
|
49 | output = nb.worksheets[0].cells[0].outputs[1] | |
|
50 | assert 'text_filename' in output | |
|
51 | text_filename = output['text_filename'] | |
|
51 | 52 | |
|
52 | 53 | # Check if png was extracted. |
|
53 |
|
|
|
54 | png_filename = nb.worksheets[0].cells[0].outputs[6]['png_filename'] | |
|
54 | output = nb.worksheets[0].cells[0].outputs[6] | |
|
55 | assert 'png_filename' in output | |
|
56 | png_filename = output['png_filename'] | |
|
55 | 57 | |
|
56 | 58 | # Verify text output |
|
57 | 59 | assert text_filename in res['outputs'] |
|
58 | 60 | self.assertEqual(res['outputs'][text_filename], b'b') |
|
59 | 61 | |
|
60 | 62 | # Verify png output |
|
61 | 63 | assert png_filename in res['outputs'] |
|
62 | 64 | self.assertEqual(res['outputs'][png_filename], b'g') |
General Comments 0
You need to be logged in to leave comments.
Login now