Show More
@@ -1,61 +1,61 b'' | |||
|
1 | 1 | """Tests for HTMLExporter""" |
|
2 | 2 | |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (c) 2013, the IPython Development Team. |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the Modified BSD License. |
|
7 | 7 | # |
|
8 | 8 | # The full license is in the file COPYING.txt, distributed with this software. |
|
9 | 9 | #----------------------------------------------------------------------------- |
|
10 | 10 | |
|
11 | 11 | #----------------------------------------------------------------------------- |
|
12 | 12 | # Imports |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | from .base import ExportersTestsBase |
|
16 | 16 | from ..html import HTMLExporter |
|
17 | 17 | from IPython.testing.decorators import onlyif_cmds_exist |
|
18 | 18 | |
|
19 | 19 | #----------------------------------------------------------------------------- |
|
20 | 20 | # Class |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | |
|
23 | 23 | class TestHTMLExporter(ExportersTestsBase): |
|
24 | 24 | """Tests for HTMLExporter""" |
|
25 | 25 | |
|
26 | 26 | exporter_class = HTMLExporter |
|
27 | 27 | should_include_raw = ['html'] |
|
28 | 28 | |
|
29 | 29 | def test_constructor(self): |
|
30 | 30 | """ |
|
31 | 31 | Can a HTMLExporter be constructed? |
|
32 | 32 | """ |
|
33 | 33 | HTMLExporter() |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | @onlyif_cmds_exist('pandoc') |
|
37 | 37 | def test_export(self): |
|
38 | 38 | """ |
|
39 | 39 | Can a HTMLExporter export something? |
|
40 | 40 | """ |
|
41 | 41 | (output, resources) = HTMLExporter().from_filename(self._get_notebook()) |
|
42 | 42 | assert len(output) > 0 |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | @onlyif_cmds_exist('pandoc') |
|
46 | 46 | def test_export_basic(self): |
|
47 | 47 | """ |
|
48 | 48 | Can a HTMLExporter export using the 'basic' template? |
|
49 | 49 | """ |
|
50 | (output, resources) = HTMLExporter(template_file='basic').from_filename(self._get_notebook()) | |
|
50 | (output, resources) = HTMLExporter(template_file='html_basic').from_filename(self._get_notebook()) | |
|
51 | 51 | assert len(output) > 0 |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | @onlyif_cmds_exist('pandoc') |
|
55 | 55 | def test_export_full(self): |
|
56 | 56 | """ |
|
57 | 57 | Can a HTMLExporter export using the 'full' template? |
|
58 | 58 | """ |
|
59 | (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook()) | |
|
59 | (output, resources) = HTMLExporter(template_file='html_full').from_filename(self._get_notebook()) | |
|
60 | 60 | assert len(output) > 0 |
|
61 | 61 |
@@ -1,51 +1,51 b'' | |||
|
1 | 1 | """Tests for SlidesExporter""" |
|
2 | 2 | |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (c) 2013, the IPython Development Team. |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the Modified BSD License. |
|
7 | 7 | # |
|
8 | 8 | # The full license is in the file COPYING.txt, distributed with this software. |
|
9 | 9 | #----------------------------------------------------------------------------- |
|
10 | 10 | |
|
11 | 11 | #----------------------------------------------------------------------------- |
|
12 | 12 | # Imports |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | from .base import ExportersTestsBase |
|
16 | 16 | from ..slides import SlidesExporter |
|
17 | 17 | from IPython.testing.decorators import onlyif_cmds_exist |
|
18 | 18 | |
|
19 | 19 | #----------------------------------------------------------------------------- |
|
20 | 20 | # Class |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | |
|
23 | 23 | class TestSlidesExporter(ExportersTestsBase): |
|
24 | 24 | """Tests for SlidesExporter""" |
|
25 | 25 | |
|
26 | 26 | exporter_class = SlidesExporter |
|
27 | 27 | should_include_raw = ['html'] |
|
28 | 28 | |
|
29 | 29 | def test_constructor(self): |
|
30 | 30 | """ |
|
31 | 31 | Can a SlidesExporter be constructed? |
|
32 | 32 | """ |
|
33 | 33 | SlidesExporter() |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | @onlyif_cmds_exist('pandoc') |
|
37 | 37 | def test_export(self): |
|
38 | 38 | """ |
|
39 | 39 | Can a SlidesExporter export something? |
|
40 | 40 | """ |
|
41 | 41 | (output, resources) = SlidesExporter().from_filename(self._get_notebook()) |
|
42 | 42 | assert len(output) > 0 |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | @onlyif_cmds_exist('pandoc') |
|
46 | 46 | def test_export_reveal(self): |
|
47 | 47 | """ |
|
48 | 48 | Can a SlidesExporter export using the 'reveal' template? |
|
49 | 49 | """ |
|
50 | (output, resources) = SlidesExporter(template_file='reveal').from_filename(self._get_notebook()) | |
|
50 | (output, resources) = SlidesExporter(template_file='slides_reveal').from_filename(self._get_notebook()) | |
|
51 | 51 | assert len(output) > 0 |
@@ -1,185 +1,185 b'' | |||
|
1 | 1 | """Test NbConvertApp""" |
|
2 | 2 | |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (C) 2013 The IPython Development Team |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the BSD License. The full license is in |
|
7 | 7 | # the file COPYING, distributed as part of this software. |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | import os |
|
15 | 15 | import glob |
|
16 | 16 | import sys |
|
17 | 17 | |
|
18 | 18 | from .base import TestsBase |
|
19 | 19 | |
|
20 | 20 | import IPython.testing.tools as tt |
|
21 | 21 | from IPython.testing import decorators as dec |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | # Constants |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | #----------------------------------------------------------------------------- |
|
30 | 30 | # Classes and functions |
|
31 | 31 | #----------------------------------------------------------------------------- |
|
32 | 32 | |
|
33 | 33 | class TestNbConvertApp(TestsBase): |
|
34 | 34 | """Collection of NbConvertApp tests""" |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | def test_notebook_help(self): |
|
38 | 38 | """Will help show if no notebooks are specified?""" |
|
39 | 39 | with self.create_temp_cwd(): |
|
40 | 40 | out, err = self.call('nbconvert --log-level 0', ignore_return_code=True) |
|
41 | 41 | self.assertIn("see '--help-all'", out) |
|
42 | 42 | |
|
43 | 43 | def test_help_output(self): |
|
44 | 44 | """ipython nbconvert --help-all works""" |
|
45 | 45 | tt.help_all_output_test('nbconvert') |
|
46 | 46 | |
|
47 | 47 | def test_glob(self): |
|
48 | 48 | """ |
|
49 | 49 | Do search patterns work for notebook names? |
|
50 | 50 | """ |
|
51 | 51 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
52 | 52 | self.call('nbconvert --to python *.ipynb --log-level 0') |
|
53 | 53 | assert os.path.isfile('notebook1.py') |
|
54 | 54 | assert os.path.isfile('notebook2.py') |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | def test_glob_subdir(self): |
|
58 | 58 | """ |
|
59 | 59 | Do search patterns work for subdirectory notebook names? |
|
60 | 60 | """ |
|
61 | 61 | with self.create_temp_cwd(): |
|
62 | 62 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') |
|
63 | 63 | self.call('nbconvert --to python --log-level 0 ' + |
|
64 | 64 | os.path.join('subdir', '*.ipynb')) |
|
65 | 65 | assert os.path.isfile('notebook1.py') |
|
66 | 66 | assert os.path.isfile('notebook2.py') |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | def test_explicit(self): |
|
70 | 70 | """ |
|
71 | 71 | Do explicit notebook names work? |
|
72 | 72 | """ |
|
73 | 73 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
74 | 74 | self.call('nbconvert --log-level 0 --to python notebook2') |
|
75 | 75 | assert not os.path.isfile('notebook1.py') |
|
76 | 76 | assert os.path.isfile('notebook2.py') |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | @dec.onlyif_cmds_exist('pdflatex') |
|
80 | 80 | @dec.onlyif_cmds_exist('pandoc') |
|
81 | 81 | def test_filename_spaces(self): |
|
82 | 82 | """ |
|
83 | 83 | Generate PDFs with graphics if notebooks have spaces in the name? |
|
84 | 84 | """ |
|
85 | 85 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
86 | 86 | os.rename('notebook2.ipynb', 'notebook with spaces.ipynb') |
|
87 | 87 | o,e = self.call('nbconvert --log-level 0 --to latex ' |
|
88 | 88 | '"notebook with spaces" --post PDF ' |
|
89 | 89 | '--PDFPostProcessor.verbose=True') |
|
90 | 90 | assert os.path.isfile('notebook with spaces.tex') |
|
91 | 91 | assert os.path.isdir('notebook with spaces_files') |
|
92 | 92 | assert os.path.isfile('notebook with spaces.pdf') |
|
93 | 93 | |
|
94 | 94 | @dec.onlyif_cmds_exist('pdflatex') |
|
95 | 95 | @dec.onlyif_cmds_exist('pandoc') |
|
96 | 96 | def test_post_processor(self): |
|
97 | 97 | """ |
|
98 | 98 | Do post processors work? |
|
99 | 99 | """ |
|
100 | 100 | with self.create_temp_cwd(['notebook1.ipynb']): |
|
101 | 101 | self.call('nbconvert --log-level 0 --to latex notebook1 ' |
|
102 | 102 | '--post PDF --PDFPostProcessor.verbose=True') |
|
103 | 103 | assert os.path.isfile('notebook1.tex') |
|
104 | 104 | assert os.path.isfile('notebook1.pdf') |
|
105 | 105 | |
|
106 | 106 | @dec.onlyif_cmds_exist('pandoc') |
|
107 | 107 | def test_spurious_cr(self): |
|
108 | 108 | """Check for extra CR characters""" |
|
109 | 109 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
110 | 110 | self.call('nbconvert --log-level 0 --to latex notebook2') |
|
111 | 111 | assert os.path.isfile('notebook2.tex') |
|
112 | 112 | with open('notebook2.tex') as f: |
|
113 | 113 | tex = f.read() |
|
114 | 114 | self.call('nbconvert --log-level 0 --to html notebook2') |
|
115 | 115 | assert os.path.isfile('notebook2.html') |
|
116 | 116 | with open('notebook2.html') as f: |
|
117 | 117 | html = f.read() |
|
118 | 118 | self.assertEqual(tex.count('\r'), tex.count('\r\n')) |
|
119 | 119 | self.assertEqual(html.count('\r'), html.count('\r\n')) |
|
120 | 120 | |
|
121 | 121 | @dec.onlyif_cmds_exist('pandoc') |
|
122 | 122 | def test_png_base64_html_ok(self): |
|
123 | 123 | """Is embedded png data well formed in HTML?""" |
|
124 | 124 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
125 | 125 | self.call('nbconvert --log-level 0 --to HTML ' |
|
126 | 'notebook2.ipynb --template full') | |
|
126 | 'notebook2.ipynb --template html_full') | |
|
127 | 127 | assert os.path.isfile('notebook2.html') |
|
128 | 128 | with open('notebook2.html') as f: |
|
129 | 129 | assert "data:image/png;base64,b'" not in f.read() |
|
130 | 130 | |
|
131 | 131 | @dec.onlyif_cmds_exist('pandoc') |
|
132 | 132 | def test_template(self): |
|
133 | 133 | """ |
|
134 | 134 | Do export templates work? |
|
135 | 135 | """ |
|
136 | 136 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
137 | 137 | self.call('nbconvert --log-level 0 --to slides ' |
|
138 | 'notebook2.ipynb --template reveal') | |
|
138 | 'notebook2.ipynb --template slides_reveal') | |
|
139 | 139 | assert os.path.isfile('notebook2.slides.html') |
|
140 | 140 | with open('notebook2.slides.html') as f: |
|
141 | 141 | assert '/reveal.css' in f.read() |
|
142 | 142 | |
|
143 | 143 | |
|
144 | 144 | def test_glob_explicit(self): |
|
145 | 145 | """ |
|
146 | 146 | Can a search pattern be used along with matching explicit notebook names? |
|
147 | 147 | """ |
|
148 | 148 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
149 | 149 | self.call('nbconvert --log-level 0 --to python ' |
|
150 | 150 | '*.ipynb notebook1.ipynb notebook2.ipynb') |
|
151 | 151 | assert os.path.isfile('notebook1.py') |
|
152 | 152 | assert os.path.isfile('notebook2.py') |
|
153 | 153 | |
|
154 | 154 | |
|
155 | 155 | def test_explicit_glob(self): |
|
156 | 156 | """ |
|
157 | 157 | Can explicit notebook names be used and then a matching search pattern? |
|
158 | 158 | """ |
|
159 | 159 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
160 | 160 | self.call('nbconvert --log-level 0 --to=python ' |
|
161 | 161 | 'notebook1.ipynb notebook2.ipynb *.ipynb') |
|
162 | 162 | assert os.path.isfile('notebook1.py') |
|
163 | 163 | assert os.path.isfile('notebook2.py') |
|
164 | 164 | |
|
165 | 165 | |
|
166 | 166 | def test_default_config(self): |
|
167 | 167 | """ |
|
168 | 168 | Does the default config work? |
|
169 | 169 | """ |
|
170 | 170 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): |
|
171 | 171 | self.call('nbconvert --log-level 0') |
|
172 | 172 | assert os.path.isfile('notebook1.py') |
|
173 | 173 | assert not os.path.isfile('notebook2.py') |
|
174 | 174 | |
|
175 | 175 | |
|
176 | 176 | def test_override_config(self): |
|
177 | 177 | """ |
|
178 | 178 | Can the default config be overriden? |
|
179 | 179 | """ |
|
180 | 180 | with self.create_temp_cwd(['notebook*.ipynb', |
|
181 | 181 | 'ipython_nbconvert_config.py', |
|
182 | 182 | 'override.py']): |
|
183 | 183 | self.call('nbconvert --log-level 0 --config="override.py"') |
|
184 | 184 | assert not os.path.isfile('notebook1.py') |
|
185 | 185 | assert os.path.isfile('notebook2.py') |
General Comments 0
You need to be logged in to leave comments.
Login now