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