test_notebook.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Tests for notebook.py"""
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. import json
  5. from .base import ExportersTestsBase
  6. from ..notebook import NotebookExporter
  7. from nbformat import validate
  8. from nbconvert.tests.base import assert_big_text_equal
  9. class TestNotebookExporter(ExportersTestsBase):
  10. """Contains test functions for notebook.py"""
  11. exporter_class = NotebookExporter
  12. def test_export(self):
  13. """
  14. Does the NotebookExporter return the file unchanged?
  15. """
  16. with open(self._get_notebook()) as f:
  17. file_contents = f.read()
  18. (output, resources) = self.exporter_class().from_filename(self._get_notebook())
  19. assert len(output) > 0
  20. assert_big_text_equal(output, file_contents)
  21. def test_downgrade_3(self):
  22. exporter = self.exporter_class(nbformat_version=3)
  23. (output, resources) = exporter.from_filename(self._get_notebook())
  24. nb = json.loads(output)
  25. validate(nb)
  26. def test_downgrade_2(self):
  27. exporter = self.exporter_class(nbformat_version=2)
  28. (output, resources) = exporter.from_filename(self._get_notebook())
  29. nb = json.loads(output)
  30. self.assertEqual(nb['nbformat'], 2)