##// END OF EJS Templates
Fix test for svg2pdf preprocessor
Thomas Kluyver -
Show More
@@ -1,74 +1,76 b''
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="image/svg+xml", output_svg=self.simple_svg)]
45 outputs = [nbformat.new_output(output_type='display_data',
46 data={'image/svg+xml':self.simple_svg})
47 ]
46
48
47 slide_metadata = {'slideshow' : {'slide_type': 'slide'}}
49 slide_metadata = {'slideshow' : {'slide_type': 'slide'}}
48 subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}}
50 subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}}
49
51
50 cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)]
52 cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)]
51
53
52 return nbformat.new_notebook(cells=cells)
54 return nbformat.new_notebook(cells=cells)
53
55
54
56
55 def build_preprocessor(self):
57 def build_preprocessor(self):
56 """Make an instance of a preprocessor"""
58 """Make an instance of a preprocessor"""
57 preprocessor = SVG2PDFPreprocessor()
59 preprocessor = SVG2PDFPreprocessor()
58 preprocessor.enabled = True
60 preprocessor.enabled = True
59 return preprocessor
61 return preprocessor
60
62
61
63
62 def test_constructor(self):
64 def test_constructor(self):
63 """Can a SVG2PDFPreprocessor be constructed?"""
65 """Can a SVG2PDFPreprocessor be constructed?"""
64 self.build_preprocessor()
66 self.build_preprocessor()
65
67
66
68
67 @dec.onlyif_cmds_exist('inkscape')
69 @dec.onlyif_cmds_exist('inkscape')
68 def test_output(self):
70 def test_output(self):
69 """Test the output of the SVG2PDFPreprocessor"""
71 """Test the output of the SVG2PDFPreprocessor"""
70 nb = self.build_notebook()
72 nb = self.build_notebook()
71 res = self.build_resources()
73 res = self.build_resources()
72 preprocessor = self.build_preprocessor()
74 preprocessor = self.build_preprocessor()
73 nb, res = preprocessor(nb, res)
75 nb, res = preprocessor(nb, res)
74 self.assertIn('application/pdf', nb.cells[0].outputs[0])
76 self.assertIn('application/pdf', nb.cells[0].outputs[0].data)
General Comments 0
You need to be logged in to leave comments. Login now