From bd43b703a4de8b84c3e05163123e4bc00e041b9d 2013-08-16 17:43:06 From: MinRK Date: 2013-08-16 17:43:06 Subject: [PATCH] Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3 closes #3945 Please see issue for more information. --- diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py index 72a4256..9f5529c 100755 --- a/IPython/nbconvert/nbconvertapp.py +++ b/IPython/nbconvert/nbconvertapp.py @@ -59,7 +59,6 @@ nbconvert_aliases.update(base_aliases) nbconvert_aliases.update({ 'to' : 'NbConvertApp.export_format', 'template' : 'Exporter.template_file', - 'notebooks' : 'NbConvertApp.notebooks', 'writer' : 'NbConvertApp.writer_class', 'post': 'NbConvertApp.post_processor_class', 'output': 'NbConvertApp.output_base' diff --git a/IPython/nbconvert/tests/base.py b/IPython/nbconvert/tests/base.py index bd8b1e4..2edd704 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 not (retcode == 0 or 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 7d6ce8b..1a7f6d3 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')