test_clearmetadata.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """
  2. Module with tests for the clearmetadata preprocessor.
  3. """
  4. # Copyright (c) IPython Development Team.
  5. # Distributed under the terms of the Modified BSD License.
  6. from .base import PreprocessorTestsBase
  7. from ..clearmetadata import ClearMetadataPreprocessor
  8. class TestClearMetadata(PreprocessorTestsBase):
  9. """Contains test functions for clearmetadata.py"""
  10. def build_notebook(self):
  11. notebook = super(TestClearMetadata, self).build_notebook()
  12. # Add a test field to the first cell
  13. if 'metadata' not in notebook.cells[0]:
  14. notebook.cells[0].metadata = {}
  15. notebook.cells[0].metadata['test_field'] = 'test_value'
  16. notebook.cells[0].metadata['executeTime'] = dict([('end_time', '09:31:50'),
  17. ('start_time', '09:31:49')])
  18. return notebook
  19. def build_preprocessor(self):
  20. """Make an instance of a preprocessor"""
  21. preprocessor = ClearMetadataPreprocessor()
  22. preprocessor.enabled = True
  23. return preprocessor
  24. def test_constructor(self):
  25. """Can a ClearMetadataPreprocessor be constructed?"""
  26. self.build_preprocessor()
  27. def test_output(self):
  28. """Test the output of the ClearMetadataPreprocessor"""
  29. nb = self.build_notebook()
  30. res = self.build_resources()
  31. preprocessor = self.build_preprocessor()
  32. nb, res = preprocessor(nb, res)
  33. assert not nb.cells[0].metadata