Show More
@@ -1,76 +1,73 | |||||
1 | """Tests for the svg2pdf preprocessor""" |
|
1 | """Tests for the svg2pdf preprocessor""" | |
2 |
|
2 | |||
3 | # Copyright (c) IPython Development Team. |
|
3 | # Copyright (c) IPython Development Team. | |
4 | # Distributed under the terms of the Modified BSD License. |
|
4 | # Distributed under the terms of the Modified BSD License. | |
5 |
|
5 | |||
6 | from IPython.testing import decorators as dec |
|
6 | from IPython.testing import decorators as dec | |
7 | from IPython.nbformat import v4 as nbformat |
|
7 | from IPython.nbformat import v4 as nbformat | |
8 |
|
8 | |||
9 | from .base import PreprocessorTestsBase |
|
9 | from .base import PreprocessorTestsBase | |
10 | from ..svg2pdf import SVG2PDFPreprocessor |
|
10 | from ..svg2pdf import SVG2PDFPreprocessor | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | class Testsvg2pdf(PreprocessorTestsBase): |
|
13 | class Testsvg2pdf(PreprocessorTestsBase): | |
14 | """Contains test functions for svg2pdf.py""" |
|
14 | """Contains test functions for svg2pdf.py""" | |
15 |
|
15 | |||
16 | simple_svg = """<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
|
16 | simple_svg = """<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
17 | <!-- Created with Inkscape (http://www.inkscape.org/) --> |
|
17 | <!-- Created with Inkscape (http://www.inkscape.org/) --> | |
18 | <svg |
|
18 | <svg | |
19 | xmlns:svg="http://www.w3.org/2000/svg" |
|
19 | xmlns:svg="http://www.w3.org/2000/svg" | |
20 | xmlns="http://www.w3.org/2000/svg" |
|
20 | xmlns="http://www.w3.org/2000/svg" | |
21 | version="1.0" |
|
21 | version="1.0" | |
22 | x="0.00000000" |
|
22 | x="0.00000000" | |
23 | y="0.00000000" |
|
23 | y="0.00000000" | |
24 | width="500.00000" |
|
24 | width="500.00000" | |
25 | height="500.00000" |
|
25 | height="500.00000" | |
26 | id="svg2"> |
|
26 | id="svg2"> | |
27 | <defs |
|
27 | <defs | |
28 | id="defs4" /> |
|
28 | id="defs4" /> | |
29 | <g |
|
29 | <g | |
30 | id="layer1"> |
|
30 | id="layer1"> | |
31 | <rect |
|
31 | <rect | |
32 | width="300.00000" |
|
32 | width="300.00000" | |
33 | height="300.00000" |
|
33 | height="300.00000" | |
34 | x="100.00000" |
|
34 | x="100.00000" | |
35 | y="100.00000" |
|
35 | y="100.00000" | |
36 | 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" |
|
36 | 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" | |
37 | id="rect5719" /> |
|
37 | id="rect5719" /> | |
38 | </g> |
|
38 | </g> | |
39 | </svg>""" |
|
39 | </svg>""" | |
40 |
|
40 | |||
41 | def build_notebook(self): |
|
41 | def build_notebook(self): | |
42 | """Build a reveal slides notebook in memory for use with tests. |
|
42 | """Build a reveal slides notebook in memory for use with tests. | |
43 | Overrides base in PreprocessorTestsBase""" |
|
43 | Overrides base in PreprocessorTestsBase""" | |
44 |
|
44 | |||
45 | outputs = [nbformat.new_output(output_type='display_data', |
|
45 | outputs = [nbformat.new_output(output_type='display_data', | |
46 | data={'image/svg+xml':self.simple_svg}) |
|
46 | data={'image/svg+xml':self.simple_svg}) | |
47 | ] |
|
47 | ] | |
48 |
|
48 | |||
49 | slide_metadata = {'slideshow' : {'slide_type': 'slide'}} |
|
|||
50 | subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} |
|
|||
51 |
|
||||
52 | cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)] |
|
49 | cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)] | |
53 |
|
50 | |||
54 | return nbformat.new_notebook(cells=cells) |
|
51 | return nbformat.new_notebook(cells=cells) | |
55 |
|
52 | |||
56 |
|
53 | |||
57 | def build_preprocessor(self): |
|
54 | def build_preprocessor(self): | |
58 | """Make an instance of a preprocessor""" |
|
55 | """Make an instance of a preprocessor""" | |
59 | preprocessor = SVG2PDFPreprocessor() |
|
56 | preprocessor = SVG2PDFPreprocessor() | |
60 | preprocessor.enabled = True |
|
57 | preprocessor.enabled = True | |
61 | return preprocessor |
|
58 | return preprocessor | |
62 |
|
59 | |||
63 |
|
60 | |||
64 | def test_constructor(self): |
|
61 | def test_constructor(self): | |
65 | """Can a SVG2PDFPreprocessor be constructed?""" |
|
62 | """Can a SVG2PDFPreprocessor be constructed?""" | |
66 | self.build_preprocessor() |
|
63 | self.build_preprocessor() | |
67 |
|
64 | |||
68 |
|
65 | |||
69 | @dec.onlyif_cmds_exist('inkscape') |
|
66 | @dec.onlyif_cmds_exist('inkscape') | |
70 | def test_output(self): |
|
67 | def test_output(self): | |
71 | """Test the output of the SVG2PDFPreprocessor""" |
|
68 | """Test the output of the SVG2PDFPreprocessor""" | |
72 | nb = self.build_notebook() |
|
69 | nb = self.build_notebook() | |
73 | res = self.build_resources() |
|
70 | res = self.build_resources() | |
74 | preprocessor = self.build_preprocessor() |
|
71 | preprocessor = self.build_preprocessor() | |
75 | nb, res = preprocessor(nb, res) |
|
72 | nb, res = preprocessor(nb, res) | |
76 | self.assertIn('application/pdf', nb.cells[0].outputs[0].data) |
|
73 | self.assertIn('application/pdf', nb.cells[0].outputs[0].data) |
General Comments 0
You need to be logged in to leave comments.
Login now