Skip to content

Commit

Permalink
Merge pull request #1095 from charlesfrye/1091_regexremove
Browse files Browse the repository at this point in the history
Change RegExRemove to remove code cells with output
  • Loading branch information
MSeal authored Sep 5, 2019
2 parents aeaa214 + fe529f6 commit a6f89c3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
5 changes: 2 additions & 3 deletions nbconvert/preprocessors/regexremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class RegexRemovePreprocessor(Preprocessor):

def check_conditions(self, cell):
"""
Checks that a cell matches the pattern and that (if a code cell)
it does not have any outputs.
Checks that a cell matches the pattern.
Returns: Boolean.
True means cell should *not* be removed.
Expand All @@ -54,7 +53,7 @@ def check_conditions(self, cell):
for pattern in self.patterns))

# Filter out cells that meet the pattern and have no outputs
return cell.get('outputs') or not pattern.match(cell.source)
return not pattern.match(cell.source)

def preprocess(self, nb, resources):
"""
Expand Down
21 changes: 0 additions & 21 deletions nbconvert/preprocessors/tests/test_regexremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,3 @@ def test_output(self):
for pattern in patterns:
self.assertFalse(pattern.match(cell.source))

def test_nosource_with_output(self):
"""
Test that the check_conditions returns true when given a code-cell
that has non-empty outputs but no source.
"""

cell = {
'cell_type': 'code',
'execution_count': 2,
'metadata': {},
'outputs': [{
'name': 'stdout',
'output_type': 'stream',
'text': 'I exist.\n'
}],
'source': ''
}
preprocessor = self.build_preprocessor()
node = from_dict(cell)
assert preprocessor.check_conditions(node)

0 comments on commit a6f89c3

Please sign in to comment.