diff --git a/IPython/nbconvert/exporters/tests/__init__.py b/IPython/nbconvert/exporters/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/__init__.py diff --git a/IPython/nbconvert/exporters/tests/base.py b/IPython/nbconvert/exporters/tests/base.py new file mode 100644 index 0000000..5501b8c --- /dev/null +++ b/IPython/nbconvert/exporters/tests/base.py @@ -0,0 +1,30 @@ +""" +Module with tests base for exporters +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os + +from ...tests.base import TestsBase + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class ExportersTestsBase(TestsBase): + """Contains base test functions for exporters""" + + def _get_notebook(self): + return os.path.join(self._get_files_path(), 'notebook2.ipynb') + \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/cheese.py b/IPython/nbconvert/exporters/tests/cheese.py new file mode 100644 index 0000000..9ca280e --- /dev/null +++ b/IPython/nbconvert/exporters/tests/cheese.py @@ -0,0 +1,48 @@ +""" +Contains CheeseTransformer +""" +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from ...transformers.base import ConfigurableTransformer + +#----------------------------------------------------------------------------- +# Classes +#----------------------------------------------------------------------------- + +class CheeseTransformer(ConfigurableTransformer): + """ + Adds a cheese tag to the resources object + """ + + + def __init__(self, **kw): + """ + Public constructor + """ + super(CheeseTransformer, self).__init__(**kw) + + + def call(self, nb, resources): + """ + Sphinx transformation to apply on each notebook. + + Parameters + ---------- + nb : NotebookNode + Notebook being converted + resources : dictionary + Additional resources used in the conversion process. Allows + transformers to pass variables into the Jinja engine. + """ + resources['cheese'] = 'real' + return nb, resources diff --git a/IPython/nbconvert/exporters/tests/files/notebook2.ipynb b/IPython/nbconvert/exporters/tests/files/notebook2.ipynb new file mode 100644 index 0000000..a7fe1a5 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/files/notebook2.ipynb @@ -0,0 +1,177 @@ +{ + "metadata": { + "name": "notebook2" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "NumPy and Matplotlib examples" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First import NumPy and Matplotlib:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "%pylab inline" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].\n", + "For more information, type 'help(pylab)'.\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import numpy as np" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we show some very basic examples of how they can be used." + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = np.random.uniform(size=(100,100))" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a.shape" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 7, + "text": [ + "(100, 100)" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "evs = np.linalg.eigvals(a)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "evs.shape" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 10, + "text": [ + "(100,)" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here is a cell that has both text and PNG output:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "hist(evs.real)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 14, + "text": [ + "(array([95, 4, 0, 0, 0, 0, 0, 0, 0, 1]),\n", + " array([ -2.93566063, 2.35937011, 7.65440086, 12.9494316 ,\n", + " 18.24446235, 23.53949309, 28.83452384, 34.12955458,\n", + " 39.42458533, 44.71961607, 50.01464682]),\n", + " )" + ] + }, + { + "metadata": {}, + "output_type": "display_data", + "png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAD9CAYAAAC2l2x5AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEhdJREFUeJzt3X1olfX/x/HXtVbT8CZDmsK6KmrubEu3U2xnZOpxLBnG\nOqsIE7RoE3QRZkT/yEAjcIh/LIs6i/BEGSU1CkxT0+pkFp1zMmsxZ5uUTIXoxm95lmdlef3+8Nep\ndbtz7exs16fnAw7sXNs5n/c14nmurl3naDmO4wgAYJy8sR4AADA6CDwAGIrAA4ChCDwAGIrAA4Ch\nCDwAGOofA9/U1KTCwkLNnj07vS2ZTCoUCsm2bTU2NmpgYCD9vccee0zFxcUqKyvTgQMHRm9qAMC/\n+sfA33PPPdq9e/eQbeFwWLZtq6+vT0VFRero6JAkffXVV3ryySf15ptvKhwOa/Xq1aM3NQDgX/1j\n4OfNm6dp06YN2RaPx9Xc3KyCggI1NTUpFotJkmKxmOrr62XbthYsWCDHcZRMJkdvcgDAP8r4HHwi\nkZDP55Mk+Xw+xeNxSecDX1pamv65kpKS9PcAALmXn+kDMvlkA8uyhrUNAPDvMv1kmYyP4Ku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XPntHPnTtXV\n1bmb38mBV155xSkqKnImTJjgFBYWOvX19envPfroo87VV1/tlJaWOvv378/FOK5Eo1HH5/M5V199\ntbN58+axHudf3Xnnnc7MmTOdiy66yCkqKnIikYhz+vRp55ZbbnEuv/xyJxQKOclkcqzH/Fvvvvuu\nY1mWU1FR4VRWVjqVlZXOrl27PLMPXV1djt/vd+bMmeMsWrTIefbZZx3HcTwz/6+i0ajT0NDgOI53\nZv/888+diooKp6KiwqmtrXW2bNniOI535nccx/nss8+cQCDgVFRUOA8++KAzMDDgav6c/5usAIDc\n4F90AgBDEXgAMBSBBwBDEXgAMBSBBwBDEXgAMNT/AQKseNIf7mhWAAAAAElFTkSuQmCC\n", + "text": [ + "" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_basichtml.py b/IPython/nbconvert/exporters/tests/test_basichtml.py new file mode 100644 index 0000000..2c8ce64 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_basichtml.py @@ -0,0 +1,39 @@ +""" +Module with tests for basichtml.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..basichtml import BasicHTMLExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_BasicHTMLExporter(ExportersTestsBase): + """Contains test functions for basichtml.py""" + + def test_constructor(self): + """ + Can a BasicHTMLExporter be constructed? + """ + BasicHTMLExporter() + + + def test_export(self): + """ + Can a BasicHTMLExporter export something? + """ + (output, resources) = BasicHTMLExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_export.py b/IPython/nbconvert/exporters/tests/test_export.py new file mode 100644 index 0000000..4a03d74 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_export.py @@ -0,0 +1,102 @@ +""" +Module with tests for export.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os + +from IPython.nbformat import current as nbformat + +from .base import ExportersTestsBase +from ..export import * +from ..python import PythonExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_Export(ExportersTestsBase): + """Contains test functions for export.py""" + + + def test_export_wrong_name(self): + """ + Is the right error thrown when a bad template name is used? + """ + try: + export_by_name('not_a_name', self._get_notebook()) + except ExporterNameError as e: + pass + + + def test_export_filename(self): + """ + Can a notebook be exported by filename? + """ + (output, resources) = export_by_name('python', self._get_notebook()) + assert len(output) > 0 + + + def test_export_nbnode(self): + """ + Can a notebook be exported by a notebook node handle? + """ + with open(self._get_notebook(), 'r') as f: + notebook = nbformat.read(f, 'json') + (output, resources) = export_by_name('python', notebook) + assert len(output) > 0 + + + def test_export_filestream(self): + """ + Can a notebook be exported by a filesteam? + """ + with open(self._get_notebook(), 'r') as f: + (output, resources) = export_by_name('python', f) + assert len(output) > 0 + + + def test_export_using_exporter(self): + """ + Can a notebook be exported using an instanciated exporter? + """ + (output, resources) = export(PythonExporter(), self._get_notebook()) + assert len(output) > 0 + + + def test_export_using_exporter_class(self): + """ + Can a notebook be exported using an exporter class type? + """ + (output, resources) = export(PythonExporter, self._get_notebook()) + assert len(output) > 0 + + + def test_export_resources(self): + """ + Can a notebook be exported along with a custom resources dict? + """ + (output, resources) = export(PythonExporter, self._get_notebook(), resources={}) + assert len(output) > 0 + + + def test_no_exporter(self): + """ + Is the right error thrown if no exporter is provided? + """ + try: + (output, resources) = export(None, self._get_notebook()) + except TypeError: + pass + \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_exporter.py b/IPython/nbconvert/exporters/tests/test_exporter.py new file mode 100644 index 0000000..6e45762 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_exporter.py @@ -0,0 +1,113 @@ +""" +Module with tests for exporter.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from IPython.config import Config + +from .base import ExportersTestsBase +from .cheese import CheeseTransformer +from ..exporter import Exporter + + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_Exporter(ExportersTestsBase): + """Contains test functions for exporter.py""" + + + def test_constructor(self): + """ + Can an Exporter be constructed? + """ + Exporter() + + + def test_export(self): + """ + Can an Exporter export something? + """ + exporter = self._make_exporter() + (output, resources) = exporter.from_filename(self._get_notebook()) + assert len(output) > 0 + + + def test_extract_figures(self): + """ + If the ExtractFigureTransformer is enabled, are figures extracted? + """ + config = Config({'ExtractFigureTransformer': {'enabled': True}}) + exporter = self._make_exporter(config=config) + (output, resources) = exporter.from_filename(self._get_notebook()) + assert resources is not None + assert 'figures' in resources + assert len(resources['figures']) > 0 + + + def test_transformer_class(self): + """ + Can a transformer be added to the transformers list by class type? + """ + config = Config({'Exporter': {'transformers': [CheeseTransformer]}}) + exporter = self._make_exporter(config=config) + (output, resources) = exporter.from_filename(self._get_notebook()) + assert resources is not None + assert 'cheese' in resources + assert resources['cheese'] == 'real' + + + def test_transformer_instance(self): + """ + Can a transformer be added to the transformers list by instance? + """ + config = Config({'Exporter': {'transformers': [CheeseTransformer()]}}) + exporter = self._make_exporter(config=config) + (output, resources) = exporter.from_filename(self._get_notebook()) + assert resources is not None + assert 'cheese' in resources + assert resources['cheese'] == 'real' + + + def test_transformer_dottedobjectname(self): + """ + Can a transformer be added to the transformers list by dotted object name? + """ + config = Config({'Exporter': {'transformers': ['IPython.nbconvert.exporters.tests.cheese.CheeseTransformer']}}) + exporter = self._make_exporter(config=config) + (output, resources) = exporter.from_filename(self._get_notebook()) + assert resources is not None + assert 'cheese' in resources + assert resources['cheese'] == 'real' + + + def test_transformer_via_method(self): + """ + Can a transformer be added via the Exporter convinience method? + """ + exporter = self._make_exporter() + exporter.register_transformer(CheeseTransformer, enabled=True) + (output, resources) = exporter.from_filename(self._get_notebook()) + assert resources is not None + assert 'cheese' in resources + assert resources['cheese'] == 'real' + + + def _make_exporter(self, config=None): + #Create the exporter instance, make sure to set a template name since + #the base Exporter doesn't have a template associated with it. + exporter = Exporter(config=config) + exporter.template_file = 'python' + return exporter \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_fullhtml.py b/IPython/nbconvert/exporters/tests/test_fullhtml.py new file mode 100644 index 0000000..01b77c0 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_fullhtml.py @@ -0,0 +1,39 @@ +""" +Module with tests for fullhtml.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..fullhtml import FullHTMLExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_FullHTMLExporter(ExportersTestsBase): + """Contains test functions for fullhtml.py""" + + def test_constructor(self): + """ + Can a FullHTMLExporter be constructed? + """ + FullHTMLExporter() + + + def test_export(self): + """ + Can a FullHTMLExporter export something? + """ + (output, resources) = FullHTMLExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_latex.py b/IPython/nbconvert/exporters/tests/test_latex.py new file mode 100644 index 0000000..882bf6f --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_latex.py @@ -0,0 +1,39 @@ +""" +Module with tests for latex.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..latex import LatexExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_LatexExporter(ExportersTestsBase): + """Contains test functions for latex.py""" + + def test_constructor(self): + """ + Can a LatexExporter be constructed? + """ + LatexExporter() + + + def test_export(self): + """ + Can a LatexExporter export something? + """ + (output, resources) = LatexExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_markdown.py b/IPython/nbconvert/exporters/tests/test_markdown.py new file mode 100644 index 0000000..1735324 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_markdown.py @@ -0,0 +1,39 @@ +""" +Module with tests for markdown.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..markdown import MarkdownExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_MarkdownExporter(ExportersTestsBase): + """Contains test functions for markdown.py""" + + def test_constructor(self): + """ + Can a MarkdownExporter be constructed? + """ + MarkdownExporter() + + + def test_export(self): + """ + Can a MarkdownExporter export something? + """ + (output, resources) = MarkdownExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_python.py b/IPython/nbconvert/exporters/tests/test_python.py new file mode 100644 index 0000000..2fc1209 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_python.py @@ -0,0 +1,39 @@ +""" +Module with tests for python.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..python import PythonExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_PythonExporter(ExportersTestsBase): + """Contains test functions for python.py""" + + def test_constructor(self): + """ + Can a PythonExporter be constructed? + """ + PythonExporter() + + + def test_export(self): + """ + Can a PythonExporter export something? + """ + (output, resources) = PythonExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_reveal.py b/IPython/nbconvert/exporters/tests/test_reveal.py new file mode 100644 index 0000000..9adf45d --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_reveal.py @@ -0,0 +1,39 @@ +""" +Module with tests for reveal.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..reveal import RevealExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_RevealExporter(ExportersTestsBase): + """Contains test functions for reveal.py""" + + def test_constructor(self): + """ + Can a RevealExporter be constructed? + """ + RevealExporter() + + + def test_export(self): + """ + Can a RevealExporter export something? + """ + (output, resources) = RevealExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_rst.py b/IPython/nbconvert/exporters/tests/test_rst.py new file mode 100644 index 0000000..51909d1 --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_rst.py @@ -0,0 +1,39 @@ +""" +Module with tests for rst.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..rst import RstExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_RstExporter(ExportersTestsBase): + """Contains test functions for rst.py""" + + def test_constructor(self): + """ + Can a RstExporter be constructed? + """ + RstExporter() + + + def test_export(self): + """ + Can a RstExporter export something? + """ + (output, resources) = RstExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_sphinx_howto.py b/IPython/nbconvert/exporters/tests/test_sphinx_howto.py new file mode 100644 index 0000000..9444c7c --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_sphinx_howto.py @@ -0,0 +1,39 @@ +""" +Module with tests for sphinx_howto.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..sphinx_howto import SphinxHowtoExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_SphinxHowtoExporter(ExportersTestsBase): + """Contains test functions for sphinx_howto.py""" + + def test_constructor(self): + """ + Can a SphinxHowtoExporter be constructed? + """ + SphinxHowtoExporter() + + + def test_export(self): + """ + Can a SphinxHowtoExporter export something? + """ + (output, resources) = SphinxHowtoExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file diff --git a/IPython/nbconvert/exporters/tests/test_sphinx_manual.py b/IPython/nbconvert/exporters/tests/test_sphinx_manual.py new file mode 100644 index 0000000..995856e --- /dev/null +++ b/IPython/nbconvert/exporters/tests/test_sphinx_manual.py @@ -0,0 +1,39 @@ +""" +Module with tests for sphinx_manual.py +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .base import ExportersTestsBase +from ..sphinx_manual import SphinxManualExporter + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class Test_SphinxManualExporter(ExportersTestsBase): + """Contains test functions for sphinx_manual.py""" + + def test_constructor(self): + """ + Can a SphinxManualExporter be constructed? + """ + SphinxManualExporter() + + + def test_export(self): + """ + Can a SphinxManualExporter export something? + """ + (output, resources) = SphinxManualExporter().from_filename(self._get_notebook()) + assert len(output) > 0 \ No newline at end of file