##// END OF EJS Templates
Expose ConfigManager one level up the hierarchy...
Expose ConfigManager one level up the hierarchy Because `from IPython.html.services.config import ConfigManager` is long enough.

File last commit:

r12521:eec42358
r19162:ee8f49f3
Show More
test_templateexporter.py
108 lines | 3.8 KiB | text/x-python | PythonLexer
Jonathan Frederic
Added exporter tests
r11480 """
Jonathan Frederic
Added tests for nb2nb Exporter...
r12521 Module with tests for templateexporter.py
Jonathan Frederic
Added exporter tests
r11480 """
#-----------------------------------------------------------------------------
# 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
#-----------------------------------------------------------------------------
from IPython.config import Config
from .base import ExportersTestsBase
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 from .cheese import CheesePreprocessor
Jonathan Frederic
Rebase changes made by hand
r12505 from ..templateexporter import TemplateExporter
Jonathan Frederic
Added exporter tests
r11480
#-----------------------------------------------------------------------------
# Class
#-----------------------------------------------------------------------------
Jonathan Frederic
s/Test_/Test
r11494 class TestExporter(ExportersTestsBase):
Jonathan Frederic
Added exporter tests
r11480 """Contains test functions for exporter.py"""
def test_constructor(self):
"""
Jonathan Frederic
Added tests for nb2nb Exporter...
r12521 Can a TemplateExporter be constructed?
Jonathan Frederic
Added exporter tests
r11480 """
Jonathan Frederic
Rebase changes made by hand
r12505 TemplateExporter()
Jonathan Frederic
Added exporter tests
r11480
def test_export(self):
"""
Jonathan Frederic
Added tests for nb2nb Exporter...
r12521 Can a TemplateExporter export something?
Jonathan Frederic
Added exporter tests
r11480 """
exporter = self._make_exporter()
(output, resources) = exporter.from_filename(self._get_notebook())
assert len(output) > 0
Jonathan Frederic
Renamed remaining `figures` strings
r11638 def test_extract_outputs(self):
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 If the ExtractOutputPreprocessor is enabled, are outputs extracted?
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 config = Config({'ExtractOutputPreprocessor': {'enabled': True}})
Jonathan Frederic
Added exporter tests
r11480 exporter = self._make_exporter(config=config)
(output, resources) = exporter.from_filename(self._get_notebook())
assert resources is not None
Jonathan Frederic
Fixed, don't check using in since resources is a default dict.
r12143 assert isinstance(resources['outputs'], dict)
Jonathan Frederic
Renamed remaining `figures` strings
r11638 assert len(resources['outputs']) > 0
Jonathan Frederic
Added exporter tests
r11480
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 def test_preprocessor_class(self):
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 Can a preprocessor be added to the preprocessors list by class type?
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 config = Config({'Exporter': {'preprocessors': [CheesePreprocessor]}})
Jonathan Frederic
Added exporter tests
r11480 exporter = self._make_exporter(config=config)
(output, resources) = exporter.from_filename(self._get_notebook())
assert resources is not None
assert resources['cheese'] == 'real'
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 def test_preprocessor_instance(self):
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 Can a preprocessor be added to the preprocessors list by instance?
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 config = Config({'Exporter': {'preprocessors': [CheesePreprocessor()]}})
Jonathan Frederic
Added exporter tests
r11480 exporter = self._make_exporter(config=config)
(output, resources) = exporter.from_filename(self._get_notebook())
assert resources is not None
assert resources['cheese'] == 'real'
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 def test_preprocessor_dottedobjectname(self):
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 Can a preprocessor be added to the preprocessors list by dotted object name?
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 config = Config({'Exporter': {'preprocessors': ['IPython.nbconvert.exporters.tests.cheese.CheesePreprocessor']}})
Jonathan Frederic
Added exporter tests
r11480 exporter = self._make_exporter(config=config)
(output, resources) = exporter.from_filename(self._get_notebook())
assert resources is not None
assert resources['cheese'] == 'real'
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 def test_preprocessor_via_method(self):
Jonathan Frederic
Added exporter tests
r11480 """
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 Can a preprocessor be added via the Exporter convenience method?
Jonathan Frederic
Added exporter tests
r11480 """
exporter = self._make_exporter()
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 exporter.register_preprocessor(CheesePreprocessor, enabled=True)
Jonathan Frederic
Added exporter tests
r11480 (output, resources) = exporter.from_filename(self._get_notebook())
assert resources is not None
assert resources['cheese'] == 'real'
def _make_exporter(self, config=None):
Jonathan Frederic
Added tests for nb2nb Exporter...
r12521 # Create the exporter instance, make sure to set a template name since
# the base TemplateExporter doesn't have a template associated with it.
Jonathan Frederic
Rebase changes made by hand
r12505 exporter = TemplateExporter(config=config, template_file='python')
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 return exporter