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