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