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