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