##// END OF EJS Templates
Added tests for nb2nb Exporter...
Jonathan Frederic -
Show More
@@ -0,0 +1,59 b''
1 """
2 Module with tests for exporter.py
3 """
4
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
17 from IPython.config import Config
18
19 from .base import ExportersTestsBase
20 from ...preprocessors.base import Preprocessor
21 from ..exporter import Exporter
22
23
24 #-----------------------------------------------------------------------------
25 # Class
26 #-----------------------------------------------------------------------------
27
28 class PizzaPreprocessor(Preprocessor):
29 """Simple preprocessor that adds a 'pizza' entry to the NotebookNode. Used
30 to test Exporter.
31 """
32
33 def preprocess(self, nb, resources):
34 nb['pizza'] = 'cheese'
35 return nb, resources
36
37
38 class TestExporter(ExportersTestsBase):
39 """Contains test functions for exporter.py"""
40
41
42 def test_constructor(self):
43 """Can an Exporter be constructed?"""
44 Exporter()
45
46
47 def test_export(self):
48 """Can an Exporter export something?"""
49 exporter = Exporter()
50 (notebook, resources) = exporter.from_filename(self._get_notebook())
51 assert isinstance(notebook, dict)
52
53
54 def test_preprocessor(self):
55 """Do preprocessors work?"""
56 config = Config({'Exporter': {'preprocessors': [PizzaPreprocessor()]}})
57 exporter = Exporter(config=config)
58 (notebook, resources) = exporter.from_filename(self._get_notebook())
59 self.assertEqual(notebook['pizza'], 'cheese')
@@ -1,5 +1,5 b''
1 """
1 """
2 Module with tests for exporter.py
2 Module with tests for templateexporter.py
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
@@ -31,14 +31,14 b' class TestExporter(ExportersTestsBase):'
31
31
32 def test_constructor(self):
32 def test_constructor(self):
33 """
33 """
34 Can an TemplateExporter be constructed?
34 Can a TemplateExporter be constructed?
35 """
35 """
36 TemplateExporter()
36 TemplateExporter()
37
37
38
38
39 def test_export(self):
39 def test_export(self):
40 """
40 """
41 Can an Exporter export something?
41 Can a TemplateExporter export something?
42 """
42 """
43 exporter = self._make_exporter()
43 exporter = self._make_exporter()
44 (output, resources) = exporter.from_filename(self._get_notebook())
44 (output, resources) = exporter.from_filename(self._get_notebook())
@@ -102,7 +102,7 b' class TestExporter(ExportersTestsBase):'
102
102
103
103
104 def _make_exporter(self, config=None):
104 def _make_exporter(self, config=None):
105 #Create the exporter instance, make sure to set a template name since
105 # Create the exporter instance, make sure to set a template name since
106 #the base Exporter doesn't have a template associated with it.
106 # the base TemplateExporter doesn't have a template associated with it.
107 exporter = TemplateExporter(config=config, template_file='python')
107 exporter = TemplateExporter(config=config, template_file='python')
108 return exporter
108 return exporter
General Comments 0
You need to be logged in to leave comments. Login now