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