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