base.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """Base TestCase class for testing Exporters"""
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. import os
  5. from ...tests.base import TestsBase
  6. all_raw_mimetypes = {
  7. 'text/x-python',
  8. 'text/markdown',
  9. 'text/html',
  10. 'text/restructuredtext',
  11. 'text/latex',
  12. }
  13. class ExportersTestsBase(TestsBase):
  14. """Contains base test functions for exporters"""
  15. exporter_class = None
  16. should_include_raw = None
  17. def _get_notebook(self, nb_name='notebook2.ipynb'):
  18. return os.path.join(self._get_files_path(), nb_name)
  19. def test_raw_cell_inclusion(self):
  20. """test raw cell inclusion based on raw_mimetype metadata"""
  21. if self.should_include_raw is None:
  22. return
  23. exporter = self.exporter_class()
  24. (output, resources) = exporter.from_filename(self._get_notebook('rawtest.ipynb'))
  25. for inc in self.should_include_raw:
  26. self.assertIn('raw %s' % inc, output, "should include %s" % inc)
  27. self.assertIn('no raw_mimetype metadata', output)
  28. for exc in all_raw_mimetypes.difference(self.should_include_raw):
  29. self.assertNotIn('raw %s' % exc, output, "should exclude %s" % exc)
  30. self.assertNotIn('never be included', output)