##// 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,6 +1,4 b''
1 """
2 Module with tests base for exporters
3 """
1 """Base TestCase class for testing Exporters"""
4 2
5 3 #-----------------------------------------------------------------------------
6 4 # Copyright (c) 2013, the IPython Development Team.
@@ -16,15 +14,35 b' Module with tests base for exporters'
16 14
17 15 import os
18 16
17 from IPython.testing.decorators import onlyif_cmds_exist
18
19 19 from ...tests.base import TestsBase
20 20
21 21 #-----------------------------------------------------------------------------
22 22 # Class
23 23 #-----------------------------------------------------------------------------
24 24
25 all_raw_formats = set(['markdown', 'html', 'rst', 'python', 'latex'])
26
25 27 class ExportersTestsBase(TestsBase):
26 28 """Contains base test functions for exporters"""
27
28 def _get_notebook(self):
29 return os.path.join(self._get_files_path(), 'notebook2.ipynb')
30
29
30 exporter_class = None
31 should_include_raw = None
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,6 +1,4 b''
1 """
2 Module with tests for html.py
3 """
1 """Tests for HTMLExporter"""
4 2
5 3 #-----------------------------------------------------------------------------
6 4 # Copyright (c) 2013, the IPython Development Team.
@@ -23,7 +21,10 b' from IPython.testing.decorators import onlyif_cmds_exist'
23 21 #-----------------------------------------------------------------------------
24 22
25 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 29 def test_constructor(self):
29 30 """
@@ -57,3 +58,4 b' class TestHTMLExporter(ExportersTestsBase):'
57 58 """
58 59 (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook())
59 60 assert len(output) > 0
61
@@ -25,6 +25,9 b' from IPython.testing.decorators import onlyif_cmds_exist'
25 25 class TestLatexExporter(ExportersTestsBase):
26 26 """Contains test functions for latex.py"""
27 27
28 exporter_class = LatexExporter
29 should_include_raw = ['latex']
30
28 31 def test_constructor(self):
29 32 """
30 33 Can a LatexExporter be constructed?
@@ -1,6 +1,4 b''
1 """
2 Module with tests for markdown.py
3 """
1 """Tests for MarkdownExporter"""
4 2
5 3 #-----------------------------------------------------------------------------
6 4 # Copyright (c) 2013, the IPython Development Team.
@@ -22,7 +20,10 b' from ..markdown import MarkdownExporter'
22 20 #-----------------------------------------------------------------------------
23 21
24 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 28 def test_constructor(self):
28 29 """
@@ -1,6 +1,4 b''
1 """
2 Module with tests for python.py
3 """
1 """Tests for PythonExporter"""
4 2
5 3 #-----------------------------------------------------------------------------
6 4 # Copyright (c) 2013, the IPython Development Team.
@@ -22,7 +20,10 b' from ..python import PythonExporter'
22 20 #-----------------------------------------------------------------------------
23 21
24 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 28 def test_constructor(self):
28 29 """
@@ -1,6 +1,4 b''
1 """
2 Module with tests for rst.py
3 """
1 """Tests for RSTExporter"""
4 2
5 3 #-----------------------------------------------------------------------------
6 4 # Copyright (c) 2013, the IPython Development Team.
@@ -23,7 +21,10 b' from IPython.testing.decorators import onlyif_cmds_exist'
23 21 #-----------------------------------------------------------------------------
24 22
25 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 29 def test_constructor(self):
29 30 """
@@ -1,6 +1,4 b''
1 """
2 Module with tests for slides.py
3 """
1 """Tests for SlidesExporter"""
4 2
5 3 #-----------------------------------------------------------------------------
6 4 # Copyright (c) 2013, the IPython Development Team.
@@ -23,7 +21,10 b' from IPython.testing.decorators import onlyif_cmds_exist'
23 21 #-----------------------------------------------------------------------------
24 22
25 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 29 def test_constructor(self):
29 30 """
General Comments 0
You need to be logged in to leave comments. Login now