Show More
@@ -1,68 +1,85 b'' | |||
|
1 | 1 | """Tests for HTMLExporter""" |
|
2 | 2 | |
|
3 | 3 | # Copyright (c) IPython Development Team. |
|
4 | 4 | # Distributed under the terms of the Modified BSD License. |
|
5 | 5 | |
|
6 | 6 | from .base import ExportersTestsBase |
|
7 | 7 | from ..html import HTMLExporter |
|
8 | from IPython.nbformat import v4 | |
|
8 | 9 | import re |
|
9 | 10 | |
|
10 | 11 | |
|
11 | 12 | class TestHTMLExporter(ExportersTestsBase): |
|
12 | 13 | """Tests for HTMLExporter""" |
|
13 | 14 | |
|
14 | 15 | exporter_class = HTMLExporter |
|
15 | 16 | should_include_raw = ['html'] |
|
16 | 17 | |
|
17 | 18 | def test_constructor(self): |
|
18 | 19 | """ |
|
19 | 20 | Can a HTMLExporter be constructed? |
|
20 | 21 | """ |
|
21 | 22 | HTMLExporter() |
|
22 | 23 | |
|
23 | 24 | |
|
24 | 25 | def test_export(self): |
|
25 | 26 | """ |
|
26 | 27 | Can a HTMLExporter export something? |
|
27 | 28 | """ |
|
28 | 29 | (output, resources) = HTMLExporter().from_filename(self._get_notebook()) |
|
29 | 30 | assert len(output) > 0 |
|
30 | 31 | |
|
31 | 32 | |
|
32 | 33 | def test_export_basic(self): |
|
33 | 34 | """ |
|
34 | 35 | Can a HTMLExporter export using the 'basic' template? |
|
35 | 36 | """ |
|
36 | 37 | (output, resources) = HTMLExporter(template_file='basic').from_filename(self._get_notebook()) |
|
37 | 38 | assert len(output) > 0 |
|
38 | 39 | |
|
39 | 40 | |
|
40 | 41 | def test_export_full(self): |
|
41 | 42 | """ |
|
42 | 43 | Can a HTMLExporter export using the 'full' template? |
|
43 | 44 | """ |
|
44 | 45 | (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook()) |
|
45 | 46 | assert len(output) > 0 |
|
46 | 47 | |
|
47 | 48 | def test_prompt_number(self): |
|
48 | 49 | """ |
|
49 | 50 | Does HTMLExporter properly format input and output prompts? |
|
50 | 51 | """ |
|
51 | 52 | (output, resources) = HTMLExporter(template_file='full').from_filename( |
|
52 | 53 | self._get_notebook(nb_name="prompt_numbers.ipynb")) |
|
53 | 54 | in_regex = r"In \[(.*)\]:" |
|
54 | 55 | out_regex = r"Out\[(.*)\]:" |
|
55 | 56 | |
|
56 | 57 | ins = ["2", "10", " ", " ", "*", "0"] |
|
57 | 58 | outs = ["10"] |
|
58 | 59 | |
|
59 | 60 | assert re.findall(in_regex, output) == ins |
|
60 | 61 | assert re.findall(out_regex, output) == outs |
|
61 | 62 | |
|
62 | 63 | def test_png_metadata(self): |
|
63 | 64 | """ |
|
64 | 65 | Does HTMLExporter with the 'basic' template treat pngs with width/height metadata correctly? |
|
65 | 66 | """ |
|
66 | 67 | (output, resources) = HTMLExporter(template_file='basic').from_filename( |
|
67 | 68 | self._get_notebook(nb_name="pngmetadata.ipynb")) |
|
68 | 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