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