Show More
@@ -0,0 +1,93 b'' | |||||
|
1 | """ | |||
|
2 | Module with tests for the revealhelp transformer | |||
|
3 | """ | |||
|
4 | ||||
|
5 | #----------------------------------------------------------------------------- | |||
|
6 | # Copyright (c) 2013, the IPython Development Team. | |||
|
7 | # | |||
|
8 | # Distributed under the terms of the Modified BSD License. | |||
|
9 | # | |||
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |||
|
11 | #----------------------------------------------------------------------------- | |||
|
12 | ||||
|
13 | #----------------------------------------------------------------------------- | |||
|
14 | # Imports | |||
|
15 | #----------------------------------------------------------------------------- | |||
|
16 | ||||
|
17 | from IPython.nbformat import current as nbformat | |||
|
18 | ||||
|
19 | from .base import TransformerTestsBase | |||
|
20 | from ..revealhelp import RevealHelpTransformer | |||
|
21 | ||||
|
22 | ||||
|
23 | #----------------------------------------------------------------------------- | |||
|
24 | # Class | |||
|
25 | #----------------------------------------------------------------------------- | |||
|
26 | ||||
|
27 | class Testrevealhelp(TransformerTestsBase): | |||
|
28 | """Contains test functions for revealhelp.py""" | |||
|
29 | ||||
|
30 | def build_notebook(self): | |||
|
31 | """Build a reveal slides notebook in memory for use with tests. | |||
|
32 | Overrides base in TransformerTestsBase""" | |||
|
33 | ||||
|
34 | outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a")] | |||
|
35 | ||||
|
36 | slide_metadata = {'slideshow' : {'slide_type': 'slide'}} | |||
|
37 | subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} | |||
|
38 | ||||
|
39 | cells=[nbformat.new_code_cell(input="", prompt_number=1, outputs=outputs), | |||
|
40 | nbformat.new_text_cell('markdown', source="", metadata=slide_metadata), | |||
|
41 | nbformat.new_code_cell(input="", prompt_number=2, outputs=outputs), | |||
|
42 | nbformat.new_text_cell('markdown', source="", metadata=slide_metadata), | |||
|
43 | nbformat.new_text_cell('markdown', source="", metadata=subslide_metadata)] | |||
|
44 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] | |||
|
45 | ||||
|
46 | return nbformat.new_notebook(name="notebook1", worksheets=worksheets) | |||
|
47 | ||||
|
48 | def test_constructor(self): | |||
|
49 | """Can a RevealHelpTransformer be constructed?""" | |||
|
50 | transformer = RevealHelpTransformer() | |||
|
51 | transformer.enabled = True | |||
|
52 | return transformer | |||
|
53 | ||||
|
54 | ||||
|
55 | def test_reveal_attribute(self): | |||
|
56 | """Make sure the reveal url_prefix resources is set""" | |||
|
57 | nb, res = self.test_constructor()(self.build_notebook(), self.build_resources()) | |||
|
58 | assert 'reveal' in res | |||
|
59 | assert 'url_prefix' in res['reveal'] | |||
|
60 | ||||
|
61 | ||||
|
62 | def test_reveal_output(self): | |||
|
63 | """Make sure that the reveal transformer """ | |||
|
64 | nb, res = self.test_constructor()(self.build_notebook(), self.build_resources()) | |||
|
65 | cells = nb.worksheets[0].cells | |||
|
66 | ||||
|
67 | # Make sure correct metadata tags are available on every cell. | |||
|
68 | assert 'slide_type' in cells[0].metadata | |||
|
69 | assert 'align_type' in cells[0].metadata | |||
|
70 | ||||
|
71 | assert 'slide_type' in cells[1].metadata | |||
|
72 | assert 'align_type' in cells[1].metadata | |||
|
73 | ||||
|
74 | assert 'slide_type' in cells[2].metadata | |||
|
75 | assert 'align_type' in cells[2].metadata | |||
|
76 | ||||
|
77 | assert 'slide_type' in cells[3].metadata | |||
|
78 | assert 'align_type' in cells[3].metadata | |||
|
79 | ||||
|
80 | assert 'slide_type' in cells[4].metadata | |||
|
81 | assert 'align_type' in cells[4].metadata | |||
|
82 | ||||
|
83 | # Make sure slide end is only applied to the cells preceeding slide | |||
|
84 | # cells. | |||
|
85 | assert 'slide_helper' not in cells[1].metadata | |||
|
86 | ||||
|
87 | # Verify 'slide-end' | |||
|
88 | assert 'slide_helper' in cells[0].metadata | |||
|
89 | self.assertEqual(cells[0].metadata['slide_helper'], 'slide_end') | |||
|
90 | assert 'slide_helper' in cells[2].metadata | |||
|
91 | self.assertEqual(cells[2].metadata['slide_helper'], 'slide_end') | |||
|
92 | assert 'slide_helper' in cells[3].metadata | |||
|
93 | self.assertEqual(cells[3].metadata['slide_helper'], 'subslide_end') |
General Comments 0
You need to be logged in to leave comments.
Login now