test_latex.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Tests for the latex preprocessor"""
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. from .base import PreprocessorTestsBase
  5. from ..latex import LatexPreprocessor
  6. class TestLatex(PreprocessorTestsBase):
  7. """Contains test functions for latex.py"""
  8. def build_preprocessor(self):
  9. """Make an instance of a preprocessor"""
  10. preprocessor = LatexPreprocessor()
  11. preprocessor.enabled = True
  12. return preprocessor
  13. def test_constructor(self):
  14. """Can a LatexPreprocessor be constructed?"""
  15. self.build_preprocessor()
  16. def test_output(self):
  17. """Test the output of the LatexPreprocessor"""
  18. nb = self.build_notebook()
  19. res = self.build_resources()
  20. preprocessor = self.build_preprocessor()
  21. nb, res = preprocessor(nb, res)
  22. # Make sure the code cell wasn't modified.
  23. self.assertEqual(nb.cells[0].source, '$ e $')
  24. # Verify that the markdown cell wasn't processed.
  25. self.assertEqual(nb.cells[1].source, '$ e $')
  26. def test_highlight(self):
  27. """Check that highlighting style can be changed"""
  28. nb = self.build_notebook()
  29. res = self.build_resources()
  30. preprocessor = self.build_preprocessor()
  31. # Set the style to a known builtin that's not the default
  32. preprocessor.style='colorful'
  33. nb, res = preprocessor(nb, res)
  34. style_defs = res['latex']['pygments_definitions']
  35. # Get the default
  36. from pygments.formatters import LatexFormatter
  37. default_defs = LatexFormatter(style='default').get_style_defs()
  38. # Verify that the style was in fact changed
  39. assert style_defs != default_defs