##// END OF EJS Templates
Use new license
Julia Evans -
Show More
@@ -1,36 +1,31 b''
1 """IPython Notebook Exporter class"""
1 """IPython Notebook Exporter class"""
2
2
3 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Copyright (c) 2013, the IPython Development Team.
5 #
6 # Distributed under the terms of the Modified BSD License.
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
5
11 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
12 # Imports
7 # Imports
13 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
14
9
15 from .exporter import Exporter
10 from .exporter import Exporter
16 from IPython.nbformat import current as nbformat
11 from IPython.nbformat import current as nbformat
17
12
18 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
19 # Classes
14 # Classes
20 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
21
16
22 class NotebookExporter(Exporter):
17 class NotebookExporter(Exporter):
23 """
18 """
24 Exports an IPython notebook.
19 Exports an IPython notebook.
25 """
20 """
26 def _file_extension_default(self):
21 def _file_extension_default(self):
27 return 'ipynb'
22 return 'ipynb'
28
23
29 output_mimetype = 'application/json'
24 output_mimetype = 'application/json'
30
25
31 def from_notebook_node(self, nb, resources=None, **kw):
26 def from_notebook_node(self, nb, resources=None, **kw):
32 nb_copy, resources = super(NotebookExporter, self).from_notebook_node(nb, resources, **kw)
27 nb_copy, resources = super(NotebookExporter, self).from_notebook_node(nb, resources, **kw)
33 output = nbformat.writes_json(nb_copy)
28 output = nbformat.writes_json(nb_copy)
34 return output, resources
29 return output, resources
35
30
36
31
@@ -1,45 +1,40 b''
1 """
1 """
2 Module with tests for notebook.py
2 Module with tests for notebook.py
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 # Copyright (c) IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
6 # 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
7
13 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
14 # Imports
9 # Imports
15 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
16
11
17 from .base import ExportersTestsBase
12 from .base import ExportersTestsBase
18 from ..notebook import NotebookExporter
13 from ..notebook import NotebookExporter
19
14
20 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
21 # Class
16 # Class
22 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
23
18
24 class TestNotebookExporter(ExportersTestsBase):
19 class TestNotebookExporter(ExportersTestsBase):
25 """Contains test functions for notebook.py"""
20 """Contains test functions for notebook.py"""
26
21
27 exporter_class = NotebookExporter
22 exporter_class = NotebookExporter
28
23
29 def test_constructor(self):
24 def test_constructor(self):
30 """
25 """
31 Can a NotebookExporter be constructed?
26 Can a NotebookExporter be constructed?
32 """
27 """
33 NotebookExporter()
28 NotebookExporter()
34
29
35
30
36 def test_export(self):
31 def test_export(self):
37 """
32 """
38 Does the NotebookExporter return the file unchanged?
33 Does the NotebookExporter return the file unchanged?
39 """
34 """
40 with open(self._get_notebook()) as f:
35 with open(self._get_notebook()) as f:
41 file_contents = f.read()
36 file_contents = f.read()
42 (output, resources) = NotebookExporter().from_filename(self._get_notebook())
37 (output, resources) = NotebookExporter().from_filename(self._get_notebook())
43 assert len(output) > 0
38 assert len(output) > 0
44 assert output == file_contents
39 assert output == file_contents
45
40
General Comments 0
You need to be logged in to leave comments. Login now