test_exporter.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Module with tests for exporter.py
  3. """
  4. #-----------------------------------------------------------------------------
  5. # Copyright (c) 2013, the IPython Development Team.
  6. #
  7. # Distributed under the terms of the Modified BSD License.
  8. #
  9. # The full license is in the file COPYING.txt, distributed with this software.
  10. #-----------------------------------------------------------------------------
  11. #-----------------------------------------------------------------------------
  12. # Imports
  13. #-----------------------------------------------------------------------------
  14. from traitlets.config import Config
  15. from .base import ExportersTestsBase
  16. from ...preprocessors.base import Preprocessor
  17. from ..exporter import Exporter
  18. #-----------------------------------------------------------------------------
  19. # Class
  20. #-----------------------------------------------------------------------------
  21. class PizzaPreprocessor(Preprocessor):
  22. """Simple preprocessor that adds a 'pizza' entry to the NotebookNode. Used
  23. to test Exporter.
  24. """
  25. def preprocess(self, nb, resources):
  26. nb['pizza'] = 'cheese'
  27. return nb, resources
  28. class TestExporter(ExportersTestsBase):
  29. """Contains test functions for exporter.py"""
  30. def test_constructor(self):
  31. """Can an Exporter be constructed?"""
  32. Exporter()
  33. def test_export(self):
  34. """Can an Exporter export something?"""
  35. exporter = Exporter()
  36. (notebook, resources) = exporter.from_filename(self._get_notebook())
  37. assert isinstance(notebook, dict)
  38. def test_preprocessor(self):
  39. """Do preprocessors work?"""
  40. config = Config({'Exporter': {'preprocessors': [PizzaPreprocessor()]}})
  41. exporter = Exporter(config=config)
  42. (notebook, resources) = exporter.from_filename(self._get_notebook())
  43. self.assertEqual(notebook['pizza'], 'cheese')