Show More
@@ -13,15 +13,13 b' Contains base test class for nbconvert' | |||
|
13 | 13 | # Imports |
|
14 | 14 | #----------------------------------------------------------------------------- |
|
15 | 15 | |
|
16 | import subprocess | |
|
17 | 16 | import os |
|
18 | 17 | import glob |
|
19 | 18 | import shutil |
|
20 | import sys | |
|
21 | 19 | |
|
22 | 20 | import IPython |
|
23 | 21 | from IPython.utils.tempdir import TemporaryDirectory |
|
24 |
from IPython.utils import |
|
|
22 | from IPython.utils.process import get_output_error_code | |
|
25 | 23 | |
|
26 | 24 | #----------------------------------------------------------------------------- |
|
27 | 25 | # Classes and functions |
@@ -166,12 +164,8 b' class TestsBase(object):' | |||
|
166 | 164 | return path |
|
167 | 165 | |
|
168 | 166 | |
|
169 | def call(self, parameters): | |
|
170 | output = subprocess.Popen(parameters, stdout=subprocess.PIPE).communicate()[0] | |
|
171 | ||
|
172 | #Convert the output to a string if running Python3 | |
|
173 | if py3compat.PY3: | |
|
174 | return output.decode('utf-8') | |
|
175 | else: | |
|
176 | return output | |
|
177 | No newline at end of file | |
|
167 | def call(self, parameters, raise_on_error=True): | |
|
168 | stdout, stderr, retcode = get_output_error_code(parameters) | |
|
169 | if retcode != 0 and raise_on_error: | |
|
170 | raise OSError(stderr) | |
|
171 | return stdout, stderr |
@@ -44,7 +44,8 b' class TestNbConvertApp(TestsBase):' | |||
|
44 | 44 | Will help show if no notebooks are specified? |
|
45 | 45 | """ |
|
46 | 46 | with self.create_temp_cwd(): |
|
47 |
|
|
|
47 | out, err = self.call(IPYTHON + ' nbconvert', raise_on_error=False) | |
|
48 | assert "see '--help-all'" in out | |
|
48 | 49 | |
|
49 | 50 | |
|
50 | 51 | def test_glob(self): |
@@ -52,8 +53,8 b' class TestNbConvertApp(TestsBase):' | |||
|
52 | 53 | Do search patterns work for notebook names? |
|
53 | 54 | """ |
|
54 | 55 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
55 |
|
|
|
56 |
' |
|
|
56 | self.call(IPYTHON + ' nbconvert --to="python"' | |
|
57 | ' --notebooks=["*.ipynb"]') | |
|
57 | 58 | assert os.path.isfile('notebook1.py') |
|
58 | 59 | assert os.path.isfile('notebook2.py') |
|
59 | 60 | |
@@ -62,10 +63,10 b' class TestNbConvertApp(TestsBase):' | |||
|
62 | 63 | """ |
|
63 | 64 | Do search patterns work for subdirectory notebook names? |
|
64 | 65 | """ |
|
65 |
with self.create_temp_cwd() |
|
|
66 | with self.create_temp_cwd(): | |
|
66 | 67 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') |
|
67 |
|
|
|
68 |
'--notebooks=["%s"]' % os.path.join('subdir', '*.ipynb') |
|
|
68 | self.call(IPYTHON + ' nbconvert --to="python"', | |
|
69 | ' --notebooks=["%s"]' % os.path.join('subdir', '*.ipynb')) | |
|
69 | 70 | assert os.path.isfile('notebook1.py') |
|
70 | 71 | assert os.path.isfile('notebook2.py') |
|
71 | 72 | |
@@ -75,8 +76,8 b' class TestNbConvertApp(TestsBase):' | |||
|
75 | 76 | Do explicit notebook names work? |
|
76 | 77 | """ |
|
77 | 78 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
78 |
|
|
|
79 |
'--notebooks=["notebook2.ipynb"]' |
|
|
79 | self.call(IPYTHON + ' nbconvert --to="python"' | |
|
80 | ' --notebooks=["notebook2.ipynb"]') | |
|
80 | 81 | assert not os.path.isfile('notebook1.py') |
|
81 | 82 | assert os.path.isfile('notebook2.py') |
|
82 | 83 | |
@@ -87,8 +88,8 b' class TestNbConvertApp(TestsBase):' | |||
|
87 | 88 | Do post processors work? |
|
88 | 89 | """ |
|
89 | 90 | with self.create_temp_cwd(['notebook1.ipynb']): |
|
90 |
|
|
|
91 |
' |
|
|
91 | self.call(IPYTHON + ' nbconvert --to="latex" notebook1' | |
|
92 | ' --post="PDF" --PDFPostProcessor.verbose=True') | |
|
92 | 93 | assert os.path.isfile('notebook1.tex') |
|
93 | 94 | print("\n\n\t" + "\n\t".join([f for f in os.listdir('.') if os.path.isfile(f)]) + "\n\n") |
|
94 | 95 | assert os.path.isfile('notebook1.pdf') |
@@ -99,8 +100,9 b' class TestNbConvertApp(TestsBase):' | |||
|
99 | 100 | Do export templates work? |
|
100 | 101 | """ |
|
101 | 102 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
102 |
|
|
|
103 |
'--notebooks=["notebook2.ipynb"]' |
|
|
103 | self.call(IPYTHON + ' nbconvert --to=slides' | |
|
104 | ' --notebooks=["notebook2.ipynb"]' | |
|
105 | ' --template=reveal') | |
|
104 | 106 | assert os.path.isfile('notebook2.slides.html') |
|
105 | 107 | with open('notebook2.slides.html') as f: |
|
106 | 108 | assert '/reveal.css' in f.read() |
@@ -111,8 +113,8 b' class TestNbConvertApp(TestsBase):' | |||
|
111 | 113 | Can a search pattern be used along with matching explicit notebook names? |
|
112 | 114 | """ |
|
113 | 115 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
114 |
|
|
|
115 |
' |
|
|
116 | self.call(IPYTHON + ' nbconvert --to="python" --notebooks=' | |
|
117 | '["*.ipynb", "notebook1.ipynb", "notebook2.ipynb"]') | |
|
116 | 118 | assert os.path.isfile('notebook1.py') |
|
117 | 119 | assert os.path.isfile('notebook2.py') |
|
118 | 120 | |
@@ -122,8 +124,8 b' class TestNbConvertApp(TestsBase):' | |||
|
122 | 124 | Can explicit notebook names be used and then a matching search pattern? |
|
123 | 125 | """ |
|
124 | 126 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
125 |
|
|
|
126 |
' |
|
|
127 | self.call(IPYTHON + ' nbconvert --to="python" --notebooks=' | |
|
128 | '["notebook1.ipynb", "notebook2.ipynb", "*.ipynb"]') | |
|
127 | 129 | assert os.path.isfile('notebook1.py') |
|
128 | 130 | assert os.path.isfile('notebook2.py') |
|
129 | 131 | |
@@ -133,7 +135,7 b' class TestNbConvertApp(TestsBase):' | |||
|
133 | 135 | Does the default config work? |
|
134 | 136 | """ |
|
135 | 137 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): |
|
136 |
|
|
|
138 | self.call(IPYTHON + ' nbconvert') | |
|
137 | 139 | assert os.path.isfile('notebook1.py') |
|
138 | 140 | assert not os.path.isfile('notebook2.py') |
|
139 | 141 | |
@@ -142,8 +144,9 b' class TestNbConvertApp(TestsBase):' | |||
|
142 | 144 | """ |
|
143 | 145 | Can the default config be overriden? |
|
144 | 146 | """ |
|
145 |
with self.create_temp_cwd(['notebook*.ipynb', |
|
|
147 | with self.create_temp_cwd(['notebook*.ipynb', | |
|
148 | 'ipython_nbconvert_config.py', | |
|
146 | 149 | 'override.py']): |
|
147 |
|
|
|
150 | self.call(IPYTHON + ' nbconvert --config="override.py"') | |
|
148 | 151 | assert not os.path.isfile('notebook1.py') |
|
149 | 152 | assert os.path.isfile('notebook2.py') |
General Comments 0
You need to be logged in to leave comments.
Login now