diff --git a/IPython/nbconvert/exporters/tests/base.py b/IPython/nbconvert/exporters/tests/base.py index 18ae21d..ee09ba4 100644 --- a/IPython/nbconvert/exporters/tests/base.py +++ b/IPython/nbconvert/exporters/tests/base.py @@ -1,6 +1,4 @@ -""" -Module with tests base for exporters -""" +"""Base TestCase class for testing Exporters""" #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. @@ -16,15 +14,35 @@ Module with tests base for exporters import os +from IPython.testing.decorators import onlyif_cmds_exist + from ...tests.base import TestsBase #----------------------------------------------------------------------------- # Class #----------------------------------------------------------------------------- +all_raw_formats = set(['markdown', 'html', 'rst', 'python', 'latex']) + class ExportersTestsBase(TestsBase): """Contains base test functions for exporters""" - - def _get_notebook(self): - return os.path.join(self._get_files_path(), 'notebook2.ipynb') - + + exporter_class = None + should_include_raw = None + + def _get_notebook(self, nb_name='notebook2.ipynb'): + return os.path.join(self._get_files_path(), nb_name) + + @onlyif_cmds_exist('pandoc') + def test_raw_cell_inclusion(self): + """test raw cell inclusion based on raw_format metadata""" + if self.should_include_raw is None: + return + exporter = self.exporter_class() + (output, resources) = exporter.from_filename(self._get_notebook('rawtest.ipynb')) + for inc in self.should_include_raw: + self.assertIn('raw %s' % inc, output, "should include %s" % inc) + self.assertIn('no raw_format metadata', output) + for exc in all_raw_formats.difference(self.should_include_raw): + self.assertNotIn('raw %s' % exc, output, "should exclude %s" % exc) + self.assertNotIn('never be included', output) diff --git a/IPython/nbconvert/exporters/tests/files/rawtest.ipynb b/IPython/nbconvert/exporters/tests/files/rawtest.ipynb new file mode 100644 index 0000000..c2a8b14 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/files/rawtest.ipynb @@ -0,0 +1,84 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "raw", + "metadata": { + "raw_format": "html" + }, + "source": [ + "raw html" + ] + }, + { + "cell_type": "raw", + "metadata": { + "raw_format": "markdown" + }, + "source": [ + "* raw markdown\n", + "* bullet\n", + "* list" + ] + }, + { + "cell_type": "raw", + "metadata": { + "raw_format": "rst" + }, + "source": [ + "``raw rst``\n", + "\n", + ".. sourcecode:: python\n", + "\n", + " def foo(): pass\n" + ] + }, + { + "cell_type": "raw", + "metadata": { + "raw_format": "python" + }, + "source": [ + "def bar():\n", + " \"\"\"raw python\"\"\"\n", + " pass" + ] + }, + { + "cell_type": "raw", + "metadata": { + "raw_format": "latex" + }, + "source": [ + "\\LaTeX\n", + "% raw latex" + ] + }, + { + "cell_type": "raw", + "metadata": {}, + "source": [ + "# no raw_format metadata, should be included by default" + ] + }, + { + "cell_type": "raw", + "metadata": { + "raw_format": "doesnotexist" + }, + "source": [ + "garbage format defined, should never be included" + ] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_html.py b/IPython/nbconvert/exporters/tests/test_html.py index 10c41ba..f2c9f6c 100644 --- a/IPython/nbconvert/exporters/tests/test_html.py +++ b/IPython/nbconvert/exporters/tests/test_html.py @@ -1,6 +1,4 @@ -""" -Module with tests for html.py -""" +"""Tests for HTMLExporter""" #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. @@ -23,7 +21,10 @@ from IPython.testing.decorators import onlyif_cmds_exist #----------------------------------------------------------------------------- class TestHTMLExporter(ExportersTestsBase): - """Contains test functions for html.py""" + """Tests for HTMLExporter""" + + exporter_class = HTMLExporter + should_include_raw = ['html'] def test_constructor(self): """ @@ -57,3 +58,4 @@ class TestHTMLExporter(ExportersTestsBase): """ (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook()) assert len(output) > 0 + diff --git a/IPython/nbconvert/exporters/tests/test_latex.py b/IPython/nbconvert/exporters/tests/test_latex.py index f1dc349..3ddc1b0 100644 --- a/IPython/nbconvert/exporters/tests/test_latex.py +++ b/IPython/nbconvert/exporters/tests/test_latex.py @@ -25,6 +25,9 @@ from IPython.testing.decorators import onlyif_cmds_exist class TestLatexExporter(ExportersTestsBase): """Contains test functions for latex.py""" + exporter_class = LatexExporter + should_include_raw = ['latex'] + def test_constructor(self): """ Can a LatexExporter be constructed? diff --git a/IPython/nbconvert/exporters/tests/test_markdown.py b/IPython/nbconvert/exporters/tests/test_markdown.py index 53a8126..1da8ed5 100644 --- a/IPython/nbconvert/exporters/tests/test_markdown.py +++ b/IPython/nbconvert/exporters/tests/test_markdown.py @@ -1,6 +1,4 @@ -""" -Module with tests for markdown.py -""" +"""Tests for MarkdownExporter""" #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. @@ -22,7 +20,10 @@ from ..markdown import MarkdownExporter #----------------------------------------------------------------------------- class TestMarkdownExporter(ExportersTestsBase): - """Contains test functions for markdown.py""" + """Tests for MarkdownExporter""" + + exporter_class = MarkdownExporter + should_include_raw = ['markdown', 'html'] def test_constructor(self): """ diff --git a/IPython/nbconvert/exporters/tests/test_python.py b/IPython/nbconvert/exporters/tests/test_python.py index 3fc4cf6..7798b81 100644 --- a/IPython/nbconvert/exporters/tests/test_python.py +++ b/IPython/nbconvert/exporters/tests/test_python.py @@ -1,6 +1,4 @@ -""" -Module with tests for python.py -""" +"""Tests for PythonExporter""" #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. @@ -22,7 +20,10 @@ from ..python import PythonExporter #----------------------------------------------------------------------------- class TestPythonExporter(ExportersTestsBase): - """Contains test functions for python.py""" + """Tests for PythonExporter""" + + exporter_class = PythonExporter + should_include_raw = ['python'] def test_constructor(self): """ diff --git a/IPython/nbconvert/exporters/tests/test_rst.py b/IPython/nbconvert/exporters/tests/test_rst.py index 6634f7b..99e3e76 100644 --- a/IPython/nbconvert/exporters/tests/test_rst.py +++ b/IPython/nbconvert/exporters/tests/test_rst.py @@ -1,6 +1,4 @@ -""" -Module with tests for rst.py -""" +"""Tests for RSTExporter""" #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. @@ -23,7 +21,10 @@ from IPython.testing.decorators import onlyif_cmds_exist #----------------------------------------------------------------------------- class TestRSTExporter(ExportersTestsBase): - """Contains test functions for rst.py""" + """Tests for RSTExporter""" + + exporter_class = RSTExporter + should_include_raw = ['rst'] def test_constructor(self): """ diff --git a/IPython/nbconvert/exporters/tests/test_slides.py b/IPython/nbconvert/exporters/tests/test_slides.py index 9b2c496..7c7d008 100644 --- a/IPython/nbconvert/exporters/tests/test_slides.py +++ b/IPython/nbconvert/exporters/tests/test_slides.py @@ -1,6 +1,4 @@ -""" -Module with tests for slides.py -""" +"""Tests for SlidesExporter""" #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. @@ -23,7 +21,10 @@ from IPython.testing.decorators import onlyif_cmds_exist #----------------------------------------------------------------------------- class TestSlidesExporter(ExportersTestsBase): - """Contains test functions for slides.py""" + """Tests for SlidesExporter""" + + exporter_class = SlidesExporter + should_include_raw = ['html'] def test_constructor(self): """