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