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