##// END OF EJS Templates
enable reading v4 notebooks...
Min RK -
Show More
@@ -21,11 +21,13 b' import json'
21 from . import v1
21 from . import v1
22 from . import v2
22 from . import v2
23 from . import v3
23 from . import v3
24 from . import v4
24
25
25 versions = {
26 versions = {
26 1: v1,
27 1: v1,
27 2: v2,
28 2: v2,
28 3: v3,
29 3: v3,
30 4: v4,
29 }
31 }
30
32
31 #-----------------------------------------------------------------------------
33 #-----------------------------------------------------------------------------
@@ -1,31 +1,19 b''
1 """
1 """
2 Contains tests class for current.py
2 Contains tests class for current.py
3 """
3 """
4 #-----------------------------------------------------------------------------
5 # Copyright (C) 2013 The IPython Development Team
6 #
7 # Distributed under the terms of the BSD License. The full license is in
8 # the file COPYING, distributed as part of this software.
9 #-----------------------------------------------------------------------------
10
4
11 #-----------------------------------------------------------------------------
5 # Copyright (c) IPython Development Team.
12 # Imports
6 # Distributed under the terms of the Modified BSD License.
13 #-----------------------------------------------------------------------------
14
7
15 from .base import TestsBase
8 from .base import TestsBase
16
9
17 from ..reader import get_version
10 from ..reader import get_version
18 from ..current import read, current_nbformat
11 from ..current import read, current_nbformat
19
12
20 #-----------------------------------------------------------------------------
21 # Classes and functions
22 #-----------------------------------------------------------------------------
23
24 class TestCurrent(TestsBase):
13 class TestCurrent(TestsBase):
25
14
26 def test_read(self):
15 def test_read_v2(self):
27 """Can older notebooks be opened and automatically converted to the current
16 """Can v2 notebooks be opened into the current nbformat?"""
28 nbformat?"""
29
17
30 # Open a version 2 notebook.
18 # Open a version 2 notebook.
31 with self.fopen(u'test2.ipynb', u'r') as f:
19 with self.fopen(u'test2.ipynb', u'r') as f:
@@ -34,3 +22,14 b' class TestCurrent(TestsBase):'
34 # Check that the notebook was upgraded to the latest version automatically.
22 # Check that the notebook was upgraded to the latest version automatically.
35 (major, minor) = get_version(nb)
23 (major, minor) = get_version(nb)
36 self.assertEqual(major, current_nbformat)
24 self.assertEqual(major, current_nbformat)
25
26 def test_read_v4(self):
27 """Can v4 notebooks be opened into the current nbformat?"""
28
29 # open a v4 notebook
30 with self.fopen(u'test4.ipynb', u'r') as f:
31 nb = read(f, u'json')
32
33 # Check that the notebook was converted to current automatically.
34 (major, minor) = get_version(nb)
35 self.assertEqual(major, current_nbformat)
@@ -13,12 +13,11 b' from ..nbbase import ('
13 png = encodestring(os.urandom(5)).decode('ascii')
13 png = encodestring(os.urandom(5)).decode('ascii')
14 jpeg = encodestring(os.urandom(6)).decode('ascii')
14 jpeg = encodestring(os.urandom(6)).decode('ascii')
15
15
16 ws = new_worksheet(name='worksheet1')
16 ws = new_worksheet()
17
17
18 ws.cells.append(new_text_cell(
18 ws.cells.append(new_text_cell(
19 u'html',
19 u'html',
20 source='Some NumPy Examples',
20 source='Some NumPy Examples',
21 rendered='Some NumPy Examples'
22 ))
21 ))
23
22
24
23
@@ -31,7 +30,6 b' ws.cells.append(new_code_cell('
31 ws.cells.append(new_text_cell(
30 ws.cells.append(new_text_cell(
32 u'markdown',
31 u'markdown',
33 source='A random array',
32 source='A random array',
34 rendered='A random array'
35 ))
33 ))
36
34
37 ws.cells.append(new_text_cell(
35 ws.cells.append(new_text_cell(
@@ -70,7 +68,7 b' ws.cells.append(new_code_cell('
70 output_png=png,
68 output_png=png,
71 output_jpeg=jpeg,
69 output_jpeg=jpeg,
72 output_svg=u'<svg>',
70 output_svg=u'<svg>',
73 output_json=u'json data',
71 output_json=u'{"json": "data"}',
74 output_javascript=u'var i=0;',
72 output_javascript=u'var i=0;',
75 prompt_number=3
73 prompt_number=3
76 ),new_output(
74 ),new_output(
@@ -81,7 +79,7 b' ws.cells.append(new_code_cell('
81 output_png=png,
79 output_png=png,
82 output_jpeg=jpeg,
80 output_jpeg=jpeg,
83 output_svg=u'<svg>',
81 output_svg=u'<svg>',
84 output_json=u'json data',
82 output_json=u'{"json": "data"}',
85 output_javascript=u'var i=0;'
83 output_javascript=u'var i=0;'
86 ),new_output(
84 ),new_output(
87 output_type=u'pyerr',
85 output_type=u'pyerr',
@@ -104,7 +102,7 b" md = new_metadata(name=u'My Notebook',license=u'BSD',created=u'8601_goes_here',"
104 modified=u'8601_goes_here',gistid=u'21341231',authors=authors)
102 modified=u'8601_goes_here',gistid=u'21341231',authors=authors)
105
103
106 nb0 = new_notebook(
104 nb0 = new_notebook(
107 worksheets=[ws, new_worksheet(name='worksheet2')],
105 worksheets=[ws, new_worksheet()],
108 metadata=md
106 metadata=md
109 )
107 )
110
108
@@ -12,15 +12,10 b' from .nbbase import ('
12 )
12 )
13
13
14 from IPython.nbformat import v3
14 from IPython.nbformat import v3
15 from IPython.utils.log import get_logger
16
15
17 def _warn_if_invalid(nb, version):
16 def _warn_if_invalid(nb, version):
18 """Log validation errors, if there are any."""
17 """Log validation errors, if there are any."""
19 from IPython.nbformat import validate, ValidationError
18 return
20 try:
21 validate(nb, version=version)
22 except ValidationError as e:
23 get_logger().error("Notebook JSON is not valid v%i: %s", version, e)
24
19
25 def upgrade(nb, from_version=3, from_minor=0):
20 def upgrade(nb, from_version=3, from_minor=0):
26 """Convert a notebook to v4.
21 """Convert a notebook to v4.
@@ -18,9 +18,8 b" nbformat_schema = 'nbformat.v4.schema.json'"
18
18
19
19
20 def validate(node, ref=None):
20 def validate(node, ref=None):
21 """validate a v4 node"""
21 """nbformat validation is not backported"""
22 from .. import validate
22 return
23 return validate(node, ref=ref, version=nbformat)
24
23
25
24
26 def new_output(output_type, data=None, **kwargs):
25 def new_output(output_type, data=None, **kwargs):
@@ -3,7 +3,7 b' import copy'
3
3
4 import nose.tools as nt
4 import nose.tools as nt
5
5
6 from IPython.nbformat import validate
6 from ..nbbase import validate
7 from .. import convert
7 from .. import convert
8
8
9 from . import nbexamples
9 from . import nbexamples
@@ -3,7 +3,6 b''
3
3
4 import nose.tools as nt
4 import nose.tools as nt
5
5
6 from IPython.nbformat.validator import isvalid, validate, ValidationError
7 from ..nbbase import (
6 from ..nbbase import (
8 NotebookNode, nbformat,
7 NotebookNode, nbformat,
9 new_code_cell, new_markdown_cell, new_notebook,
8 new_code_cell, new_markdown_cell, new_notebook,
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now