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