diff --git a/IPython/nbconvert/tests/base.py b/IPython/nbconvert/tests/base.py index 0955121..4edfff7 100644 --- a/IPython/nbconvert/tests/base.py +++ b/IPython/nbconvert/tests/base.py @@ -13,15 +13,13 @@ Contains base test class for nbconvert # Imports #----------------------------------------------------------------------------- -import subprocess import os import glob import shutil -import sys import IPython from IPython.utils.tempdir import TemporaryDirectory -from IPython.utils import py3compat +from IPython.utils.process import get_output_error_code #----------------------------------------------------------------------------- # Classes and functions @@ -166,12 +164,8 @@ class TestsBase(object): return path - def call(self, parameters): - output = subprocess.Popen(parameters, stdout=subprocess.PIPE).communicate()[0] - - #Convert the output to a string if running Python3 - if py3compat.PY3: - return output.decode('utf-8') - else: - return output - \ No newline at end of file + def call(self, parameters, raise_on_error=True): + stdout, stderr, retcode = get_output_error_code(parameters) + if retcode != 0 and raise_on_error: + raise OSError(stderr) + return stdout, stderr diff --git a/IPython/nbconvert/tests/test_nbconvertapp.py b/IPython/nbconvert/tests/test_nbconvertapp.py index 355923e..d8213e5 100644 --- a/IPython/nbconvert/tests/test_nbconvertapp.py +++ b/IPython/nbconvert/tests/test_nbconvertapp.py @@ -44,7 +44,8 @@ class TestNbConvertApp(TestsBase): Will help show if no notebooks are specified? """ with self.create_temp_cwd(): - assert "see '--help-all'" in self.call([IPYTHON, 'nbconvert']) + out, err = self.call(IPYTHON + ' nbconvert', raise_on_error=False) + assert "see '--help-all'" in out def test_glob(self): @@ -52,8 +53,8 @@ class TestNbConvertApp(TestsBase): Do search patterns work for notebook names? """ with self.create_temp_cwd(['notebook*.ipynb']): - assert not 'error' in self.call([IPYTHON, 'nbconvert', - '--to="python"', '--notebooks=["*.ipynb"]']).lower() + self.call(IPYTHON + ' nbconvert --to="python"' + ' --notebooks=["*.ipynb"]') assert os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -62,10 +63,10 @@ class TestNbConvertApp(TestsBase): """ Do search patterns work for subdirectory notebook names? """ - with self.create_temp_cwd() as cwd: + with self.create_temp_cwd(): self.copy_files_to(['notebook*.ipynb'], 'subdir/') - assert not 'error' in self.call([IPYTHON, 'nbconvert', '--to="python"', - '--notebooks=["%s"]' % os.path.join('subdir', '*.ipynb')]).lower() + self.call(IPYTHON + ' nbconvert --to="python"', + ' --notebooks=["%s"]' % os.path.join('subdir', '*.ipynb')) assert os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -75,8 +76,8 @@ class TestNbConvertApp(TestsBase): Do explicit notebook names work? """ with self.create_temp_cwd(['notebook*.ipynb']): - assert not 'error' in self.call([IPYTHON, 'nbconvert', '--to="python"', - '--notebooks=["notebook2.ipynb"]']).lower() + self.call(IPYTHON + ' nbconvert --to="python"' + ' --notebooks=["notebook2.ipynb"]') assert not os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -87,8 +88,8 @@ class TestNbConvertApp(TestsBase): Do post processors work? """ with self.create_temp_cwd(['notebook1.ipynb']): - assert not 'error' in self.call([IPYTHON, 'nbconvert', '--to="latex"', - 'notebook1', '--post="PDF"', '--PDFPostProcessor.verbose=True']).lower() + self.call(IPYTHON + ' nbconvert --to="latex" notebook1' + ' --post="PDF" --PDFPostProcessor.verbose=True') assert os.path.isfile('notebook1.tex') print("\n\n\t" + "\n\t".join([f for f in os.listdir('.') if os.path.isfile(f)]) + "\n\n") assert os.path.isfile('notebook1.pdf') @@ -99,8 +100,9 @@ class TestNbConvertApp(TestsBase): Do export templates work? """ with self.create_temp_cwd(['notebook2.ipynb']): - assert not 'error' in self.call([IPYTHON, 'nbconvert', '--to=slides', - '--notebooks=["notebook2.ipynb"]', '--template=reveal']).lower() + self.call(IPYTHON + ' nbconvert --to=slides' + ' --notebooks=["notebook2.ipynb"]' + ' --template=reveal') assert os.path.isfile('notebook2.slides.html') with open('notebook2.slides.html') as f: assert '/reveal.css' in f.read() @@ -111,8 +113,8 @@ class TestNbConvertApp(TestsBase): Can a search pattern be used along with matching explicit notebook names? """ with self.create_temp_cwd(['notebook*.ipynb']): - assert not 'error' in self.call([IPYTHON, 'nbconvert', '--to="python"', - '--notebooks=["*.ipynb", "notebook1.ipynb", "notebook2.ipynb"]']).lower() + self.call(IPYTHON + ' nbconvert --to="python" --notebooks=' + '["*.ipynb", "notebook1.ipynb", "notebook2.ipynb"]') assert os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -122,8 +124,8 @@ class TestNbConvertApp(TestsBase): Can explicit notebook names be used and then a matching search pattern? """ with self.create_temp_cwd(['notebook*.ipynb']): - assert not 'error' in self.call([IPYTHON, 'nbconvert', '--to="python"', - '--notebooks=["notebook1.ipynb", "notebook2.ipynb", "*.ipynb"]']).lower() + self.call(IPYTHON + ' nbconvert --to="python" --notebooks=' + '["notebook1.ipynb", "notebook2.ipynb", "*.ipynb"]') assert os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -133,7 +135,7 @@ class TestNbConvertApp(TestsBase): Does the default config work? """ with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): - assert not 'error' in self.call([IPYTHON, 'nbconvert']).lower() + self.call(IPYTHON + ' nbconvert') assert os.path.isfile('notebook1.py') assert not os.path.isfile('notebook2.py') @@ -142,8 +144,9 @@ class TestNbConvertApp(TestsBase): """ Can the default config be overriden? """ - with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py', + with self.create_temp_cwd(['notebook*.ipynb', + 'ipython_nbconvert_config.py', 'override.py']): - assert not 'error' in self.call([IPYTHON, 'nbconvert', '--config="override.py"']).lower() + self.call(IPYTHON + ' nbconvert --config="override.py"') assert not os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py')