##// END OF EJS Templates
Merge pull request #7027 from takluyver/svg2pdf-test-fix...
Thomas Kluyver -
r19075:1da9421a merge
parent child Browse files
Show More
@@ -47,18 +47,12 b' class ConvertFiguresPreprocessor(Preprocessor):'
47 """
47 """
48
48
49 # Loop through all of the datatypes of the outputs in the cell.
49 # Loop through all of the datatypes of the outputs in the cell.
50 for index, cell_out in enumerate(cell.get('outputs', [])):
50 for output in cell.get('outputs', []):
51 for data_type, data in list(cell_out.items()):
51 if output.output_type in {'execute_result', 'display_data'} \
52 # this must run *before* extract outputs,
52 and self.from_format in output.data \
53 # so figure_name and filename do not exist
53 and self.to_format not in output.data:
54 self._convert_figure(cell_out, resources, data_type, data)
55 return cell, resources
56
54
55 output.data[self.to_format] = self.convert_figure(
56 self.from_format, output.data[self.from_format])
57
57
58 def _convert_figure(self, cell_out, resources, data_type, data):
58 return cell, resources
59 """
60 Convert a figure and output the results to the cell output
61 """
62 if not self.to_format in cell_out and data_type == self.from_format:
63 data = self.convert_figure(data_type, data)
64 cell_out[self.to_format] = data
@@ -61,7 +61,7 b' class SVG2PDFPreprocessor(ConvertFiguresPreprocessor):'
61 with TemporaryDirectory() as tmpdir:
61 with TemporaryDirectory() as tmpdir:
62
62
63 #Write fig to temp file
63 #Write fig to temp file
64 input_filename = os.path.join(tmpdir, 'figure.' + data_format)
64 input_filename = os.path.join(tmpdir, 'figure.svg')
65 # SVG data is unicode text
65 # SVG data is unicode text
66 with io.open(input_filename, 'w', encoding='utf8') as f:
66 with io.open(input_filename, 'w', encoding='utf8') as f:
67 f.write(data)
67 f.write(data)
@@ -42,10 +42,9 b' class Testsvg2pdf(PreprocessorTestsBase):'
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
46 data={'image/svg+xml':self.simple_svg})
47 slide_metadata = {'slideshow' : {'slide_type': 'slide'}}
47 ]
48 subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}}
49
48
50 cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)]
49 cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)]
51
50
@@ -71,4 +70,4 b' class Testsvg2pdf(PreprocessorTestsBase):'
71 res = self.build_resources()
70 res = self.build_resources()
72 preprocessor = self.build_preprocessor()
71 preprocessor = self.build_preprocessor()
73 nb, res = preprocessor(nb, res)
72 nb, res = preprocessor(nb, res)
74 self.assertIn('application/pdf', nb.cells[0].outputs[0])
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