Show More
@@ -1,62 +1,62 | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for the extractoutput transformer |
|
2 | Module with tests for the extractoutput transformer | |
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 TransformerTestsBase |
|
17 | from .base import TransformerTestsBase | |
18 | from ..extractoutput import ExtractOutputTransformer |
|
18 | from ..extractoutput import ExtractOutputTransformer | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Class |
|
22 | # Class | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
|
24 | |||
25 | class TestExtractOutput(TransformerTestsBase): |
|
25 | class TestExtractOutput(TransformerTestsBase): | |
26 | """Contains test functions for extractoutput.py""" |
|
26 | """Contains test functions for extractoutput.py""" | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | def build_transformer(self): |
|
29 | def build_transformer(self): | |
30 | """Make an instance of a transformer""" |
|
30 | """Make an instance of a transformer""" | |
31 | transformer = ExtractOutputTransformer() |
|
31 | transformer = ExtractOutputTransformer() | |
32 | transformer.enabled = True |
|
32 | transformer.enabled = True | |
33 | return transformer |
|
33 | return transformer | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | def test_constructor(self): |
|
36 | def test_constructor(self): | |
37 | """Can a ExtractOutputTransformer be constructed?""" |
|
37 | """Can a ExtractOutputTransformer be constructed?""" | |
38 | self.build_transformer() |
|
38 | self.build_transformer() | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | def test_output(self): |
|
41 | def test_output(self): | |
42 | """Test the output of the ExtractOutputTransformer""" |
|
42 | """Test the output of the ExtractOutputTransformer""" | |
43 | nb, res = self.build_transformer()(self.build_notebook(), self.build_resources()) |
|
43 | nb, res = self.build_transformer()(self.build_notebook(), self.build_resources()) | |
44 |
|
44 | |||
45 | # Check if text was extracted. |
|
45 | # Check if text was extracted. | |
46 | assert 'text_filename' in nb.worksheets[0].cells[0].outputs[1] |
|
46 | assert 'text_filename' in nb.worksheets[0].cells[0].outputs[1] | |
47 | text_filename = nb.worksheets[0].cells[0].outputs[1]['text_filename'] |
|
47 | text_filename = nb.worksheets[0].cells[0].outputs[1]['text_filename'] | |
48 |
|
48 | |||
49 | # Check if png was extracted. |
|
49 | # Check if png was extracted. | |
50 | assert 'png_filename' in nb.worksheets[0].cells[0].outputs[6] |
|
50 | assert 'png_filename' in nb.worksheets[0].cells[0].outputs[6] | |
51 | png_filename = nb.worksheets[0].cells[0].outputs[6]['png_filename'] |
|
51 | png_filename = nb.worksheets[0].cells[0].outputs[6]['png_filename'] | |
52 |
|
52 | |||
53 | # Make sure an entry to the resources was added. |
|
53 | # Make sure an entry to the resources was added. | |
54 | assert 'outputs' in res |
|
54 | assert 'outputs' in res | |
55 |
|
55 | |||
56 | # Verify text output |
|
56 | # Verify text output | |
57 | assert text_filename in res['outputs'] |
|
57 | assert text_filename in res['outputs'] | |
58 | self.assertEqual(res['outputs'][text_filename], 'b') |
|
58 | self.assertEqual(res['outputs'][text_filename], b'b') | |
59 |
|
59 | |||
60 | # Verify png output |
|
60 | # Verify png output | |
61 | assert png_filename in res['outputs'] |
|
61 | assert png_filename in res['outputs'] | |
62 | self.assertEqual(res['outputs'][png_filename], 'g') |
|
62 | self.assertEqual(res['outputs'][png_filename], b'g') |
General Comments 0
You need to be logged in to leave comments.
Login now