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