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