##// END OF EJS Templates
Add preprocessor that clears cell outputs
Julia Evans -
Show More
@@ -0,0 +1,32 b''
1 """Module containing a preprocessor that removes the outputs from code cells"""
2
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2013, the IPython Development Team.
5 #
6 # Distributed under the terms of the Modified BSD License.
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
14
15 from .base import Preprocessor
16
17
18 #-----------------------------------------------------------------------------
19 # Classes
20 #-----------------------------------------------------------------------------
21 class ClearOutputPreprocessor(Preprocessor):
22 """
23 Removes the output from all code cells in a notebook.
24 """
25
26 def preprocess_cell(self, cell, resources, cell_index):
27 """
28 Apply a transformation on each cell. See base.py for details.
29 """
30 if cell.cell_type == 'code':
31 cell.outputs = []
32 return cell, resources
@@ -0,0 +1,46 b''
1 """
2 Module with tests for the clearoutput preprocessor.
3 """
4
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16 from IPython.nbformat import current as nbformat
17
18 from .base import PreprocessorTestsBase
19 from ..clearoutput import ClearOutputPreprocessor
20
21
22 #-----------------------------------------------------------------------------
23 # Class
24 #-----------------------------------------------------------------------------
25
26 class TestClearOutput(PreprocessorTestsBase):
27 """Contains test functions for clearoutput.py"""
28
29
30 def build_preprocessor(self):
31 """Make an instance of a preprocessor"""
32 preprocessor = ClearOutputPreprocessor()
33 preprocessor.enabled = True
34 return preprocessor
35
36 def test_constructor(self):
37 """Can a ClearOutputPreprocessor be constructed?"""
38 self.build_preprocessor()
39
40 def test_output(self):
41 """Test the output of the ClearOutputPreprocessor"""
42 nb = self.build_notebook()
43 res = self.build_resources()
44 preprocessor = self.build_preprocessor()
45 nb, res = preprocessor(nb, res)
46 assert nb.worksheets[0].cells[0].outputs == []
@@ -70,6 +70,7 b' class Exporter(LoggingConfigurable):'
70 'IPython.nbconvert.preprocessors.CSSHTMLHeaderPreprocessor',
70 'IPython.nbconvert.preprocessors.CSSHTMLHeaderPreprocessor',
71 'IPython.nbconvert.preprocessors.RevealHelpPreprocessor',
71 'IPython.nbconvert.preprocessors.RevealHelpPreprocessor',
72 'IPython.nbconvert.preprocessors.LatexPreprocessor',
72 'IPython.nbconvert.preprocessors.LatexPreprocessor',
73 'IPython.nbconvert.preprocessors.ClearOutputPreprocessor',
73 'IPython.nbconvert.preprocessors.HighlightMagicsPreprocessor'],
74 'IPython.nbconvert.preprocessors.HighlightMagicsPreprocessor'],
74 config=True,
75 config=True,
75 help="""List of preprocessors available by default, by name, namespace,
76 help="""List of preprocessors available by default, by name, namespace,
@@ -7,6 +7,7 b' from .revealhelp import RevealHelpPreprocessor'
7 from .latex import LatexPreprocessor
7 from .latex import LatexPreprocessor
8 from .csshtmlheader import CSSHTMLHeaderPreprocessor
8 from .csshtmlheader import CSSHTMLHeaderPreprocessor
9 from .highlightmagics import HighlightMagicsPreprocessor
9 from .highlightmagics import HighlightMagicsPreprocessor
10 from .clearoutput import ClearOutputPreprocessor
10
11
11 # decorated function Preprocessors
12 # decorated function Preprocessors
12 from .coalescestreams import coalesce_streams
13 from .coalescestreams import coalesce_streams
General Comments 0
You need to be logged in to leave comments. Login now