Show More
@@ -1,36 +1,39 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for the coalescestreams transformer |
|
2 | Module with tests for the coalescestreams 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 ..coalescestreams import coalesce_streams |
|
18 | from ..coalescestreams import coalesce_streams | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Class |
|
22 | # Class | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
|
24 | |||
25 | class TestCoalesceStreams(TransformerTestsBase): |
|
25 | class TestCoalesceStreams(TransformerTestsBase): | |
26 | """Contains test functions for coalescestreams.py""" |
|
26 | """Contains test functions for coalescestreams.py""" | |
27 |
|
27 | |||
28 | def test_coalesce_streams(self): |
|
28 | def test_coalesce_streams(self): | |
29 | """coalesce_streams transformer output test""" |
|
29 | """coalesce_streams transformer output test""" | |
30 | nb, res = coalesce_streams(self.build_notebook(), self.build_resources()) |
|
30 | nb = self.build_notebook() | |
|
31 | res = self.build_resources() | |||
|
32 | nb, res = transformer(nb, res) | |||
|
33 | nb, res = coalesce_streams(nb, res) | |||
31 | outputs = nb.worksheets[0].cells[0].outputs |
|
34 | outputs = nb.worksheets[0].cells[0].outputs | |
32 | self.assertEqual(outputs[0].text, "a") |
|
35 | self.assertEqual(outputs[0].text, "a") | |
33 | self.assertEqual(outputs[1].output_type, "text") |
|
36 | self.assertEqual(outputs[1].output_type, "text") | |
34 | self.assertEqual(outputs[2].text, "cd") |
|
37 | self.assertEqual(outputs[2].text, "cd") | |
35 | self.assertEqual(outputs[3].text, "ef") |
|
38 | self.assertEqual(outputs[3].text, "ef") | |
36 | No newline at end of file |
|
39 |
@@ -1,45 +1,48 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for the csshtmlheader transformer |
|
2 | Module with tests for the csshtmlheader 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 ..csshtmlheader import CSSHTMLHeaderTransformer |
|
18 | from ..csshtmlheader import CSSHTMLHeaderTransformer | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Class |
|
22 | # Class | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
|
24 | |||
25 | class TestCSSHTMLHeader(TransformerTestsBase): |
|
25 | class TestCSSHTMLHeader(TransformerTestsBase): | |
26 | """Contains test functions for csshtmlheader.py""" |
|
26 | """Contains test functions for csshtmlheader.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 = CSSHTMLHeaderTransformer() |
|
31 | transformer = CSSHTMLHeaderTransformer() | |
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 CSSHTMLHeaderTransformer be constructed?""" |
|
37 | """Can a CSSHTMLHeaderTransformer 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 CSSHTMLHeaderTransformer""" |
|
42 | """Test the output of the CSSHTMLHeaderTransformer""" | |
43 | nb, res = self.build_transformer()(self.build_notebook(), self.build_resources()) |
|
43 | nb = self.build_notebook() | |
|
44 | res = self.build_resources() | |||
|
45 | transformer = self.build_transformer() | |||
|
46 | nb, res = transformer(nb, res) | |||
44 | assert 'inlining' in res |
|
47 | assert 'inlining' in res | |
45 | assert 'css' in res['inlining'] No newline at end of file |
|
48 | assert 'css' in res['inlining'] |
@@ -1,62 +1,65 b'' | |||||
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 = self.build_notebook() | |
|
44 | res = self.build_resources() | |||
|
45 | transformer = self.build_transformer() | |||
|
46 | nb, res = transformer(nb, res) | |||
44 |
|
47 | |||
45 | # Check if text was extracted. |
|
48 | # Check if text was extracted. | |
46 | assert 'text_filename' in nb.worksheets[0].cells[0].outputs[1] |
|
49 | assert 'text_filename' in nb.worksheets[0].cells[0].outputs[1] | |
47 | text_filename = nb.worksheets[0].cells[0].outputs[1]['text_filename'] |
|
50 | text_filename = nb.worksheets[0].cells[0].outputs[1]['text_filename'] | |
48 |
|
51 | |||
49 | # Check if png was extracted. |
|
52 | # Check if png was extracted. | |
50 | assert 'png_filename' in nb.worksheets[0].cells[0].outputs[6] |
|
53 | assert 'png_filename' in nb.worksheets[0].cells[0].outputs[6] | |
51 | png_filename = nb.worksheets[0].cells[0].outputs[6]['png_filename'] |
|
54 | png_filename = nb.worksheets[0].cells[0].outputs[6]['png_filename'] | |
52 |
|
55 | |||
53 | # Make sure an entry to the resources was added. |
|
56 | # Make sure an entry to the resources was added. | |
54 | assert 'outputs' in res |
|
57 | assert 'outputs' in res | |
55 |
|
58 | |||
56 | # Verify text output |
|
59 | # Verify text output | |
57 | assert text_filename in res['outputs'] |
|
60 | assert text_filename in res['outputs'] | |
58 | self.assertEqual(res['outputs'][text_filename], b'b') |
|
61 | self.assertEqual(res['outputs'][text_filename], b'b') | |
59 |
|
62 | |||
60 | # Verify png output |
|
63 | # Verify png output | |
61 | assert png_filename in res['outputs'] |
|
64 | assert png_filename in res['outputs'] | |
62 | self.assertEqual(res['outputs'][png_filename], b'g') |
|
65 | self.assertEqual(res['outputs'][png_filename], b'g') |
@@ -1,48 +1,51 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for the latex transformer |
|
2 | Module with tests for the latex 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 ..latex import LatexTransformer |
|
18 | from ..latex import LatexTransformer | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Class |
|
22 | # Class | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
|
24 | |||
25 | class TestLatex(TransformerTestsBase): |
|
25 | class TestLatex(TransformerTestsBase): | |
26 | """Contains test functions for latex.py""" |
|
26 | """Contains test functions for latex.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 = LatexTransformer() |
|
31 | transformer = LatexTransformer() | |
32 | transformer.enabled = True |
|
32 | transformer.enabled = True | |
33 | return transformer |
|
33 | return transformer | |
34 |
|
34 | |||
35 | def test_constructor(self): |
|
35 | def test_constructor(self): | |
36 | """Can a LatexTransformer be constructed?""" |
|
36 | """Can a LatexTransformer be constructed?""" | |
37 | self.build_transformer() |
|
37 | self.build_transformer() | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | def test_output(self): |
|
40 | def test_output(self): | |
41 | """Test the output of the LatexTransformer""" |
|
41 | """Test the output of the LatexTransformer""" | |
42 | nb, res = self.build_transformer()(self.build_notebook(), self.build_resources()) |
|
42 | nb = self.build_notebook() | |
|
43 | res = self.build_resources() | |||
|
44 | transformer = self.build_transformer() | |||
|
45 | nb, res = transformer(nb, res) | |||
43 |
|
46 | |||
44 | # Make sure the code cell wasn't modified. |
|
47 | # Make sure the code cell wasn't modified. | |
45 | self.assertEqual(nb.worksheets[0].cells[0].input, '$ e $') |
|
48 | self.assertEqual(nb.worksheets[0].cells[0].input, '$ e $') | |
46 |
|
49 | |||
47 | # Verify that the markdown cell was processed. |
|
50 | # Verify that the markdown cell was processed. | |
48 | self.assertEqual(nb.worksheets[0].cells[1].source, '$e$') |
|
51 | self.assertEqual(nb.worksheets[0].cells[1].source, '$e$') |
@@ -1,88 +1,94 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for the revealhelp transformer |
|
2 | Module with tests for the revealhelp 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 IPython.nbformat import current as nbformat |
|
17 | from IPython.nbformat import current as nbformat | |
18 |
|
18 | |||
19 | from .base import TransformerTestsBase |
|
19 | from .base import TransformerTestsBase | |
20 | from ..revealhelp import RevealHelpTransformer |
|
20 | from ..revealhelp import RevealHelpTransformer | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 | # Class |
|
24 | # Class | |
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 |
|
26 | |||
27 | class Testrevealhelp(TransformerTestsBase): |
|
27 | class Testrevealhelp(TransformerTestsBase): | |
28 | """Contains test functions for revealhelp.py""" |
|
28 | """Contains test functions for revealhelp.py""" | |
29 |
|
29 | |||
30 | def build_notebook(self): |
|
30 | def build_notebook(self): | |
31 | """Build a reveal slides notebook in memory for use with tests. |
|
31 | """Build a reveal slides notebook in memory for use with tests. | |
32 | Overrides base in TransformerTestsBase""" |
|
32 | Overrides base in TransformerTestsBase""" | |
33 |
|
33 | |||
34 | outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a")] |
|
34 | outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a")] | |
35 |
|
35 | |||
36 | slide_metadata = {'slideshow' : {'slide_type': 'slide'}} |
|
36 | slide_metadata = {'slideshow' : {'slide_type': 'slide'}} | |
37 | subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} |
|
37 | subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} | |
38 |
|
38 | |||
39 | cells=[nbformat.new_code_cell(input="", prompt_number=1, outputs=outputs), |
|
39 | cells=[nbformat.new_code_cell(input="", prompt_number=1, outputs=outputs), | |
40 | nbformat.new_text_cell('markdown', source="", metadata=slide_metadata), |
|
40 | nbformat.new_text_cell('markdown', source="", metadata=slide_metadata), | |
41 | nbformat.new_code_cell(input="", prompt_number=2, outputs=outputs), |
|
41 | nbformat.new_code_cell(input="", prompt_number=2, outputs=outputs), | |
42 | nbformat.new_text_cell('markdown', source="", metadata=slide_metadata), |
|
42 | nbformat.new_text_cell('markdown', source="", metadata=slide_metadata), | |
43 | nbformat.new_text_cell('markdown', source="", metadata=subslide_metadata)] |
|
43 | nbformat.new_text_cell('markdown', source="", metadata=subslide_metadata)] | |
44 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] |
|
44 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] | |
45 |
|
45 | |||
46 | return nbformat.new_notebook(name="notebook1", worksheets=worksheets) |
|
46 | return nbformat.new_notebook(name="notebook1", worksheets=worksheets) | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | def build_transformer(self): |
|
49 | def build_transformer(self): | |
50 | """Make an instance of a transformer""" |
|
50 | """Make an instance of a transformer""" | |
51 | transformer = RevealHelpTransformer() |
|
51 | transformer = RevealHelpTransformer() | |
52 | transformer.enabled = True |
|
52 | transformer.enabled = True | |
53 | return transformer |
|
53 | return transformer | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | def test_constructor(self): |
|
56 | def test_constructor(self): | |
57 | """Can a RevealHelpTransformer be constructed?""" |
|
57 | """Can a RevealHelpTransformer be constructed?""" | |
58 | self.build_transformer() |
|
58 | self.build_transformer() | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def test_reveal_attribute(self): |
|
61 | def test_reveal_attribute(self): | |
62 | """Make sure the reveal url_prefix resources is set""" |
|
62 | """Make sure the reveal url_prefix resources is set""" | |
63 | nb, res = self.build_transformer()(self.build_notebook(), self.build_resources()) |
|
63 | nb = self.build_notebook() | |
|
64 | res = self.build_resources() | |||
|
65 | transformer = self.build_transformer() | |||
|
66 | nb, res = transformer(nb, res) | |||
64 | assert 'reveal' in res |
|
67 | assert 'reveal' in res | |
65 | assert 'url_prefix' in res['reveal'] |
|
68 | assert 'url_prefix' in res['reveal'] | |
66 |
|
69 | |||
67 |
|
70 | |||
68 | def test_reveal_output(self): |
|
71 | def test_reveal_output(self): | |
69 | """Make sure that the reveal transformer """ |
|
72 | """Make sure that the reveal transformer """ | |
70 | nb, res = self.build_transformer()(self.build_notebook(), self.build_resources()) |
|
73 | nb = self.build_notebook() | |
|
74 | res = self.build_resources() | |||
|
75 | transformer = self.build_transformer() | |||
|
76 | nb, res = transformer(nb, res) | |||
71 | cells = nb.worksheets[0].cells |
|
77 | cells = nb.worksheets[0].cells | |
72 |
|
78 | |||
73 | # Make sure correct metadata tags are available on every cell. |
|
79 | # Make sure correct metadata tags are available on every cell. | |
74 | for cell in cells: |
|
80 | for cell in cells: | |
75 | assert 'slide_type' in cell.metadata |
|
81 | assert 'slide_type' in cell.metadata | |
76 | assert 'align_type' in cell.metadata |
|
82 | assert 'align_type' in cell.metadata | |
77 |
|
83 | |||
78 | # Make sure slide end is only applied to the cells preceeding slide |
|
84 | # Make sure slide end is only applied to the cells preceeding slide | |
79 | # cells. |
|
85 | # cells. | |
80 | assert 'slide_helper' not in cells[1].metadata |
|
86 | assert 'slide_helper' not in cells[1].metadata | |
81 |
|
87 | |||
82 | # Verify 'slide-end' |
|
88 | # Verify 'slide-end' | |
83 | assert 'slide_helper' in cells[0].metadata |
|
89 | assert 'slide_helper' in cells[0].metadata | |
84 | self.assertEqual(cells[0].metadata['slide_helper'], 'slide_end') |
|
90 | self.assertEqual(cells[0].metadata['slide_helper'], 'slide_end') | |
85 | assert 'slide_helper' in cells[2].metadata |
|
91 | assert 'slide_helper' in cells[2].metadata | |
86 | self.assertEqual(cells[2].metadata['slide_helper'], 'slide_end') |
|
92 | self.assertEqual(cells[2].metadata['slide_helper'], 'slide_end') | |
87 | assert 'slide_helper' in cells[3].metadata |
|
93 | assert 'slide_helper' in cells[3].metadata | |
88 | self.assertEqual(cells[3].metadata['slide_helper'], 'subslide_end') |
|
94 | self.assertEqual(cells[3].metadata['slide_helper'], 'subslide_end') |
@@ -1,55 +1,58 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for the sphinx transformer |
|
2 | Module with tests for the sphinx 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 ..sphinx import SphinxTransformer |
|
18 | from ..sphinx import SphinxTransformer | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Class |
|
22 | # Class | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
|
24 | |||
25 | class TestSphinx(TransformerTestsBase): |
|
25 | class TestSphinx(TransformerTestsBase): | |
26 | """Contains test functions for sphinx.py""" |
|
26 | """Contains test functions for sphinx.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 = SphinxTransformer() |
|
31 | transformer = SphinxTransformer() | |
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 SphinxTransformer be constructed?""" |
|
37 | """Can a SphinxTransformer be constructed?""" | |
38 | self.build_transformer() |
|
38 | self.build_transformer() | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | def test_resources(self): |
|
41 | def test_resources(self): | |
42 | """Make sure the SphinxTransformer adds the appropriate resources to the |
|
42 | """Make sure the SphinxTransformer adds the appropriate resources to the | |
43 | resources dict.""" |
|
43 | resources dict.""" | |
44 | nb, res = self.build_transformer()(self.build_notebook(), self.build_resources()) |
|
44 | nb = self.build_notebook() | |
|
45 | res = self.build_resources() | |||
|
46 | transformer = self.build_transformer() | |||
|
47 | nb, res = transformer(nb, res) | |||
45 | assert 'sphinx' in res |
|
48 | assert 'sphinx' in res | |
46 | assert "author" in res['sphinx'] |
|
49 | assert "author" in res['sphinx'] | |
47 | assert "version" in res['sphinx'] |
|
50 | assert "version" in res['sphinx'] | |
48 | assert "release" in res['sphinx'] |
|
51 | assert "release" in res['sphinx'] | |
49 | assert "date" in res['sphinx'] |
|
52 | assert "date" in res['sphinx'] | |
50 | assert "chapterstyle" in res['sphinx'] |
|
53 | assert "chapterstyle" in res['sphinx'] | |
51 | assert "outputstyle" in res['sphinx'] |
|
54 | assert "outputstyle" in res['sphinx'] | |
52 | assert "centeroutput" in res['sphinx'] |
|
55 | assert "centeroutput" in res['sphinx'] | |
53 | assert "header" in res['sphinx'] |
|
56 | assert "header" in res['sphinx'] | |
54 | assert "texinputs" in res['sphinx'] |
|
57 | assert "texinputs" in res['sphinx'] | |
55 | assert "pygment_definitions" in res['sphinx'] |
|
58 | assert "pygment_definitions" in res['sphinx'] |
@@ -1,87 +1,90 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for the svg2pdf transformer |
|
2 | Module with tests for the svg2pdf 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 IPython.testing import decorators as dec |
|
17 | from IPython.testing import decorators as dec | |
18 | from IPython.nbformat import current as nbformat |
|
18 | from IPython.nbformat import current as nbformat | |
19 |
|
19 | |||
20 | from .base import TransformerTestsBase |
|
20 | from .base import TransformerTestsBase | |
21 | from ..svg2pdf import SVG2PDFTransformer |
|
21 | from ..svg2pdf import SVG2PDFTransformer | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 | # Class |
|
25 | # Class | |
26 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
27 |
|
27 | |||
28 | class Testsvg2pdf(TransformerTestsBase): |
|
28 | class Testsvg2pdf(TransformerTestsBase): | |
29 | """Contains test functions for svg2pdf.py""" |
|
29 | """Contains test functions for svg2pdf.py""" | |
30 |
|
30 | |||
31 | simple_svg = """<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
|
31 | simple_svg = """<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
32 | <!-- Created with Inkscape (http://www.inkscape.org/) --> |
|
32 | <!-- Created with Inkscape (http://www.inkscape.org/) --> | |
33 | <svg |
|
33 | <svg | |
34 | xmlns:svg="http://www.w3.org/2000/svg" |
|
34 | xmlns:svg="http://www.w3.org/2000/svg" | |
35 | xmlns="http://www.w3.org/2000/svg" |
|
35 | xmlns="http://www.w3.org/2000/svg" | |
36 | version="1.0" |
|
36 | version="1.0" | |
37 | x="0.00000000" |
|
37 | x="0.00000000" | |
38 | y="0.00000000" |
|
38 | y="0.00000000" | |
39 | width="500.00000" |
|
39 | width="500.00000" | |
40 | height="500.00000" |
|
40 | height="500.00000" | |
41 | id="svg2"> |
|
41 | id="svg2"> | |
42 | <defs |
|
42 | <defs | |
43 | id="defs4" /> |
|
43 | id="defs4" /> | |
44 | <g |
|
44 | <g | |
45 | id="layer1"> |
|
45 | id="layer1"> | |
46 | <rect |
|
46 | <rect | |
47 | width="300.00000" |
|
47 | width="300.00000" | |
48 | height="300.00000" |
|
48 | height="300.00000" | |
49 | x="100.00000" |
|
49 | x="100.00000" | |
50 | y="100.00000" |
|
50 | y="100.00000" | |
51 | style="opacity:1.0000000;fill:none;fill-opacity:1.0000000;fill-rule:evenodd;stroke:#000000;stroke-width:8.0000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.00000000;stroke-opacity:1.0000000" |
|
51 | style="opacity:1.0000000;fill:none;fill-opacity:1.0000000;fill-rule:evenodd;stroke:#000000;stroke-width:8.0000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.00000000;stroke-opacity:1.0000000" | |
52 | id="rect5719" /> |
|
52 | id="rect5719" /> | |
53 | </g> |
|
53 | </g> | |
54 | </svg>""" |
|
54 | </svg>""" | |
55 |
|
55 | |||
56 | def build_notebook(self): |
|
56 | def build_notebook(self): | |
57 | """Build a reveal slides notebook in memory for use with tests. |
|
57 | """Build a reveal slides notebook in memory for use with tests. | |
58 | Overrides base in TransformerTestsBase""" |
|
58 | Overrides base in TransformerTestsBase""" | |
59 |
|
59 | |||
60 | outputs = [nbformat.new_output(output_type="svg", output_svg=self.simple_svg)] |
|
60 | outputs = [nbformat.new_output(output_type="svg", output_svg=self.simple_svg)] | |
61 |
|
61 | |||
62 | slide_metadata = {'slideshow' : {'slide_type': 'slide'}} |
|
62 | slide_metadata = {'slideshow' : {'slide_type': 'slide'}} | |
63 | subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} |
|
63 | subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} | |
64 |
|
64 | |||
65 | cells=[nbformat.new_code_cell(input="", prompt_number=1, outputs=outputs)] |
|
65 | cells=[nbformat.new_code_cell(input="", prompt_number=1, outputs=outputs)] | |
66 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] |
|
66 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] | |
67 |
|
67 | |||
68 | return nbformat.new_notebook(name="notebook1", worksheets=worksheets) |
|
68 | return nbformat.new_notebook(name="notebook1", worksheets=worksheets) | |
69 |
|
69 | |||
70 |
|
70 | |||
71 | def build_transformer(self): |
|
71 | def build_transformer(self): | |
72 | """Make an instance of a transformer""" |
|
72 | """Make an instance of a transformer""" | |
73 | transformer = SVG2PDFTransformer() |
|
73 | transformer = SVG2PDFTransformer() | |
74 | transformer.enabled = True |
|
74 | transformer.enabled = True | |
75 | return transformer |
|
75 | return transformer | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | def test_constructor(self): |
|
78 | def test_constructor(self): | |
79 | """Can a SVG2PDFTransformer be constructed?""" |
|
79 | """Can a SVG2PDFTransformer be constructed?""" | |
80 | self.build_transformer() |
|
80 | self.build_transformer() | |
81 |
|
81 | |||
82 |
|
82 | |||
83 | @dec.onlyif_cmds_exist('inkscape') |
|
83 | @dec.onlyif_cmds_exist('inkscape') | |
84 | def test_output(self): |
|
84 | def test_output(self): | |
85 | """Test the output of the SVG2PDFTransformer""" |
|
85 | """Test the output of the SVG2PDFTransformer""" | |
86 | nb, res = self.build_transformer()(self.build_notebook(), self.build_resources()) |
|
86 | nb = self.build_notebook() | |
|
87 | res = self.build_resources() | |||
|
88 | transformer = self.build_transformer() | |||
|
89 | nb, res = transformer(nb, res) | |||
87 | assert 'svg' in nb.worksheets[0].cells[0].outputs[0] |
|
90 | assert 'svg' in nb.worksheets[0].cells[0].outputs[0] |
General Comments 0
You need to be logged in to leave comments.
Login now