test_nbconvertapp.py
123 lines
| 4.4 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 | ||
#----------------------------------------------------------------------------- | ||||
# 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(): | ||||
Jonathan Frederic
|
r11547 | assert "see '--help-all'" in self.call([IPYTHON, 'nbconvert']) | ||
Jonathan Frederic
|
r11478 | |||
def test_glob(self): | ||||
""" | ||||
Do search patterns work for notebook names? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb']): | ||||
Jonathan Frederic
|
r11547 | assert not 'error' in self.call([IPYTHON, 'nbconvert', | ||
Jonathan Frederic
|
r11478 | '--format="python"', '--notebooks=["*.ipynb"]']).lower() | ||
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? | ||||
""" | ||||
with self.create_temp_cwd() as cwd: | ||||
self.copy_files_to(['notebook*.ipynb'], 'subdir/') | ||||
Jonathan Frederic
|
r11547 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', | ||
Jonathan Frederic
|
r11478 | '--notebooks=["%s"]' % os.path.join('subdir', '*.ipynb')]).lower() | ||
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']): | ||||
Jonathan Frederic
|
r11547 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', | ||
Jonathan Frederic
|
r11478 | '--notebooks=["notebook2.ipynb"]']).lower() | ||
Jonathan Frederic
|
r11639 | assert not os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||
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']): | ||||
Jonathan Frederic
|
r11547 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', | ||
Jonathan Frederic
|
r11478 | '--notebooks=["*.ipynb", "notebook1.ipynb", "notebook2.ipynb"]']).lower() | ||
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']): | ||||
Jonathan Frederic
|
r11547 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--format="python"', | ||
Jonathan Frederic
|
r11478 | '--notebooks=["notebook1.ipynb", "notebook2.ipynb", "*.ipynb"]']).lower() | ||
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']): | ||||
Jonathan Frederic
|
r11547 | assert not 'error' in self.call([IPYTHON, 'nbconvert']).lower() | ||
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? | ||||
""" | ||||
with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py', | ||||
'override.py']): | ||||
Jonathan Frederic
|
r11547 | assert not 'error' in self.call([IPYTHON, 'nbconvert', '--config="override.py"']).lower() | ||
Jonathan Frederic
|
r11639 | assert not os.path.isfile('notebook1.py') | ||
assert os.path.isfile('notebook2.py') | ||||