##// END OF EJS Templates
use notebook which has an image in it for the test
Paul Ivanov -
Show More
@@ -1,159 +1,160 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')
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(['notebook1.ipynb']):
85 with self.create_temp_cwd(['notebook2.ipynb']):
86 os.rename('notebook1.ipynb', 'notebook with spaces.ipynb')
86 os.rename('notebook2.ipynb', 'notebook with spaces.ipynb')
87 self.call('nbconvert --log-level=0 --to="latex" "notebook with spaces"')
87 o,e = self.call('nbconvert --log-level=0 --to="latex" "notebook with spaces"'
88 ' --post="PDF" --PDFPostProcessor.verbose=True')
88 assert os.path.isfile('notebook with spaces.tex')
89 assert os.path.isfile('notebook with spaces.tex')
89 assert os.path.isdir('notebook with spaces_files')
90 assert os.path.isdir('notebook with spaces_files')
90 assert os.path.isfile('notebook with spaces.pdf')
91 assert os.path.isfile('notebook with spaces.pdf')
91
92
92 @dec.onlyif_cmds_exist('pdflatex')
93 @dec.onlyif_cmds_exist('pdflatex')
93 @dec.onlyif_cmds_exist('pandoc')
94 @dec.onlyif_cmds_exist('pandoc')
94 def test_post_processor(self):
95 def test_post_processor(self):
95 """
96 """
96 Do post processors work?
97 Do post processors work?
97 """
98 """
98 with self.create_temp_cwd(['notebook1.ipynb']):
99 with self.create_temp_cwd(['notebook1.ipynb']):
99 self.call('nbconvert --log-level=0 --to="latex" notebook1'
100 self.call('nbconvert --log-level=0 --to="latex" notebook1'
100 ' --post="PDF" --PDFPostProcessor.verbose=True')
101 ' --post="PDF" --PDFPostProcessor.verbose=True')
101 assert os.path.isfile('notebook1.tex')
102 assert os.path.isfile('notebook1.tex')
102 assert os.path.isfile('notebook1.pdf')
103 assert os.path.isfile('notebook1.pdf')
103
104
104
105
105 @dec.onlyif_cmds_exist('pandoc')
106 @dec.onlyif_cmds_exist('pandoc')
106 def test_template(self):
107 def test_template(self):
107 """
108 """
108 Do export templates work?
109 Do export templates work?
109 """
110 """
110 with self.create_temp_cwd(['notebook2.ipynb']):
111 with self.create_temp_cwd(['notebook2.ipynb']):
111 self.call('nbconvert --log-level=0 --to=slides --notebooks='
112 self.call('nbconvert --log-level=0 --to=slides --notebooks='
112 '\'["notebook2.ipynb"]\' --template=reveal')
113 '\'["notebook2.ipynb"]\' --template=reveal')
113 assert os.path.isfile('notebook2.slides.html')
114 assert os.path.isfile('notebook2.slides.html')
114 with open('notebook2.slides.html') as f:
115 with open('notebook2.slides.html') as f:
115 assert '/reveal.css' in f.read()
116 assert '/reveal.css' in f.read()
116
117
117
118
118 def test_glob_explicit(self):
119 def test_glob_explicit(self):
119 """
120 """
120 Can a search pattern be used along with matching explicit notebook names?
121 Can a search pattern be used along with matching explicit notebook names?
121 """
122 """
122 with self.create_temp_cwd(['notebook*.ipynb']):
123 with self.create_temp_cwd(['notebook*.ipynb']):
123 self.call('nbconvert --log-level=0 --to="python" --notebooks='
124 self.call('nbconvert --log-level=0 --to="python" --notebooks='
124 '\'["*.ipynb","notebook1.ipynb","notebook2.ipynb"]\'')
125 '\'["*.ipynb","notebook1.ipynb","notebook2.ipynb"]\'')
125 assert os.path.isfile('notebook1.py')
126 assert os.path.isfile('notebook1.py')
126 assert os.path.isfile('notebook2.py')
127 assert os.path.isfile('notebook2.py')
127
128
128
129
129 def test_explicit_glob(self):
130 def test_explicit_glob(self):
130 """
131 """
131 Can explicit notebook names be used and then a matching search pattern?
132 Can explicit notebook names be used and then a matching search pattern?
132 """
133 """
133 with self.create_temp_cwd(['notebook*.ipynb']):
134 with self.create_temp_cwd(['notebook*.ipynb']):
134 self.call('nbconvert --log-level=0 --to="python" --notebooks='
135 self.call('nbconvert --log-level=0 --to="python" --notebooks='
135 '\'["notebook1.ipynb","notebook2.ipynb","*.ipynb"]\'')
136 '\'["notebook1.ipynb","notebook2.ipynb","*.ipynb"]\'')
136 assert os.path.isfile('notebook1.py')
137 assert os.path.isfile('notebook1.py')
137 assert os.path.isfile('notebook2.py')
138 assert os.path.isfile('notebook2.py')
138
139
139
140
140 def test_default_config(self):
141 def test_default_config(self):
141 """
142 """
142 Does the default config work?
143 Does the default config work?
143 """
144 """
144 with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']):
145 with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']):
145 self.call('nbconvert --log-level=0')
146 self.call('nbconvert --log-level=0')
146 assert os.path.isfile('notebook1.py')
147 assert os.path.isfile('notebook1.py')
147 assert not os.path.isfile('notebook2.py')
148 assert not os.path.isfile('notebook2.py')
148
149
149
150
150 def test_override_config(self):
151 def test_override_config(self):
151 """
152 """
152 Can the default config be overriden?
153 Can the default config be overriden?
153 """
154 """
154 with self.create_temp_cwd(['notebook*.ipynb',
155 with self.create_temp_cwd(['notebook*.ipynb',
155 'ipython_nbconvert_config.py',
156 'ipython_nbconvert_config.py',
156 'override.py']):
157 'override.py']):
157 self.call('nbconvert --log-level=0 --config="override.py"')
158 self.call('nbconvert --log-level=0 --config="override.py"')
158 assert not os.path.isfile('notebook1.py')
159 assert not os.path.isfile('notebook1.py')
159 assert os.path.isfile('notebook2.py')
160 assert os.path.isfile('notebook2.py')
General Comments 0
You need to be logged in to leave comments. Login now