From aa7fe5b099d3da5c5efbbe0146a968428dd94ad6 2014-05-16 16:13:29 From: Thomas Kluyver Date: 2014-05-16 16:13:29 Subject: [PATCH] Rework Latex test for nbconvert Python API Also, skip it if pandoc is not available --- diff --git a/IPython/nbconvert/exporters/tests/test_latex.py b/IPython/nbconvert/exporters/tests/test_latex.py index 3ddc1b0..a6effc9 100644 --- a/IPython/nbconvert/exporters/tests/test_latex.py +++ b/IPython/nbconvert/exporters/tests/test_latex.py @@ -1,26 +1,17 @@ -""" -Module with tests for latex.py -""" +"""Tests for Latex exporter""" -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# +# Copyright (c) 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.path +import textwrap from .base import ExportersTestsBase from ..latex import LatexExporter +from IPython.nbformat import current from IPython.testing.decorators import onlyif_cmds_exist +from IPython.utils.tempdir import TemporaryDirectory -#----------------------------------------------------------------------------- -# Class -#----------------------------------------------------------------------------- class TestLatexExporter(ExportersTestsBase): """Contains test functions for latex.py""" @@ -68,4 +59,43 @@ class TestLatexExporter(ExportersTestsBase): Can a LatexExporter export using 'article' template? """ (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook()) - assert len(output) > 0 \ No newline at end of file + assert len(output) > 0 + + @onlyif_cmds_exist('pandoc') + def test_very_long_cells(self): + """ + Torture test that long cells do not cause issues + """ + lorem_ipsum_text = textwrap.dedent("""\ + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec + dignissim, ipsum non facilisis tempus, dui felis tincidunt metus, + nec pulvinar neque odio eget risus. Nulla nisi lectus, cursus + suscipit interdum at, ultrices sit amet orci. Mauris facilisis + imperdiet elit, vitae scelerisque ipsum dignissim non. Integer + consequat malesuada neque sit amet pulvinar. Curabitur pretium + ut turpis eget aliquet. Maecenas sagittis lacus sed lectus + volutpat, eu adipiscing purus pulvinar. Maecenas consequat + luctus urna, eget cursus quam mollis a. Aliquam vitae ornare + erat, non hendrerit urna. Sed eu diam nec massa egestas pharetra + at nec tellus. Fusce feugiat lacus quis urna sollicitudin volutpat. + Quisque at sapien non nibh feugiat tempus ac ultricies purus. + """) + lorem_ipsum_text = lorem_ipsum_text.replace("\n"," ") + "\n\n" + large_lorem_ipsum_text = "".join([lorem_ipsum_text]*3000) + + notebook_name = "lorem_ipsum_long.ipynb" + nb = current.new_notebook( + worksheets=[ + current.new_worksheet(cells=[ + current.new_text_cell('markdown',source=large_lorem_ipsum_text) + ]) + ] + ) + + with TemporaryDirectory() as td: + nbfile = os.path.join(td, notebook_name) + with open(nbfile, 'w') as f: + current.write(nb, f, 'ipynb') + + (output, resources) = LatexExporter(template_file='article').from_filename(nbfile) + assert len(output) > 0 diff --git a/IPython/nbconvert/tests/test_latex.py b/IPython/nbconvert/tests/test_latex.py deleted file mode 100644 index 41d5083..0000000 --- a/IPython/nbconvert/tests/test_latex.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -"""Test Latex in NbConvertApp""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2013 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -import os -import textwrap -from IPython.nbformat import current - -from .base import TestsBase - -#----------------------------------------------------------------------------- -# Classes and functions -#----------------------------------------------------------------------------- - -class TestNbConvertLatex(TestsBase): - """Collection of NbConvert Latex tests""" - - def test_very_long_cells(self): - """ - Torture test that long cells do not cause issues - """ - lorem_ipsum_text = textwrap.dedent("""\ - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec - dignissim, ipsum non facilisis tempus, dui felis tincidunt metus, - nec pulvinar neque odio eget risus. Nulla nisi lectus, cursus - suscipit interdum at, ultrices sit amet orci. Mauris facilisis - imperdiet elit, vitae scelerisque ipsum dignissim non. Integer - consequat malesuada neque sit amet pulvinar. Curabitur pretium - ut turpis eget aliquet. Maecenas sagittis lacus sed lectus - volutpat, eu adipiscing purus pulvinar. Maecenas consequat - luctus urna, eget cursus quam mollis a. Aliquam vitae ornare - erat, non hendrerit urna. Sed eu diam nec massa egestas pharetra - at nec tellus. Fusce feugiat lacus quis urna sollicitudin volutpat. - Quisque at sapien non nibh feugiat tempus ac ultricies purus. - """) - lorem_ipsum_text = lorem_ipsum_text.replace("\n"," ") + "\n\n" - large_lorem_ipsum_text = "".join([lorem_ipsum_text]*3000) - - notebook_name = "lorem_ipsum_long.ipynb" - tex_name = "lorem_ipsum_long.tex" - with self.create_temp_cwd([]): - nb = current.new_notebook( - worksheets=[ - current.new_worksheet(cells=[ - current.new_text_cell('markdown',source=large_lorem_ipsum_text) - ]) - ] - ) - with open(notebook_name, 'w') as f: current.write(nb, f, 'ipynb') - self.call('nbconvert --to latex --log-level 0 ' + - os.path.join(notebook_name)) - assert os.path.isfile(tex_name) - -