##// END OF EJS Templates
Set prompt number to None
Jessica B. Hamrick -
Show More
@@ -1,29 +1,28 b''
1 """Module containing a preprocessor that removes the outputs from code cells"""
1 """Module containing a preprocessor that removes the outputs from code cells"""
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 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
7 # Imports
7 # Imports
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9
9
10 from .base import Preprocessor
10 from .base import Preprocessor
11
11
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Classes
14 # Classes
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 class ClearOutputPreprocessor(Preprocessor):
16 class ClearOutputPreprocessor(Preprocessor):
17 """
17 """
18 Removes the output from all code cells in a notebook.
18 Removes the output from all code cells in a notebook.
19 """
19 """
20
20
21 def preprocess_cell(self, cell, resources, cell_index):
21 def preprocess_cell(self, cell, resources, cell_index):
22 """
22 """
23 Apply a transformation on each cell. See base.py for details.
23 Apply a transformation on each cell. See base.py for details.
24 """
24 """
25 if cell.cell_type == 'code':
25 if cell.cell_type == 'code':
26 cell.outputs = []
26 cell.outputs = []
27 if 'prompt_number' in cell:
27 cell['prompt_number'] = None
28 del cell['prompt_number']
29 return cell, resources
28 return cell, resources
@@ -1,42 +1,42 b''
1 """
1 """
2 Module with tests for the clearoutput preprocessor.
2 Module with tests for the clearoutput preprocessor.
3 """
3 """
4
4
5 # Copyright (c) IPython Development Team.
5 # Copyright (c) IPython Development Team.
6 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Imports
9 # Imports
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11 from IPython.nbformat import current as nbformat
11 from IPython.nbformat import current as nbformat
12
12
13 from .base import PreprocessorTestsBase
13 from .base import PreprocessorTestsBase
14 from ..clearoutput import ClearOutputPreprocessor
14 from ..clearoutput import ClearOutputPreprocessor
15
15
16
16
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18 # Class
18 # Class
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20
20
21 class TestClearOutput(PreprocessorTestsBase):
21 class TestClearOutput(PreprocessorTestsBase):
22 """Contains test functions for clearoutput.py"""
22 """Contains test functions for clearoutput.py"""
23
23
24
24
25 def build_preprocessor(self):
25 def build_preprocessor(self):
26 """Make an instance of a preprocessor"""
26 """Make an instance of a preprocessor"""
27 preprocessor = ClearOutputPreprocessor()
27 preprocessor = ClearOutputPreprocessor()
28 preprocessor.enabled = True
28 preprocessor.enabled = True
29 return preprocessor
29 return preprocessor
30
30
31 def test_constructor(self):
31 def test_constructor(self):
32 """Can a ClearOutputPreprocessor be constructed?"""
32 """Can a ClearOutputPreprocessor be constructed?"""
33 self.build_preprocessor()
33 self.build_preprocessor()
34
34
35 def test_output(self):
35 def test_output(self):
36 """Test the output of the ClearOutputPreprocessor"""
36 """Test the output of the ClearOutputPreprocessor"""
37 nb = self.build_notebook()
37 nb = self.build_notebook()
38 res = self.build_resources()
38 res = self.build_resources()
39 preprocessor = self.build_preprocessor()
39 preprocessor = self.build_preprocessor()
40 nb, res = preprocessor(nb, res)
40 nb, res = preprocessor(nb, res)
41 assert nb.worksheets[0].cells[0].outputs == []
41 assert nb.worksheets[0].cells[0].outputs == []
42 assert 'prompt_number' not in nb.worksheets[0].cells[0]
42 assert nb.worksheets[0].cells[0].prompt_number is None
General Comments 0
You need to be logged in to leave comments. Login now