test_nbconvertapp.py
152 lines
| 5.3 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
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 | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r11478 | import os | ||
Jonathan Frederic
|
r11477 | from .base import TestsBase | ||
Jonathan Frederic
|
r11547 | from IPython.utils import py3compat | ||
Jonathan Frederic
|
r11747 | from IPython.testing import decorators as dec | ||
Jonathan Frederic
|
r11547 | |||
#----------------------------------------------------------------------------- | ||||
# Constants | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r11640 | # Define ipython commandline name | ||
Jonathan Frederic
|
r11547 | if py3compat.PY3: | ||
IPYTHON = 'ipython3' | ||||
else: | ||||
IPYTHON = 'ipython' | ||||
Jonathan Frederic
|
r11477 | #----------------------------------------------------------------------------- | ||
# Classes and functions | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r11494 | class TestNbConvertApp(TestsBase): | ||
Jonathan Frederic
|
r11477 | """Collection of NbConvertApp tests""" | ||
Jonathan Frederic
|
r11478 | |||
def test_notebook_help(self): | ||||
""" | ||||
Will help show if no notebooks are specified? | ||||
""" | ||||
with self.create_temp_cwd(): | ||||
Paul Ivanov
|
r11828 | out, err = self.call(IPYTHON + ' nbconvert', raise_on_error=False) | ||
assert "see '--help-all'" in out | ||||
Jonathan Frederic
|
r11478 | |||
def test_glob(self): | ||||
""" | ||||
Do search patterns work for notebook names? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb']): | ||||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert --to="python"' | ||
' --notebooks=["*.ipynb"]') | ||||
Jonathan Frederic
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
Jonathan Frederic
|
r11478 | |||
def test_glob_subdir(self): | ||||
""" | ||||
Do search patterns work for subdirectory notebook names? | ||||
""" | ||||
Paul Ivanov
|
r11828 | with self.create_temp_cwd(): | ||
Jonathan Frederic
|
r11478 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') | ||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert --to="python"', | ||
' --notebooks=["%s"]' % os.path.join('subdir', '*.ipynb')) | ||||
Jonathan Frederic
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
Jonathan Frederic
|
r11478 | |||
def test_explicit(self): | ||||
""" | ||||
Do explicit notebook names work? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb']): | ||||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert --to="python"' | ||
' --notebooks=["notebook2.ipynb"]') | ||||
Jonathan Frederic
|
r11639 | assert not os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
Jonathan Frederic
|
r11478 | |||
Jonathan Frederic
|
r11752 | @dec.onlyif_cmds_exist('pdflatex') | ||
Jonathan Frederic
|
r11747 | def test_post_processor(self): | ||
""" | ||||
Do post processors work? | ||||
""" | ||||
with self.create_temp_cwd(['notebook1.ipynb']): | ||||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert --to="latex" notebook1' | ||
' --post="PDF" --PDFPostProcessor.verbose=True') | ||||
Jonathan Frederic
|
r11747 | 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') | ||||
Jonathan Frederic
|
r11745 | def test_template(self): | ||
Jonathan Frederic
|
r11740 | """ | ||
Jonathan Frederic
|
r11745 | Do export templates work? | ||
Jonathan Frederic
|
r11740 | """ | ||
Jonathan Frederic
|
r11767 | with self.create_temp_cwd(['notebook2.ipynb']): | ||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert --to=slides' | ||
' --notebooks=["notebook2.ipynb"]' | ||||
' --template=reveal') | ||||
Jonathan Frederic
|
r11767 | assert os.path.isfile('notebook2.slides.html') | ||
with open('notebook2.slides.html') as f: | ||||
Jonathan Frederic
|
r11740 | assert '/reveal.css' in f.read() | ||
Jonathan Frederic
|
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']): | ||||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert --to="python" --notebooks=' | ||
'["*.ipynb", "notebook1.ipynb", "notebook2.ipynb"]') | ||||
Jonathan Frederic
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
Jonathan Frederic
|
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']): | ||||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert --to="python" --notebooks=' | ||
'["notebook1.ipynb", "notebook2.ipynb", "*.ipynb"]') | ||||
Jonathan Frederic
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
Jonathan Frederic
|
r11478 | |||
def test_default_config(self): | ||||
""" | ||||
Does the default config work? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): | ||||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert') | ||
Jonathan Frederic
|
r11639 | assert os.path.isfile('notebook1.py') | ||
assert not os.path.isfile('notebook2.py') | ||||
Jonathan Frederic
|
r11478 | |||
def test_override_config(self): | ||||
""" | ||||
Can the default config be overriden? | ||||
""" | ||||
Paul Ivanov
|
r11828 | with self.create_temp_cwd(['notebook*.ipynb', | ||
'ipython_nbconvert_config.py', | ||||
Jonathan Frederic
|
r11478 | 'override.py']): | ||
Paul Ivanov
|
r11828 | self.call(IPYTHON + ' nbconvert --config="override.py"') | ||
Jonathan Frederic
|
r11639 | assert not os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||