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