##// END OF EJS Templates
test raw cell inclusion based on raw_format metadata
MinRK -
Show More
@@ -0,0 +1,84 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "raw",
12 "metadata": {
13 "raw_format": "html"
14 },
15 "source": [
16 "<b>raw html</b>"
17 ]
18 },
19 {
20 "cell_type": "raw",
21 "metadata": {
22 "raw_format": "markdown"
23 },
24 "source": [
25 "* raw markdown\n",
26 "* bullet\n",
27 "* list"
28 ]
29 },
30 {
31 "cell_type": "raw",
32 "metadata": {
33 "raw_format": "rst"
34 },
35 "source": [
36 "``raw rst``\n",
37 "\n",
38 ".. sourcecode:: python\n",
39 "\n",
40 " def foo(): pass\n"
41 ]
42 },
43 {
44 "cell_type": "raw",
45 "metadata": {
46 "raw_format": "python"
47 },
48 "source": [
49 "def bar():\n",
50 " \"\"\"raw python\"\"\"\n",
51 " pass"
52 ]
53 },
54 {
55 "cell_type": "raw",
56 "metadata": {
57 "raw_format": "latex"
58 },
59 "source": [
60 "\\LaTeX\n",
61 "% raw latex"
62 ]
63 },
64 {
65 "cell_type": "raw",
66 "metadata": {},
67 "source": [
68 "# no raw_format metadata, should be included by default"
69 ]
70 },
71 {
72 "cell_type": "raw",
73 "metadata": {
74 "raw_format": "doesnotexist"
75 },
76 "source": [
77 "garbage format defined, should never be included"
78 ]
79 }
80 ],
81 "metadata": {}
82 }
83 ]
84 } No newline at end of file
@@ -1,30 +1,48 b''
1 """
1 """Base TestCase class for testing Exporters"""
2 Module with tests base for exporters
3 """
4
2
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
4 # Copyright (c) 2013, the IPython Development Team.
7 #
5 #
8 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
9 #
7 #
10 # The full license is in the file COPYING.txt, distributed with this software.
8 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
12
10
13 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
14 # Imports
12 # Imports
15 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
16
14
17 import os
15 import os
18
16
17 from IPython.testing.decorators import onlyif_cmds_exist
18
19 from ...tests.base import TestsBase
19 from ...tests.base import TestsBase
20
20
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # Class
22 # Class
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 all_raw_formats = set(['markdown', 'html', 'rst', 'python', 'latex'])
26
25 class ExportersTestsBase(TestsBase):
27 class ExportersTestsBase(TestsBase):
26 """Contains base test functions for exporters"""
28 """Contains base test functions for exporters"""
27
29
28 def _get_notebook(self):
30 exporter_class = None
29 return os.path.join(self._get_files_path(), 'notebook2.ipynb')
31 should_include_raw = None
30
32
33 def _get_notebook(self, nb_name='notebook2.ipynb'):
34 return os.path.join(self._get_files_path(), nb_name)
35
36 @onlyif_cmds_exist('pandoc')
37 def test_raw_cell_inclusion(self):
38 """test raw cell inclusion based on raw_format metadata"""
39 if self.should_include_raw is None:
40 return
41 exporter = self.exporter_class()
42 (output, resources) = exporter.from_filename(self._get_notebook('rawtest.ipynb'))
43 for inc in self.should_include_raw:
44 self.assertIn('raw %s' % inc, output, "should include %s" % inc)
45 self.assertIn('no raw_format metadata', output)
46 for exc in all_raw_formats.difference(self.should_include_raw):
47 self.assertNotIn('raw %s' % exc, output, "should exclude %s" % exc)
48 self.assertNotIn('never be included', output)
@@ -1,59 +1,61 b''
1 """
1 """Tests for HTMLExporter"""
2 Module with tests for html.py
3 """
4
2
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
4 # Copyright (c) 2013, the IPython Development Team.
7 #
5 #
8 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
9 #
7 #
10 # The full license is in the file COPYING.txt, distributed with this software.
8 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
12
10
13 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
14 # Imports
12 # Imports
15 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
16
14
17 from .base import ExportersTestsBase
15 from .base import ExportersTestsBase
18 from ..html import HTMLExporter
16 from ..html import HTMLExporter
19 from IPython.testing.decorators import onlyif_cmds_exist
17 from IPython.testing.decorators import onlyif_cmds_exist
20
18
21 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
22 # Class
20 # Class
23 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
24
22
25 class TestHTMLExporter(ExportersTestsBase):
23 class TestHTMLExporter(ExportersTestsBase):
26 """Contains test functions for html.py"""
24 """Tests for HTMLExporter"""
25
26 exporter_class = HTMLExporter
27 should_include_raw = ['html']
27
28
28 def test_constructor(self):
29 def test_constructor(self):
29 """
30 """
30 Can a HTMLExporter be constructed?
31 Can a HTMLExporter be constructed?
31 """
32 """
32 HTMLExporter()
33 HTMLExporter()
33
34
34
35
35 @onlyif_cmds_exist('pandoc')
36 @onlyif_cmds_exist('pandoc')
36 def test_export(self):
37 def test_export(self):
37 """
38 """
38 Can a HTMLExporter export something?
39 Can a HTMLExporter export something?
39 """
40 """
40 (output, resources) = HTMLExporter().from_filename(self._get_notebook())
41 (output, resources) = HTMLExporter().from_filename(self._get_notebook())
41 assert len(output) > 0
42 assert len(output) > 0
42
43
43
44
44 @onlyif_cmds_exist('pandoc')
45 @onlyif_cmds_exist('pandoc')
45 def test_export_basic(self):
46 def test_export_basic(self):
46 """
47 """
47 Can a HTMLExporter export using the 'basic' template?
48 Can a HTMLExporter export using the 'basic' template?
48 """
49 """
49 (output, resources) = HTMLExporter(template_file='basic').from_filename(self._get_notebook())
50 (output, resources) = HTMLExporter(template_file='basic').from_filename(self._get_notebook())
50 assert len(output) > 0
51 assert len(output) > 0
51
52
52
53
53 @onlyif_cmds_exist('pandoc')
54 @onlyif_cmds_exist('pandoc')
54 def test_export_full(self):
55 def test_export_full(self):
55 """
56 """
56 Can a HTMLExporter export using the 'full' template?
57 Can a HTMLExporter export using the 'full' template?
57 """
58 """
58 (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook())
59 (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook())
59 assert len(output) > 0
60 assert len(output) > 0
61
@@ -1,68 +1,71 b''
1 """
1 """
2 Module with tests for latex.py
2 Module with tests for latex.py
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 from .base import ExportersTestsBase
17 from .base import ExportersTestsBase
18 from ..latex import LatexExporter
18 from ..latex import LatexExporter
19 from IPython.testing.decorators import onlyif_cmds_exist
19 from IPython.testing.decorators import onlyif_cmds_exist
20
20
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # Class
22 # Class
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 class TestLatexExporter(ExportersTestsBase):
25 class TestLatexExporter(ExportersTestsBase):
26 """Contains test functions for latex.py"""
26 """Contains test functions for latex.py"""
27
27
28 exporter_class = LatexExporter
29 should_include_raw = ['latex']
30
28 def test_constructor(self):
31 def test_constructor(self):
29 """
32 """
30 Can a LatexExporter be constructed?
33 Can a LatexExporter be constructed?
31 """
34 """
32 LatexExporter()
35 LatexExporter()
33
36
34
37
35 @onlyif_cmds_exist('pandoc')
38 @onlyif_cmds_exist('pandoc')
36 def test_export(self):
39 def test_export(self):
37 """
40 """
38 Can a LatexExporter export something?
41 Can a LatexExporter export something?
39 """
42 """
40 (output, resources) = LatexExporter().from_filename(self._get_notebook())
43 (output, resources) = LatexExporter().from_filename(self._get_notebook())
41 assert len(output) > 0
44 assert len(output) > 0
42
45
43
46
44 @onlyif_cmds_exist('pandoc')
47 @onlyif_cmds_exist('pandoc')
45 def test_export_book(self):
48 def test_export_book(self):
46 """
49 """
47 Can a LatexExporter export using 'report' template?
50 Can a LatexExporter export using 'report' template?
48 """
51 """
49 (output, resources) = LatexExporter(template_file='report').from_filename(self._get_notebook())
52 (output, resources) = LatexExporter(template_file='report').from_filename(self._get_notebook())
50 assert len(output) > 0
53 assert len(output) > 0
51
54
52
55
53 @onlyif_cmds_exist('pandoc')
56 @onlyif_cmds_exist('pandoc')
54 def test_export_basic(self):
57 def test_export_basic(self):
55 """
58 """
56 Can a LatexExporter export using 'article' template?
59 Can a LatexExporter export using 'article' template?
57 """
60 """
58 (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook())
61 (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook())
59 assert len(output) > 0
62 assert len(output) > 0
60
63
61
64
62 @onlyif_cmds_exist('pandoc')
65 @onlyif_cmds_exist('pandoc')
63 def test_export_article(self):
66 def test_export_article(self):
64 """
67 """
65 Can a LatexExporter export using 'article' template?
68 Can a LatexExporter export using 'article' template?
66 """
69 """
67 (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook())
70 (output, resources) = LatexExporter(template_file='article').from_filename(self._get_notebook())
68 assert len(output) > 0 No newline at end of file
71 assert len(output) > 0
@@ -1,39 +1,40 b''
1 """
1 """Tests for MarkdownExporter"""
2 Module with tests for markdown.py
3 """
4
2
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
4 # Copyright (c) 2013, the IPython Development Team.
7 #
5 #
8 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
9 #
7 #
10 # The full license is in the file COPYING.txt, distributed with this software.
8 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
12
10
13 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
14 # Imports
12 # Imports
15 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
16
14
17 from .base import ExportersTestsBase
15 from .base import ExportersTestsBase
18 from ..markdown import MarkdownExporter
16 from ..markdown import MarkdownExporter
19
17
20 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
21 # Class
19 # Class
22 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
23
21
24 class TestMarkdownExporter(ExportersTestsBase):
22 class TestMarkdownExporter(ExportersTestsBase):
25 """Contains test functions for markdown.py"""
23 """Tests for MarkdownExporter"""
24
25 exporter_class = MarkdownExporter
26 should_include_raw = ['markdown', 'html']
26
27
27 def test_constructor(self):
28 def test_constructor(self):
28 """
29 """
29 Can a MarkdownExporter be constructed?
30 Can a MarkdownExporter be constructed?
30 """
31 """
31 MarkdownExporter()
32 MarkdownExporter()
32
33
33
34
34 def test_export(self):
35 def test_export(self):
35 """
36 """
36 Can a MarkdownExporter export something?
37 Can a MarkdownExporter export something?
37 """
38 """
38 (output, resources) = MarkdownExporter().from_filename(self._get_notebook())
39 (output, resources) = MarkdownExporter().from_filename(self._get_notebook())
39 assert len(output) > 0 No newline at end of file
40 assert len(output) > 0
@@ -1,39 +1,40 b''
1 """
1 """Tests for PythonExporter"""
2 Module with tests for python.py
3 """
4
2
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
4 # Copyright (c) 2013, the IPython Development Team.
7 #
5 #
8 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
9 #
7 #
10 # The full license is in the file COPYING.txt, distributed with this software.
8 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
12
10
13 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
14 # Imports
12 # Imports
15 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
16
14
17 from .base import ExportersTestsBase
15 from .base import ExportersTestsBase
18 from ..python import PythonExporter
16 from ..python import PythonExporter
19
17
20 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
21 # Class
19 # Class
22 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
23
21
24 class TestPythonExporter(ExportersTestsBase):
22 class TestPythonExporter(ExportersTestsBase):
25 """Contains test functions for python.py"""
23 """Tests for PythonExporter"""
24
25 exporter_class = PythonExporter
26 should_include_raw = ['python']
26
27
27 def test_constructor(self):
28 def test_constructor(self):
28 """
29 """
29 Can a PythonExporter be constructed?
30 Can a PythonExporter be constructed?
30 """
31 """
31 PythonExporter()
32 PythonExporter()
32
33
33
34
34 def test_export(self):
35 def test_export(self):
35 """
36 """
36 Can a PythonExporter export something?
37 Can a PythonExporter export something?
37 """
38 """
38 (output, resources) = PythonExporter().from_filename(self._get_notebook())
39 (output, resources) = PythonExporter().from_filename(self._get_notebook())
39 assert len(output) > 0 No newline at end of file
40 assert len(output) > 0
@@ -1,41 +1,42 b''
1 """
1 """Tests for RSTExporter"""
2 Module with tests for rst.py
3 """
4
2
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
4 # Copyright (c) 2013, the IPython Development Team.
7 #
5 #
8 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
9 #
7 #
10 # The full license is in the file COPYING.txt, distributed with this software.
8 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
12
10
13 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
14 # Imports
12 # Imports
15 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
16
14
17 from .base import ExportersTestsBase
15 from .base import ExportersTestsBase
18 from ..rst import RSTExporter
16 from ..rst import RSTExporter
19 from IPython.testing.decorators import onlyif_cmds_exist
17 from IPython.testing.decorators import onlyif_cmds_exist
20
18
21 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
22 # Class
20 # Class
23 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
24
22
25 class TestRSTExporter(ExportersTestsBase):
23 class TestRSTExporter(ExportersTestsBase):
26 """Contains test functions for rst.py"""
24 """Tests for RSTExporter"""
25
26 exporter_class = RSTExporter
27 should_include_raw = ['rst']
27
28
28 def test_constructor(self):
29 def test_constructor(self):
29 """
30 """
30 Can a RSTExporter be constructed?
31 Can a RSTExporter be constructed?
31 """
32 """
32 RSTExporter()
33 RSTExporter()
33
34
34
35
35 @onlyif_cmds_exist('pandoc')
36 @onlyif_cmds_exist('pandoc')
36 def test_export(self):
37 def test_export(self):
37 """
38 """
38 Can a RSTExporter export something?
39 Can a RSTExporter export something?
39 """
40 """
40 (output, resources) = RSTExporter().from_filename(self._get_notebook())
41 (output, resources) = RSTExporter().from_filename(self._get_notebook())
41 assert len(output) > 0
42 assert len(output) > 0
@@ -1,50 +1,51 b''
1 """
1 """Tests for SlidesExporter"""
2 Module with tests for slides.py
3 """
4
2
5 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
4 # Copyright (c) 2013, the IPython Development Team.
7 #
5 #
8 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
9 #
7 #
10 # The full license is in the file COPYING.txt, distributed with this software.
8 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
12
10
13 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
14 # Imports
12 # Imports
15 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
16
14
17 from .base import ExportersTestsBase
15 from .base import ExportersTestsBase
18 from ..slides import SlidesExporter
16 from ..slides import SlidesExporter
19 from IPython.testing.decorators import onlyif_cmds_exist
17 from IPython.testing.decorators import onlyif_cmds_exist
20
18
21 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
22 # Class
20 # Class
23 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
24
22
25 class TestSlidesExporter(ExportersTestsBase):
23 class TestSlidesExporter(ExportersTestsBase):
26 """Contains test functions for slides.py"""
24 """Tests for SlidesExporter"""
25
26 exporter_class = SlidesExporter
27 should_include_raw = ['html']
27
28
28 def test_constructor(self):
29 def test_constructor(self):
29 """
30 """
30 Can a SlidesExporter be constructed?
31 Can a SlidesExporter be constructed?
31 """
32 """
32 SlidesExporter()
33 SlidesExporter()
33
34
34
35
35 @onlyif_cmds_exist('pandoc')
36 @onlyif_cmds_exist('pandoc')
36 def test_export(self):
37 def test_export(self):
37 """
38 """
38 Can a SlidesExporter export something?
39 Can a SlidesExporter export something?
39 """
40 """
40 (output, resources) = SlidesExporter().from_filename(self._get_notebook())
41 (output, resources) = SlidesExporter().from_filename(self._get_notebook())
41 assert len(output) > 0
42 assert len(output) > 0
42
43
43
44
44 @onlyif_cmds_exist('pandoc')
45 @onlyif_cmds_exist('pandoc')
45 def test_export_reveal(self):
46 def test_export_reveal(self):
46 """
47 """
47 Can a SlidesExporter export using the 'reveal' template?
48 Can a SlidesExporter export using the 'reveal' template?
48 """
49 """
49 (output, resources) = SlidesExporter(template_file='reveal').from_filename(self._get_notebook())
50 (output, resources) = SlidesExporter(template_file='reveal').from_filename(self._get_notebook())
50 assert len(output) > 0
51 assert len(output) > 0
General Comments 0
You need to be logged in to leave comments. Login now