##// END OF EJS Templates
test that javascript output is included in html export
Min RK -
Show More
@@ -1,68 +1,85 b''
1 """Tests for HTMLExporter"""
1 """Tests for HTMLExporter"""
2
2
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 from .base import ExportersTestsBase
6 from .base import ExportersTestsBase
7 from ..html import HTMLExporter
7 from ..html import HTMLExporter
8 from IPython.nbformat import v4
8 import re
9 import re
9
10
10
11
11 class TestHTMLExporter(ExportersTestsBase):
12 class TestHTMLExporter(ExportersTestsBase):
12 """Tests for HTMLExporter"""
13 """Tests for HTMLExporter"""
13
14
14 exporter_class = HTMLExporter
15 exporter_class = HTMLExporter
15 should_include_raw = ['html']
16 should_include_raw = ['html']
16
17
17 def test_constructor(self):
18 def test_constructor(self):
18 """
19 """
19 Can a HTMLExporter be constructed?
20 Can a HTMLExporter be constructed?
20 """
21 """
21 HTMLExporter()
22 HTMLExporter()
22
23
23
24
24 def test_export(self):
25 def test_export(self):
25 """
26 """
26 Can a HTMLExporter export something?
27 Can a HTMLExporter export something?
27 """
28 """
28 (output, resources) = HTMLExporter().from_filename(self._get_notebook())
29 (output, resources) = HTMLExporter().from_filename(self._get_notebook())
29 assert len(output) > 0
30 assert len(output) > 0
30
31
31
32
32 def test_export_basic(self):
33 def test_export_basic(self):
33 """
34 """
34 Can a HTMLExporter export using the 'basic' template?
35 Can a HTMLExporter export using the 'basic' template?
35 """
36 """
36 (output, resources) = HTMLExporter(template_file='basic').from_filename(self._get_notebook())
37 (output, resources) = HTMLExporter(template_file='basic').from_filename(self._get_notebook())
37 assert len(output) > 0
38 assert len(output) > 0
38
39
39
40
40 def test_export_full(self):
41 def test_export_full(self):
41 """
42 """
42 Can a HTMLExporter export using the 'full' template?
43 Can a HTMLExporter export using the 'full' template?
43 """
44 """
44 (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook())
45 (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook())
45 assert len(output) > 0
46 assert len(output) > 0
46
47
47 def test_prompt_number(self):
48 def test_prompt_number(self):
48 """
49 """
49 Does HTMLExporter properly format input and output prompts?
50 Does HTMLExporter properly format input and output prompts?
50 """
51 """
51 (output, resources) = HTMLExporter(template_file='full').from_filename(
52 (output, resources) = HTMLExporter(template_file='full').from_filename(
52 self._get_notebook(nb_name="prompt_numbers.ipynb"))
53 self._get_notebook(nb_name="prompt_numbers.ipynb"))
53 in_regex = r"In \[(.*)\]:"
54 in_regex = r"In \[(.*)\]:"
54 out_regex = r"Out\[(.*)\]:"
55 out_regex = r"Out\[(.*)\]:"
55
56
56 ins = ["2", "10", " ", " ", "*", "0"]
57 ins = ["2", "10", " ", " ", "*", "0"]
57 outs = ["10"]
58 outs = ["10"]
58
59
59 assert re.findall(in_regex, output) == ins
60 assert re.findall(in_regex, output) == ins
60 assert re.findall(out_regex, output) == outs
61 assert re.findall(out_regex, output) == outs
61
62
62 def test_png_metadata(self):
63 def test_png_metadata(self):
63 """
64 """
64 Does HTMLExporter with the 'basic' template treat pngs with width/height metadata correctly?
65 Does HTMLExporter with the 'basic' template treat pngs with width/height metadata correctly?
65 """
66 """
66 (output, resources) = HTMLExporter(template_file='basic').from_filename(
67 (output, resources) = HTMLExporter(template_file='basic').from_filename(
67 self._get_notebook(nb_name="pngmetadata.ipynb"))
68 self._get_notebook(nb_name="pngmetadata.ipynb"))
68 assert len(output) > 0
69 assert len(output) > 0
70
71 def test_javascript_output(self):
72 nb = v4.new_notebook(
73 cells=[
74 v4.new_code_cell(
75 outputs=[v4.new_output(
76 output_type='display_data',
77 data={
78 'application/javascript': "javascript_output();"
79 }
80 )]
81 )
82 ]
83 )
84 (output, resources) = HTMLExporter(template_file='basic').from_notebook_node(nb)
85 self.assertIn('javascript_output', output)
General Comments 0
You need to be logged in to leave comments. Login now