diff --git a/IPython/nbconvert/transformers/tests/base.py b/IPython/nbconvert/transformers/tests/base.py new file mode 100644 index 0000000..7ba15f4 --- /dev/null +++ b/IPython/nbconvert/transformers/tests/base.py @@ -0,0 +1,43 @@ +""" +Module with utility functions for transformer tests +""" + +#----------------------------------------------------------------------------- +# 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 ...tests.base import TestsBase + +from IPython.nbformat import current as nbformat + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class TransformerTestsBase(TestsBase): + """Contains test functions transformer tests""" + + + def build_notebook(self): + """Build a notebook in memory for use with transformer tests""" + + outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a"), + nbformat.new_output(output_type="text", output_text="b"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="c"), + nbformat.new_output(output_type="stream", stream="stdout", output_text="d"), + nbformat.new_output(output_type="stream", stream="stderr", output_text="e"), + nbformat.new_output(output_type="stream", stream="stderr", output_text="f")] + + cells=[nbformat.new_code_cell(input="test", + prompt_number=1,outputs=outputs)] + worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] + + return nbformat.new_notebook(name="notebook1", worksheets=worksheets) diff --git a/IPython/nbconvert/transformers/tests/test_coalescestreams.py b/IPython/nbconvert/transformers/tests/test_coalescestreams.py index 25d461f..1f69f93 100644 --- a/IPython/nbconvert/transformers/tests/test_coalescestreams.py +++ b/IPython/nbconvert/transformers/tests/test_coalescestreams.py @@ -14,32 +14,19 @@ Module with tests for the coalescestreams transformer # Imports #----------------------------------------------------------------------------- -from ...tests.base import TestsBase +from .base import TransformerTestsBase from ..coalescestreams import coalesce_streams -from IPython.nbformat import current as nbformat #----------------------------------------------------------------------------- # Class #----------------------------------------------------------------------------- -class TestCoalesceStreams(TestsBase): +class TestCoalesceStreams(TransformerTestsBase): """Contains test functions for coalescestreams.py""" - - def build_notebook(self): - outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a"), - nbformat.new_output(output_type="text", output_text="b"), - nbformat.new_output(output_type="stream", stream="stdout", output_text="c"), - nbformat.new_output(output_type="stream", stream="stdout", output_text="d"), - nbformat.new_output(output_type="stream", stream="stderr", output_text="e"), - nbformat.new_output(output_type="stream", stream="stderr", output_text="f")] - cells=[nbformat.new_code_cell(input="test", - prompt_number=1,outputs=outputs)] - worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] - return nbformat.new_notebook(name="notebook1", worksheets=worksheets) - def test_coalesce_streams(self): + """coalesce_streams transformer output test""" nb, res = coalesce_streams(self.build_notebook(), {}) self.assertEqual(nb.worksheets[0].cells[0].outputs[0].text, "a") self.assertEqual(nb.worksheets[0].cells[0].outputs[1].output_type, "text") diff --git a/IPython/nbconvert/transformers/tests/test_csshtmlheader.py b/IPython/nbconvert/transformers/tests/test_csshtmlheader.py new file mode 100644 index 0000000..237e8f6 --- /dev/null +++ b/IPython/nbconvert/transformers/tests/test_csshtmlheader.py @@ -0,0 +1,37 @@ +""" +Module with tests for the csshtmlheader transformer +""" + +#----------------------------------------------------------------------------- +# 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 TransformerTestsBase +from ..csshtmlheader import CSSHTMLHeaderTransformer + + +#----------------------------------------------------------------------------- +# Class +#----------------------------------------------------------------------------- + +class TestCSSHTMLHeader(TransformerTestsBase): + """Contains test functions for csshtmlheader.py""" + + def test_constructor(self): + """Can a CSSHTMLHeaderTransformer be constructed?""" + CSSHTMLHeaderTransformer() + + + def test_output(self): + """Test the output of the CSSHTMLHeaderTransformer""" + nb, res = CSSHTMLHeaderTransformer()(self.build_notebook(), {}) + assert 'inlining' in res + assert 'css' in res.inlining \ No newline at end of file