Skip to content

Commit

Permalink
regularise traitlet name improve test formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mpacer committed Aug 7, 2017
1 parent aa79f8d commit 9eb211f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions nbconvert/preprocessors/tagremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TagRemovePreprocessor(ClearOutputPreprocessor):
"""

remove_cell_tags = List(Unicode, default_value=[]).tag(config=True)
remove_all_output_tags = List(Unicode, default_value=[]).tag(config=True)
remove_all_outputs_tags = List(Unicode, default_value=[]).tag(config=True)
remove_single_output_tags = List(Unicode, default_value=[]).tag(config=True)

def check_cell_conditions(self, cell, resources, index):
Expand All @@ -47,8 +47,8 @@ def preprocess(self, nb, resources):
"""
# Skip preprocessing if the list of patterns is empty
if not any([self.remove_cell_tags,
self.remove_all_output_tags,
self.remove_single_output_tags]):
self.remove_all_outputs_tags,
self.remove_single_output_tags]):
return nb, resources

# Filter out cells that meet the conditions
Expand All @@ -63,8 +63,8 @@ def preprocess_cell(self, cell, resources, cell_index):
Apply a transformation on each cell. See base.py for details.
"""

if (any([tag in cell.get('metadata', {}).get('tags',[])
for tag in self.remove_all_output_tags])
if (any([tag in cell.get('metadata', {}).get('tags', [])
for tag in self.remove_all_outputs_tags])
and cell.cell_type == 'code'):
cell.outputs = []
cell.execution_count = None
Expand Down
11 changes: 10 additions & 1 deletion nbconvert/preprocessors/tests/test_tagremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class TestTagRemove(PreprocessorTestsBase):
"""Contains test functions for tagremove.py"""

def build_notebook(self):
"""
Build a notebook to have metadata tags for cells, output_areas, and
individual outputs.
"""
notebook = super(TestTagRemove, self).build_notebook()
# Add a few empty cells
notebook.cells[0].outputs.extend(
Expand Down Expand Up @@ -66,11 +70,16 @@ def test_output(self):
res = self.build_resources()
preprocessor = self.build_preprocessor()
preprocessor.remove_cell_tags.append("hide_this_cell")
preprocessor.remove_all_output_tags.append('hide_all_outputs')
preprocessor.remove_all_outputs_tags.append('hide_all_outputs')
preprocessor.remove_single_output_tags.append('hide_one_output')

nb, res = preprocessor(nb, res)

# checks that we can remove entire cells
self.assertEqual(len(nb.cells), 3)

# checks that we can remove output areas
self.assertEqual(len(nb.cells[-1].outputs), 0)

# checks that we can remove individual outputs
self.assertEqual(len(nb.cells[0].outputs), 8)

0 comments on commit 9eb211f

Please sign in to comment.