test_pdf.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Tests for PDF export"""
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. import logging
  5. import os
  6. import shutil
  7. from testpath import tempdir
  8. from .base import ExportersTestsBase
  9. from ..pdf import PDFExporter
  10. from ...tests.utils import onlyif_cmds_exist
  11. #-----------------------------------------------------------------------------
  12. # Class
  13. #-----------------------------------------------------------------------------
  14. class TestPDF(ExportersTestsBase):
  15. """Test PDF export"""
  16. exporter_class = PDFExporter
  17. def test_constructor(self):
  18. """Can a PDFExporter be constructed?"""
  19. self.exporter_class()
  20. @onlyif_cmds_exist('xelatex', 'pandoc')
  21. def test_export(self):
  22. """Smoke test PDFExporter"""
  23. with tempdir.TemporaryDirectory() as td:
  24. file_name = os.path.basename(self._get_notebook())
  25. newpath = os.path.join(td, file_name)
  26. shutil.copy(self._get_notebook(), newpath)
  27. (output, resources) = self.exporter_class(latex_count=1).from_filename(newpath)
  28. self.assertIsInstance(output, bytes)
  29. assert len(output) > 0
  30. # all temporary file should be cleaned up
  31. assert {file_name} == set(os.listdir(td))