test_asciidoc.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """Tests for ASCIIDocExporter`"""
  2. #-----------------------------------------------------------------------------
  3. # Copyright (c) 2016, the IPython Development Team.
  4. #
  5. # Distributed under the terms of the Modified BSD License.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #-----------------------------------------------------------------------------
  9. #-----------------------------------------------------------------------------
  10. # Imports
  11. #-----------------------------------------------------------------------------
  12. import re
  13. from traitlets.config import Config
  14. from .base import ExportersTestsBase
  15. from ..asciidoc import ASCIIDocExporter
  16. from ...tests.utils import onlyif_cmds_exist
  17. #-----------------------------------------------------------------------------
  18. # Class
  19. #-----------------------------------------------------------------------------
  20. in_regex = r"In\[(.*)\]:"
  21. out_regex = r"Out\[(.*)\]:"
  22. class TestASCIIDocExporter(ExportersTestsBase):
  23. """Tests for ASCIIDocExporter"""
  24. exporter_class = ASCIIDocExporter
  25. def test_constructor(self):
  26. """
  27. Can a ASCIIDocExporter be constructed?
  28. """
  29. ASCIIDocExporter()
  30. @onlyif_cmds_exist('pandoc')
  31. def test_export(self):
  32. """
  33. Can a ASCIIDocExporter export something?
  34. """
  35. (output, resources) = ASCIIDocExporter().from_filename(self._get_notebook())
  36. assert len(output) > 0
  37. assert re.findall(in_regex, output)
  38. assert re.findall(out_regex, output)
  39. @onlyif_cmds_exist('pandoc')
  40. def test_export_no_prompt(self):
  41. """
  42. Can a ASCIIDocExporter export something without prompts?
  43. """
  44. no_prompt = {
  45. "TemplateExporter":{
  46. "exclude_input_prompt": True,
  47. "exclude_output_prompt": True,
  48. }
  49. }
  50. c_no_prompt = Config(no_prompt)
  51. exporter = ASCIIDocExporter(config=c_no_prompt)
  52. (output, resources) = exporter.from_filename(
  53. self._get_notebook(nb_name="prompt_numbers.ipynb"))
  54. assert not re.findall(in_regex, output)
  55. assert not re.findall(out_regex, output)