##// END OF EJS Templates
Merge pull request #8085 from minrk/nbconvert-tests...
Thomas Kluyver -
r20738:f2b097ea merge
parent child Browse files
Show More
@@ -1,54 +1,38
1 1 """Base TestCase class for testing Exporters"""
2 2
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2013, the IPython Development Team.
5 #
3 # Copyright (c) IPython Development Team.
6 4 # Distributed under the terms of the Modified BSD License.
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
14 5
15 6 import os
16 7
17 from IPython.testing.decorators import onlyif_any_cmd_exists
18
19 8 from ...tests.base import TestsBase
20 9
21 #-----------------------------------------------------------------------------
22 # Class
23 #-----------------------------------------------------------------------------
24
25 10 all_raw_mimetypes = {
26 11 'text/x-python',
27 12 'text/markdown',
28 13 'text/html',
29 14 'text/restructuredtext',
30 15 'text/latex',
31 16 }
32 17
33 18 class ExportersTestsBase(TestsBase):
34 19 """Contains base test functions for exporters"""
35 20
36 21 exporter_class = None
37 22 should_include_raw = None
38 23
39 24 def _get_notebook(self, nb_name='notebook2.ipynb'):
40 25 return os.path.join(self._get_files_path(), nb_name)
41 26
42 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
43 27 def test_raw_cell_inclusion(self):
44 28 """test raw cell inclusion based on raw_mimetype metadata"""
45 29 if self.should_include_raw is None:
46 30 return
47 31 exporter = self.exporter_class()
48 32 (output, resources) = exporter.from_filename(self._get_notebook('rawtest.ipynb'))
49 33 for inc in self.should_include_raw:
50 34 self.assertIn('raw %s' % inc, output, "should include %s" % inc)
51 35 self.assertIn('no raw_mimetype metadata', output)
52 36 for exc in all_raw_mimetypes.difference(self.should_include_raw):
53 37 self.assertNotIn('raw %s' % exc, output, "should exclude %s" % exc)
54 38 self.assertNotIn('never be included', output)
@@ -1,86 +1,68
1 1 """Tests for HTMLExporter"""
2 2
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2013, the IPython Development Team.
5 #
3 # Copyright (c) IPython Development Team.
6 4 # Distributed under the terms of the Modified BSD License.
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
14 5
15 6 from .base import ExportersTestsBase
16 7 from ..html import HTMLExporter
17 from IPython.testing.decorators import onlyif_any_cmd_exists
18 8 import re
19 9
20 #-----------------------------------------------------------------------------
21 # Class
22 #-----------------------------------------------------------------------------
23 10
24 11 class TestHTMLExporter(ExportersTestsBase):
25 12 """Tests for HTMLExporter"""
26 13
27 14 exporter_class = HTMLExporter
28 15 should_include_raw = ['html']
29 16
30 17 def test_constructor(self):
31 18 """
32 19 Can a HTMLExporter be constructed?
33 20 """
34 21 HTMLExporter()
35 22
36 23
37 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
38 24 def test_export(self):
39 25 """
40 26 Can a HTMLExporter export something?
41 27 """
42 28 (output, resources) = HTMLExporter().from_filename(self._get_notebook())
43 29 assert len(output) > 0
44 30
45 31
46 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
47 32 def test_export_basic(self):
48 33 """
49 34 Can a HTMLExporter export using the 'basic' template?
50 35 """
51 36 (output, resources) = HTMLExporter(template_file='basic').from_filename(self._get_notebook())
52 37 assert len(output) > 0
53 38
54 39
55 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
56 40 def test_export_full(self):
57 41 """
58 42 Can a HTMLExporter export using the 'full' template?
59 43 """
60 44 (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook())
61 45 assert len(output) > 0
62 46
63 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
64 47 def test_prompt_number(self):
65 48 """
66 49 Does HTMLExporter properly format input and output prompts?
67 50 """
68 51 (output, resources) = HTMLExporter(template_file='full').from_filename(
69 52 self._get_notebook(nb_name="prompt_numbers.ipynb"))
70 53 in_regex = r"In \[(.*)\]:"
71 54 out_regex = r"Out\[(.*)\]:"
72 55
73 56 ins = ["2", "10", " ", " ", "*", "0"]
74 57 outs = ["10"]
75 58
76 59 assert re.findall(in_regex, output) == ins
77 60 assert re.findall(out_regex, output) == outs
78 61
79 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
80 62 def test_png_metadata(self):
81 63 """
82 64 Does HTMLExporter with the 'basic' template treat pngs with width/height metadata correctly?
83 65 """
84 66 (output, resources) = HTMLExporter(template_file='basic').from_filename(
85 67 self._get_notebook(nb_name="pngmetadata.ipynb"))
86 68 assert len(output) > 0
@@ -1,51 +1,36
1 1 """Tests for SlidesExporter"""
2 2
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2013, the IPython Development Team.
5 #
3 # Copyright (c) IPython Development Team.
6 4 # Distributed under the terms of the Modified BSD License.
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
14 5
15 6 from .base import ExportersTestsBase
16 7 from ..slides import SlidesExporter
17 from IPython.testing.decorators import onlyif_any_cmd_exists
18 8
19 #-----------------------------------------------------------------------------
20 # Class
21 #-----------------------------------------------------------------------------
22 9
23 10 class TestSlidesExporter(ExportersTestsBase):
24 11 """Tests for SlidesExporter"""
25 12
26 13 exporter_class = SlidesExporter
27 14 should_include_raw = ['html']
28 15
29 16 def test_constructor(self):
30 17 """
31 18 Can a SlidesExporter be constructed?
32 19 """
33 20 SlidesExporter()
34 21
35 22
36 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
37 23 def test_export(self):
38 24 """
39 25 Can a SlidesExporter export something?
40 26 """
41 27 (output, resources) = SlidesExporter().from_filename(self._get_notebook())
42 28 assert len(output) > 0
43 29
44 30
45 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
46 31 def test_export_reveal(self):
47 32 """
48 33 Can a SlidesExporter export using the 'reveal' template?
49 34 """
50 35 (output, resources) = SlidesExporter(template_file='slides_reveal').from_filename(self._get_notebook())
51 36 assert len(output) > 0
General Comments 0
You need to be logged in to leave comments. Login now