Show More
@@ -1,158 +1,159 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 |
|
18 | |||
19 | from .base import TestsBase |
|
19 | from .base import TestsBase | |
20 |
|
20 | |||
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 | """ |
|
38 | """ | |
39 | Will help show if no notebooks are specified? |
|
39 | Will help show if no notebooks are specified? | |
40 | """ |
|
40 | """ | |
41 | with self.create_temp_cwd(): |
|
41 | with self.create_temp_cwd(): | |
42 | out, err = self.call('nbconvert --log-level=0', raise_on_error=False) |
|
42 | out, err = self.call('nbconvert --log-level=0', raise_on_error=False) | |
43 | assert "see '--help-all'" in out |
|
43 | assert "see '--help-all'" in out | |
44 |
|
44 | |||
45 |
|
45 | |||
46 | def test_glob(self): |
|
46 | def test_glob(self): | |
47 | """ |
|
47 | """ | |
48 | Do search patterns work for notebook names? |
|
48 | Do search patterns work for notebook names? | |
49 | """ |
|
49 | """ | |
50 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
50 | with self.create_temp_cwd(['notebook*.ipynb']): | |
51 | self.call('nbconvert --to="python" --notebooks=\'["*.ipynb"]\' --log-level=0') |
|
51 | self.call('nbconvert --to="python" --notebooks=\'["*.ipynb"]\' --log-level=0') | |
52 | assert os.path.isfile('notebook1.py') |
|
52 | assert os.path.isfile('notebook1.py') | |
53 | assert os.path.isfile('notebook2.py') |
|
53 | assert os.path.isfile('notebook2.py') | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | def test_glob_subdir(self): |
|
56 | def test_glob_subdir(self): | |
57 | """ |
|
57 | """ | |
58 | Do search patterns work for subdirectory notebook names? |
|
58 | Do search patterns work for subdirectory notebook names? | |
59 | """ |
|
59 | """ | |
60 | with self.create_temp_cwd(): |
|
60 | with self.create_temp_cwd(): | |
61 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') |
|
61 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') | |
62 | self.call('nbconvert --to="python" --log-level=0 --notebooks=' |
|
62 | self.call('nbconvert --to="python" --log-level=0 --notebooks=' | |
63 | '\'["%s"]\'' % os.path.join('subdir', '*.ipynb')) |
|
63 | '\'["%s"]\'' % os.path.join('subdir', '*.ipynb')) | |
64 | assert os.path.isfile('notebook1.py') |
|
64 | assert os.path.isfile('notebook1.py') | |
65 | assert os.path.isfile('notebook2.py') |
|
65 | assert os.path.isfile('notebook2.py') | |
66 |
|
66 | |||
67 |
|
67 | |||
68 | def test_explicit(self): |
|
68 | def test_explicit(self): | |
69 | """ |
|
69 | """ | |
70 | Do explicit notebook names work? |
|
70 | Do explicit notebook names work? | |
71 | """ |
|
71 | """ | |
72 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
72 | with self.create_temp_cwd(['notebook*.ipynb']): | |
73 | self.call('nbconvert --log-level=0 --to="python" --notebooks=' |
|
73 | self.call('nbconvert --log-level=0 --to="python" --notebooks=' | |
74 | '\'["notebook2.ipynb"]\'') |
|
74 | '\'["notebook2.ipynb"]\'') | |
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') | |||
|
80 | @dec.onlyif_cmds_exist('pandoc') | |||
79 | def test_filename_spaces(self): |
|
81 | def test_filename_spaces(self): | |
80 | """ |
|
82 | """ | |
81 | Are spaces removed from filenames? |
|
83 | Generate PDFs with graphics if notebooks have spaces in the name? | |
82 | """ |
|
84 | """ | |
83 | with self.create_temp_cwd(['notebook1.ipynb']): |
|
85 | with self.create_temp_cwd(['notebook1.ipynb']): | |
84 | os.rename('notebook1.ipynb', 'notebook with spaces.ipynb') |
|
86 | os.rename('notebook1.ipynb', 'notebook with spaces.ipynb') | |
85 | self.call('nbconvert --log-level=0 --to="latex" "notebook with spaces"') |
|
87 | self.call('nbconvert --log-level=0 --to="latex" "notebook with spaces"') | |
86 | assert os.path.isfile('notebook with spaces.tex') |
|
88 | assert os.path.isfile('notebook with spaces.tex') | |
87 |
assert os.path.isdir('notebook |
|
89 | assert os.path.isdir('notebook with spaces_files') | |
88 |
|
|
90 | assert os.path.isfile('notebook with spaces.pdf') | |
89 | assert r" \t\n" not in f |
|
|||
90 |
|
91 | |||
91 | @dec.onlyif_cmds_exist('pdflatex') |
|
92 | @dec.onlyif_cmds_exist('pdflatex') | |
92 | @dec.onlyif_cmds_exist('pandoc') |
|
93 | @dec.onlyif_cmds_exist('pandoc') | |
93 | def test_post_processor(self): |
|
94 | def test_post_processor(self): | |
94 | """ |
|
95 | """ | |
95 | Do post processors work? |
|
96 | Do post processors work? | |
96 | """ |
|
97 | """ | |
97 | with self.create_temp_cwd(['notebook1.ipynb']): |
|
98 | with self.create_temp_cwd(['notebook1.ipynb']): | |
98 | self.call('nbconvert --log-level=0 --to="latex" notebook1' |
|
99 | self.call('nbconvert --log-level=0 --to="latex" notebook1' | |
99 | ' --post="PDF" --PDFPostProcessor.verbose=True') |
|
100 | ' --post="PDF" --PDFPostProcessor.verbose=True') | |
100 | assert os.path.isfile('notebook1.tex') |
|
101 | assert os.path.isfile('notebook1.tex') | |
101 | assert os.path.isfile('notebook1.pdf') |
|
102 | assert os.path.isfile('notebook1.pdf') | |
102 |
|
103 | |||
103 |
|
104 | |||
104 | @dec.onlyif_cmds_exist('pandoc') |
|
105 | @dec.onlyif_cmds_exist('pandoc') | |
105 | def test_template(self): |
|
106 | def test_template(self): | |
106 | """ |
|
107 | """ | |
107 | Do export templates work? |
|
108 | Do export templates work? | |
108 | """ |
|
109 | """ | |
109 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
110 | with self.create_temp_cwd(['notebook2.ipynb']): | |
110 | self.call('nbconvert --log-level=0 --to=slides --notebooks=' |
|
111 | self.call('nbconvert --log-level=0 --to=slides --notebooks=' | |
111 | '\'["notebook2.ipynb"]\' --template=reveal') |
|
112 | '\'["notebook2.ipynb"]\' --template=reveal') | |
112 | assert os.path.isfile('notebook2.slides.html') |
|
113 | assert os.path.isfile('notebook2.slides.html') | |
113 | with open('notebook2.slides.html') as f: |
|
114 | with open('notebook2.slides.html') as f: | |
114 | assert '/reveal.css' in f.read() |
|
115 | assert '/reveal.css' in f.read() | |
115 |
|
116 | |||
116 |
|
117 | |||
117 | def test_glob_explicit(self): |
|
118 | def test_glob_explicit(self): | |
118 | """ |
|
119 | """ | |
119 | Can a search pattern be used along with matching explicit notebook names? |
|
120 | Can a search pattern be used along with matching explicit notebook names? | |
120 | """ |
|
121 | """ | |
121 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
122 | with self.create_temp_cwd(['notebook*.ipynb']): | |
122 | self.call('nbconvert --log-level=0 --to="python" --notebooks=' |
|
123 | self.call('nbconvert --log-level=0 --to="python" --notebooks=' | |
123 | '\'["*.ipynb","notebook1.ipynb","notebook2.ipynb"]\'') |
|
124 | '\'["*.ipynb","notebook1.ipynb","notebook2.ipynb"]\'') | |
124 | assert os.path.isfile('notebook1.py') |
|
125 | assert os.path.isfile('notebook1.py') | |
125 | assert os.path.isfile('notebook2.py') |
|
126 | assert os.path.isfile('notebook2.py') | |
126 |
|
127 | |||
127 |
|
128 | |||
128 | def test_explicit_glob(self): |
|
129 | def test_explicit_glob(self): | |
129 | """ |
|
130 | """ | |
130 | Can explicit notebook names be used and then a matching search pattern? |
|
131 | Can explicit notebook names be used and then a matching search pattern? | |
131 | """ |
|
132 | """ | |
132 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
133 | with self.create_temp_cwd(['notebook*.ipynb']): | |
133 | self.call('nbconvert --log-level=0 --to="python" --notebooks=' |
|
134 | self.call('nbconvert --log-level=0 --to="python" --notebooks=' | |
134 | '\'["notebook1.ipynb","notebook2.ipynb","*.ipynb"]\'') |
|
135 | '\'["notebook1.ipynb","notebook2.ipynb","*.ipynb"]\'') | |
135 | assert os.path.isfile('notebook1.py') |
|
136 | assert os.path.isfile('notebook1.py') | |
136 | assert os.path.isfile('notebook2.py') |
|
137 | assert os.path.isfile('notebook2.py') | |
137 |
|
138 | |||
138 |
|
139 | |||
139 | def test_default_config(self): |
|
140 | def test_default_config(self): | |
140 | """ |
|
141 | """ | |
141 | Does the default config work? |
|
142 | Does the default config work? | |
142 | """ |
|
143 | """ | |
143 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): |
|
144 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): | |
144 | self.call('nbconvert --log-level=0') |
|
145 | self.call('nbconvert --log-level=0') | |
145 | assert os.path.isfile('notebook1.py') |
|
146 | assert os.path.isfile('notebook1.py') | |
146 | assert not os.path.isfile('notebook2.py') |
|
147 | assert not os.path.isfile('notebook2.py') | |
147 |
|
148 | |||
148 |
|
149 | |||
149 | def test_override_config(self): |
|
150 | def test_override_config(self): | |
150 | """ |
|
151 | """ | |
151 | Can the default config be overriden? |
|
152 | Can the default config be overriden? | |
152 | """ |
|
153 | """ | |
153 | with self.create_temp_cwd(['notebook*.ipynb', |
|
154 | with self.create_temp_cwd(['notebook*.ipynb', | |
154 | 'ipython_nbconvert_config.py', |
|
155 | 'ipython_nbconvert_config.py', | |
155 | 'override.py']): |
|
156 | 'override.py']): | |
156 | self.call('nbconvert --log-level=0 --config="override.py"') |
|
157 | self.call('nbconvert --log-level=0 --config="override.py"') | |
157 | assert not os.path.isfile('notebook1.py') |
|
158 | assert not os.path.isfile('notebook1.py') | |
158 | assert os.path.isfile('notebook2.py') |
|
159 | assert os.path.isfile('notebook2.py') |
General Comments 0
You need to be logged in to leave comments.
Login now