test_nbconvertapp.py
144 lines
| 5.3 KiB
| text/x-python
|
PythonLexer
|
r11477 | """ | ||
Contains tests for the nbconvertapp | ||||
""" | ||||
#----------------------------------------------------------------------------- | ||||
#Copyright (c) 2013, the IPython Development Team. | ||||
# | ||||
#Distributed under the terms of the Modified BSD License. | ||||
# | ||||
#The full license is in the file COPYING.txt, distributed with this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
|
r11478 | import os | ||
|
r11477 | from .base import TestsBase | ||
|
r11747 | from IPython.testing import decorators as dec | ||
|
r11547 | |||
#----------------------------------------------------------------------------- | ||||
# Constants | ||||
#----------------------------------------------------------------------------- | ||||
|
r11477 | #----------------------------------------------------------------------------- | ||
# Classes and functions | ||||
#----------------------------------------------------------------------------- | ||||
|
r11494 | class TestNbConvertApp(TestsBase): | ||
|
r11477 | """Collection of NbConvertApp tests""" | ||
|
r11478 | |||
def test_notebook_help(self): | ||||
""" | ||||
Will help show if no notebooks are specified? | ||||
""" | ||||
with self.create_temp_cwd(): | ||||
|
r11912 | out, err = self.call('nbconvert --NbConvertApp.log_level="WARN"', raise_on_error=False) | ||
|
r11828 | assert "see '--help-all'" in out | ||
|
r11478 | |||
def test_glob(self): | ||||
""" | ||||
Do search patterns work for notebook names? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb']): | ||||
|
r11912 | self.call('nbconvert --to="python" --notebooks=\'["*.ipynb"]\' --NbConvertApp.log_level="WARN"') | ||
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
|
r11478 | |||
def test_glob_subdir(self): | ||||
""" | ||||
Do search patterns work for subdirectory notebook names? | ||||
""" | ||||
|
r11828 | with self.create_temp_cwd(): | ||
|
r11478 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') | ||
|
r11912 | self.call('nbconvert --to="python" --NbConvertApp.log_level="WARN" --notebooks=' | ||
|
r11866 | '\'["%s"]\'' % os.path.join('subdir', '*.ipynb')) | ||
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
|
r11478 | |||
def test_explicit(self): | ||||
""" | ||||
Do explicit notebook names work? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb']): | ||||
|
r11912 | self.call('nbconvert --NbConvertApp.log_level="WARN" --to="python" --notebooks=' | ||
|
r11866 | '\'["notebook2.ipynb"]\'') | ||
|
r11639 | assert not os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
|
r11478 | |||
|
r11752 | @dec.onlyif_cmds_exist('pdflatex') | ||
|
r11833 | @dec.onlyif_cmds_exist('pandoc') | ||
|
r11747 | def test_post_processor(self): | ||
""" | ||||
Do post processors work? | ||||
""" | ||||
with self.create_temp_cwd(['notebook1.ipynb']): | ||||
|
r11912 | self.call('nbconvert --NbConvertApp.log_level="WARN" --to="latex" notebook1' | ||
|
r11834 | ' --post="PDF" --PDFPostProcessor.verbose=True') | ||
|
r11747 | assert os.path.isfile('notebook1.tex') | ||
assert os.path.isfile('notebook1.pdf') | ||||
|
r11833 | @dec.onlyif_cmds_exist('pandoc') | ||
|
r11745 | def test_template(self): | ||
|
r11740 | """ | ||
|
r11745 | Do export templates work? | ||
|
r11740 | """ | ||
|
r11767 | with self.create_temp_cwd(['notebook2.ipynb']): | ||
|
r11912 | self.call('nbconvert --NbConvertApp.log_level="WARN" --to=slides --notebooks=' | ||
|
r11866 | '\'["notebook2.ipynb"]\' --template=reveal') | ||
|
r11767 | assert os.path.isfile('notebook2.slides.html') | ||
with open('notebook2.slides.html') as f: | ||||
|
r11740 | assert '/reveal.css' in f.read() | ||
|
r11478 | def test_glob_explicit(self): | ||
""" | ||||
Can a search pattern be used along with matching explicit notebook names? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb']): | ||||
|
r11912 | self.call('nbconvert --NbConvertApp.log_level="WARN" --to="python" --notebooks=' | ||
|
r11866 | '\'["*.ipynb","notebook1.ipynb","notebook2.ipynb"]\'') | ||
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
|
r11478 | |||
def test_explicit_glob(self): | ||||
""" | ||||
Can explicit notebook names be used and then a matching search pattern? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb']): | ||||
|
r11912 | self.call('nbconvert --NbConvertApp.log_level="WARN" --to="python" --notebooks=' | ||
|
r11866 | '\'["notebook1.ipynb","notebook2.ipynb","*.ipynb"]\'') | ||
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
|
r11478 | |||
def test_default_config(self): | ||||
""" | ||||
Does the default config work? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): | ||||
|
r11912 | self.call('nbconvert --NbConvertApp.log_level="WARN"') | ||
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert not os.path.isfile('notebook2.py') | ||||
|
r11478 | |||
def test_override_config(self): | ||||
""" | ||||
Can the default config be overriden? | ||||
""" | ||||
|
r11828 | with self.create_temp_cwd(['notebook*.ipynb', | ||
'ipython_nbconvert_config.py', | ||||
|
r11478 | 'override.py']): | ||
|
r11912 | self.call('nbconvert --NbConvertApp.log_level="WARN" --config="override.py"') | ||
|
r11639 | assert not os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||