test_revealhelp.py
78 lines
| 2.9 KiB
| text/x-python
|
PythonLexer
MinRK
|
r18244 | """Tests for the revealhelp preprocessor""" | ||
Jonathan Frederic
|
r12032 | |||
MinRK
|
r18244 | # Copyright (c) IPython Development Team. | ||
Jonathan Frederic
|
r12032 | # Distributed under the terms of the Modified BSD License. | ||
MinRK
|
r18605 | from IPython.nbformat import v4 as nbformat | ||
Jonathan Frederic
|
r12032 | |||
Paul Ivanov
|
r12219 | from .base import PreprocessorTestsBase | ||
from ..revealhelp import RevealHelpPreprocessor | ||||
Jonathan Frederic
|
r12032 | |||
Paul Ivanov
|
r12219 | class Testrevealhelp(PreprocessorTestsBase): | ||
Jonathan Frederic
|
r12032 | """Contains test functions for revealhelp.py""" | ||
def build_notebook(self): | ||||
damianavila
|
r16869 | """Build a reveal slides notebook in memory for use with tests. | ||
Paul Ivanov
|
r12219 | Overrides base in PreprocessorTestsBase""" | ||
Jonathan Frederic
|
r12032 | |||
MinRK
|
r18580 | outputs = [nbformat.new_output(output_type="stream", name="stdout", text="a")] | ||
damianavila
|
r16869 | |||
Jonathan Frederic
|
r12032 | slide_metadata = {'slideshow' : {'slide_type': 'slide'}} | ||
subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} | ||||
MinRK
|
r18587 | cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs), | ||
MinRK
|
r18580 | nbformat.new_markdown_cell(source="", metadata=slide_metadata), | ||
MinRK
|
r18587 | nbformat.new_code_cell(source="", execution_count=2, outputs=outputs), | ||
MinRK
|
r18580 | nbformat.new_markdown_cell(source="", metadata=slide_metadata), | ||
nbformat.new_markdown_cell(source="", metadata=subslide_metadata)] | ||||
Jonathan Frederic
|
r12032 | |||
MinRK
|
r18580 | return nbformat.new_notebook(cells=cells) | ||
Jonathan Frederic
|
r12032 | |||
Jonathan Frederic
|
r12035 | |||
Paul Ivanov
|
r12219 | def build_preprocessor(self): | ||
"""Make an instance of a preprocessor""" | ||||
preprocessor = RevealHelpPreprocessor() | ||||
preprocessor.enabled = True | ||||
return preprocessor | ||||
Jonathan Frederic
|
r12035 | |||
def test_constructor(self): | ||||
Paul Ivanov
|
r12219 | """Can a RevealHelpPreprocessor be constructed?""" | ||
self.build_preprocessor() | ||||
damianavila
|
r16869 | |||
Jonathan Frederic
|
r12032 | |||
def test_reveal_attribute(self): | ||||
"""Make sure the reveal url_prefix resources is set""" | ||||
Jonathan Frederic
|
r12039 | nb = self.build_notebook() | ||
res = self.build_resources() | ||||
Paul Ivanov
|
r12219 | preprocessor = self.build_preprocessor() | ||
nb, res = preprocessor(nb, res) | ||||
Jonathan Frederic
|
r12032 | assert 'reveal' in res | ||
assert 'url_prefix' in res['reveal'] | ||||
def test_reveal_output(self): | ||||
Paul Ivanov
|
r12219 | """Make sure that the reveal preprocessor """ | ||
Jonathan Frederic
|
r12039 | nb = self.build_notebook() | ||
res = self.build_resources() | ||||
Paul Ivanov
|
r12219 | preprocessor = self.build_preprocessor() | ||
nb, res = preprocessor(nb, res) | ||||
MinRK
|
r18580 | cells = nb.cells | ||
Jonathan Frederic
|
r12032 | |||
# Make sure correct metadata tags are available on every cell. | ||||
Jonathan Frederic
|
r12035 | for cell in cells: | ||
assert 'slide_type' in cell.metadata | ||||
Jonathan Frederic
|
r12032 | |||
# Make sure slide end is only applied to the cells preceeding slide | ||||
# cells. | ||||
damianavila
|
r16869 | assert 'slide_helper' in cells[1].metadata | ||
self.assertEqual(cells[1].metadata['slide_helper'], '-') | ||||
Jonathan Frederic
|
r12032 | |||
# Verify 'slide-end' | ||||
assert 'slide_helper' in cells[0].metadata | ||||
self.assertEqual(cells[0].metadata['slide_helper'], 'slide_end') | ||||
assert 'slide_helper' in cells[2].metadata | ||||
self.assertEqual(cells[2].metadata['slide_helper'], 'slide_end') | ||||
assert 'slide_helper' in cells[3].metadata | ||||
self.assertEqual(cells[3].metadata['slide_helper'], 'subslide_end') | ||||