Show More
@@ -1,71 +1,101 | |||||
1 | """ |
|
1 | """Tests for Latex exporter""" | |
2 | Module with tests for latex.py |
|
|||
3 | """ |
|
|||
4 |
|
2 | |||
5 | #----------------------------------------------------------------------------- |
|
3 | # Copyright (c) IPython Development Team. | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
|||
7 | # |
|
|||
8 | # Distributed under the terms of the Modified BSD License. |
|
4 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
|||
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
5 | |||
13 | #----------------------------------------------------------------------------- |
|
6 | import os.path | |
14 | # Imports |
|
7 | import textwrap | |
15 | #----------------------------------------------------------------------------- |
|
|||
16 |
|
8 | |||
17 | from .base import ExportersTestsBase |
|
9 | from .base import ExportersTestsBase | |
18 | from ..latex import LatexExporter |
|
10 | from ..latex import LatexExporter | |
|
11 | from IPython.nbformat import current | |||
19 | from IPython.testing.decorators import onlyif_cmds_exist |
|
12 | from IPython.testing.decorators import onlyif_cmds_exist | |
|
13 | from IPython.utils.tempdir import TemporaryDirectory | |||
20 |
|
14 | |||
21 | #----------------------------------------------------------------------------- |
|
|||
22 | # Class |
|
|||
23 | #----------------------------------------------------------------------------- |
|
|||
24 |
|
15 | |||
25 | class TestLatexExporter(ExportersTestsBase): |
|
16 | class TestLatexExporter(ExportersTestsBase): | |
26 | """Contains test functions for latex.py""" |
|
17 | """Contains test functions for latex.py""" | |
27 |
|
18 | |||
28 | exporter_class = LatexExporter |
|
19 | exporter_class = LatexExporter | |
29 | should_include_raw = ['latex'] |
|
20 | should_include_raw = ['latex'] | |
30 |
|
21 | |||
31 | def test_constructor(self): |
|
22 | def test_constructor(self): | |
32 | """ |
|
23 | """ | |
33 | Can a LatexExporter be constructed? |
|
24 | Can a LatexExporter be constructed? | |
34 | """ |
|
25 | """ | |
35 | LatexExporter() |
|
26 | LatexExporter() | |
36 |
|
27 | |||
37 |
|
28 | |||
38 | @onlyif_cmds_exist('pandoc') |
|
29 | @onlyif_cmds_exist('pandoc') | |
39 | def test_export(self): |
|
30 | def test_export(self): | |
40 | """ |
|
31 | """ | |
41 | Can a LatexExporter export something? |
|
32 | Can a LatexExporter export something? | |
42 | """ |
|
33 | """ | |
43 | (output, resources) = LatexExporter().from_filename(self._get_notebook()) |
|
34 | (output, resources) = LatexExporter().from_filename(self._get_notebook()) | |
44 | assert len(output) > 0 |
|
35 | assert len(output) > 0 | |
45 |
|
36 | |||
46 |
|
37 | |||
47 | @onlyif_cmds_exist('pandoc') |
|
38 | @onlyif_cmds_exist('pandoc') | |
48 | def test_export_book(self): |
|
39 | def test_export_book(self): | |
49 | """ |
|
40 | """ | |
50 | Can a LatexExporter export using 'report' template? |
|
41 | Can a LatexExporter export using 'report' template? | |
51 | """ |
|
42 | """ | |
52 | (output, resources) = LatexExporter(template_file='report').from_filename(self._get_notebook()) |
|
43 | (output, resources) = LatexExporter(template_file='report').from_filename(self._get_notebook()) | |
53 | assert len(output) > 0 |
|
44 | assert len(output) > 0 | |
54 |
|
45 | |||
55 |
|
46 | |||
56 | @onlyif_cmds_exist('pandoc') |
|
47 | @onlyif_cmds_exist('pandoc') | |
57 | def test_export_basic(self): |
|
48 | def test_export_basic(self): | |
58 | """ |
|
49 | """ | |
59 | Can a LatexExporter export using 'article' template? |
|
50 | Can a LatexExporter export using 'article' template? | |
60 | """ |
|
51 | """ | |
61 | (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook()) |
|
52 | (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook()) | |
62 | assert len(output) > 0 |
|
53 | assert len(output) > 0 | |
63 |
|
54 | |||
64 |
|
55 | |||
65 | @onlyif_cmds_exist('pandoc') |
|
56 | @onlyif_cmds_exist('pandoc') | |
66 | def test_export_article(self): |
|
57 | def test_export_article(self): | |
67 | """ |
|
58 | """ | |
68 | Can a LatexExporter export using 'article' template? |
|
59 | Can a LatexExporter export using 'article' template? | |
69 | """ |
|
60 | """ | |
70 | (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook()) |
|
61 | (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook()) | |
71 | assert len(output) > 0 |
|
62 | assert len(output) > 0 | |
|
63 | ||||
|
64 | @onlyif_cmds_exist('pandoc') | |||
|
65 | def test_very_long_cells(self): | |||
|
66 | """ | |||
|
67 | Torture test that long cells do not cause issues | |||
|
68 | """ | |||
|
69 | lorem_ipsum_text = textwrap.dedent("""\ | |||
|
70 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec | |||
|
71 | dignissim, ipsum non facilisis tempus, dui felis tincidunt metus, | |||
|
72 | nec pulvinar neque odio eget risus. Nulla nisi lectus, cursus | |||
|
73 | suscipit interdum at, ultrices sit amet orci. Mauris facilisis | |||
|
74 | imperdiet elit, vitae scelerisque ipsum dignissim non. Integer | |||
|
75 | consequat malesuada neque sit amet pulvinar. Curabitur pretium | |||
|
76 | ut turpis eget aliquet. Maecenas sagittis lacus sed lectus | |||
|
77 | volutpat, eu adipiscing purus pulvinar. Maecenas consequat | |||
|
78 | luctus urna, eget cursus quam mollis a. Aliquam vitae ornare | |||
|
79 | erat, non hendrerit urna. Sed eu diam nec massa egestas pharetra | |||
|
80 | at nec tellus. Fusce feugiat lacus quis urna sollicitudin volutpat. | |||
|
81 | Quisque at sapien non nibh feugiat tempus ac ultricies purus. | |||
|
82 | """) | |||
|
83 | lorem_ipsum_text = lorem_ipsum_text.replace("\n"," ") + "\n\n" | |||
|
84 | large_lorem_ipsum_text = "".join([lorem_ipsum_text]*3000) | |||
|
85 | ||||
|
86 | notebook_name = "lorem_ipsum_long.ipynb" | |||
|
87 | nb = current.new_notebook( | |||
|
88 | worksheets=[ | |||
|
89 | current.new_worksheet(cells=[ | |||
|
90 | current.new_text_cell('markdown',source=large_lorem_ipsum_text) | |||
|
91 | ]) | |||
|
92 | ] | |||
|
93 | ) | |||
|
94 | ||||
|
95 | with TemporaryDirectory() as td: | |||
|
96 | nbfile = os.path.join(td, notebook_name) | |||
|
97 | with open(nbfile, 'w') as f: | |||
|
98 | current.write(nb, f, 'ipynb') | |||
|
99 | ||||
|
100 | (output, resources) = LatexExporter(template_file='article').from_filename(nbfile) | |||
|
101 | assert len(output) > 0 |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now