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