From fa6c52444ebeb3b139be3a290f9ed522bd24d2c3 2013-08-10 18:40:18 From: Jonathan Frederic Date: 2013-08-10 18:40:18 Subject: [PATCH] Further refinement --- diff --git a/IPython/nbconvert/tests/base.py b/IPython/nbconvert/tests/base.py index bd8b1e4..26f6ec6 100644 --- a/IPython/nbconvert/tests/base.py +++ b/IPython/nbconvert/tests/base.py @@ -136,8 +136,20 @@ class TestsBase(ParametricTestCase): return path - def call(self, parameters, raise_on_error=True): + def call(self, parameters, ignore_return_code=False): + """ + Execute a, IPython shell command, listening for both Errors and non-zero + return codes. + + PARAMETERS: + ----------- + parameters : str + List of parameters to pass to IPython. + ignore_return_code : optional bool (default False) + Throw an OSError if the return code + """ + stdout, stderr, retcode = get_output_error_code(ipy_cmd + parameters) - if retcode != 0 and raise_on_error: + if retcode != 0 and not ignore_return_code: raise OSError(stderr) return stdout, stderr diff --git a/IPython/nbconvert/tests/test_nbconvertapp.py b/IPython/nbconvert/tests/test_nbconvertapp.py index 259f6df..1eabe13 100644 --- a/IPython/nbconvert/tests/test_nbconvertapp.py +++ b/IPython/nbconvert/tests/test_nbconvertapp.py @@ -39,7 +39,7 @@ class TestNbConvertApp(TestsBase): Will help show if no notebooks are specified? """ with self.create_temp_cwd(): - out, err = self.call('nbconvert --log-level=0', raise_on_error=False) + out, err = self.call('nbconvert --log-level 0', ignore_return_code=True) assert "see '--help-all'" in out @@ -48,7 +48,7 @@ class TestNbConvertApp(TestsBase): Do search patterns work for notebook names? """ with self.create_temp_cwd(['notebook*.ipynb']): - self.call("""nbconvert --to="python" --notebooks="['*.ipynb']" --log-level=0""") + self.call('nbconvert --to python *.ipynb --log-level 0') assert os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -59,8 +59,8 @@ class TestNbConvertApp(TestsBase): """ with self.create_temp_cwd(): self.copy_files_to(['notebook*.ipynb'], 'subdir/') - self.call('nbconvert --to="python" --log-level=0 --notebooks=' - """"['%s']"' % os.path.join('subdir', '*.ipynb""")) + self.call('nbconvert --to python --log-level 0 ' + + os.path.join('subdir', '*.ipynb')) assert os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -70,8 +70,7 @@ class TestNbConvertApp(TestsBase): Do explicit notebook names work? """ with self.create_temp_cwd(['notebook*.ipynb']): - self.call('nbconvert --log-level=0 --to="python" --notebooks=' - """"['notebook2.ipynb']\"""") + self.call('nbconvert --log-level 0 --to python notebook2') assert not os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -84,8 +83,9 @@ class TestNbConvertApp(TestsBase): """ with self.create_temp_cwd(['notebook2.ipynb']): os.rename('notebook2.ipynb', 'notebook with spaces.ipynb') - o,e = self.call('nbconvert --log-level=0 --to="latex" "notebook with spaces"' - ' --post="PDF" --PDFPostProcessor.verbose=True') + o,e = self.call('nbconvert --log-level 0 --to latex ' + '"notebook with spaces" --post PDF ' + '--PDFPostProcessor.verbose=True') assert os.path.isfile('notebook with spaces.tex') assert os.path.isdir('notebook with spaces_files') assert os.path.isfile('notebook with spaces.pdf') @@ -97,8 +97,8 @@ class TestNbConvertApp(TestsBase): Do post processors work? """ with self.create_temp_cwd(['notebook1.ipynb']): - self.call('nbconvert --log-level=0 --to="latex" notebook1' - ' --post="PDF" --PDFPostProcessor.verbose=True') + self.call('nbconvert --log-level 0 --to latex notebook1 ' + '--post PDF --PDFPostProcessor.verbose=True') assert os.path.isfile('notebook1.tex') assert os.path.isfile('notebook1.pdf') @@ -109,8 +109,8 @@ class TestNbConvertApp(TestsBase): Do export templates work? """ with self.create_temp_cwd(['notebook2.ipynb']): - self.call('nbconvert --log-level=0 --to=slides --notebooks=' - """"['notebook2.ipynb']" --template=reveal""") + self.call('nbconvert --log-level 0 --to slides ' + 'notebook2.ipynb --template reveal') assert os.path.isfile('notebook2.slides.html') with open('notebook2.slides.html') as f: assert '/reveal.css' in f.read() @@ -121,8 +121,8 @@ class TestNbConvertApp(TestsBase): Can a search pattern be used along with matching explicit notebook names? """ with self.create_temp_cwd(['notebook*.ipynb']): - self.call('nbconvert --log-level=0 --to="python" --notebooks=' - """"['*.ipynb','notebook1.ipynb','notebook2.ipynb']\"""") + self.call('nbconvert --log-level 0 --to python ' + '*.ipynb notebook1.ipynb notebook2.ipynb') assert os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -132,8 +132,8 @@ class TestNbConvertApp(TestsBase): Can explicit notebook names be used and then a matching search pattern? """ with self.create_temp_cwd(['notebook*.ipynb']): - self.call('nbconvert --log-level=0 --to="python" --notebooks=' - """"['notebook1.ipynb','notebook2.ipynb','*.ipynb']\"""") + self.call('nbconvert --log-level 0 --to=python ' + 'notebook1.ipynb notebook2.ipynb *.ipynb') assert os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py') @@ -143,7 +143,7 @@ class TestNbConvertApp(TestsBase): Does the default config work? """ with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): - self.call('nbconvert --log-level=0') + self.call('nbconvert --log-level 0') assert os.path.isfile('notebook1.py') assert not os.path.isfile('notebook2.py') @@ -155,6 +155,6 @@ class TestNbConvertApp(TestsBase): with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py', 'override.py']): - self.call('nbconvert --log-level=0 --config="override.py"') + self.call('nbconvert --log-level 0 --config="override.py"') assert not os.path.isfile('notebook1.py') assert os.path.isfile('notebook2.py')