##// END OF EJS Templates
Use Draft4 JSON Schema for v4
MinRK -
Show More
@@ -19,7 +19,7 b' from IPython.utils.py3compat import cast_unicode, unicode_type'
19 # Change this when incrementing the nbformat version
19 # Change this when incrementing the nbformat version
20 nbformat = 4
20 nbformat = 4
21 nbformat_minor = 0
21 nbformat_minor = 0
22 nbformat_schema = 'v4.withref.json'
22 nbformat_schema = 'nbformat.v4.schema.json'
23
23
24 class NotebookNode(Struct):
24 class NotebookNode(Struct):
25 pass
25 pass
@@ -141,8 +141,7 b''
141 "level": {
141 "level": {
142 "description": "Level of heading cells.",
142 "description": "Level of heading cells.",
143 "type": "integer",
143 "type": "integer",
144 "minimum": 1,
144 "minimum": 1
145 "maximum": 6
146 }
145 }
147 }
146 }
148 },
147 },
@@ -8,119 +8,123 b' import os'
8
8
9 import nose.tools as nt
9 import nose.tools as nt
10
10
11 from ..validator import isvalid, validate, ValidationError
11 from IPython.nbformat.validator import validate, ValidationError
12 from ..nbjson import reads
12 from ..nbjson import reads
13 from ..nbbase import nbformat
13 from ..compose import (
14 from ..compose import (
14 new_code_cell, new_heading_cell, new_markdown_cell, new_notebook,
15 new_code_cell, new_heading_cell, new_markdown_cell, new_notebook,
15 new_output, new_raw_cell,
16 new_output, new_raw_cell,
16 )
17 )
17
18
19 def validate4(obj, ref=None):
20 return validate(obj, ref, version=nbformat)
21
18 def test_valid_code_cell():
22 def test_valid_code_cell():
19 cell = new_code_cell()
23 cell = new_code_cell()
20 validate(cell, 'code_cell')
24 validate4(cell, 'code_cell')
21
25
22 def test_invalid_code_cell():
26 def test_invalid_code_cell():
23 cell = new_code_cell()
27 cell = new_code_cell()
24
28
25 cell['source'] = 5
29 cell['source'] = 5
26 with nt.assert_raises(ValidationError):
30 with nt.assert_raises(ValidationError):
27 validate(cell, 'code_cell')
31 validate4(cell, 'code_cell')
28
32
29 cell = new_code_cell()
33 cell = new_code_cell()
30 del cell['metadata']
34 del cell['metadata']
31
35
32 with nt.assert_raises(ValidationError):
36 with nt.assert_raises(ValidationError):
33 validate(cell, 'code_cell')
37 validate4(cell, 'code_cell')
34
38
35 cell = new_code_cell()
39 cell = new_code_cell()
36 del cell['source']
40 del cell['source']
37
41
38 with nt.assert_raises(ValidationError):
42 with nt.assert_raises(ValidationError):
39 validate(cell, 'code_cell')
43 validate4(cell, 'code_cell')
40
44
41 cell = new_code_cell()
45 cell = new_code_cell()
42 del cell['cell_type']
46 del cell['cell_type']
43
47
44 with nt.assert_raises(ValidationError):
48 with nt.assert_raises(ValidationError):
45 validate(cell, 'code_cell')
49 validate4(cell, 'code_cell')
46
50
47 def test_invalid_markdown_cell():
51 def test_invalid_markdown_cell():
48 cell = new_markdown_cell()
52 cell = new_markdown_cell()
49
53
50 cell['source'] = 5
54 cell['source'] = 5
51 with nt.assert_raises(ValidationError):
55 with nt.assert_raises(ValidationError):
52 validate(cell, 'markdown_cell')
56 validate4(cell, 'markdown_cell')
53
57
54 cell = new_markdown_cell()
58 cell = new_markdown_cell()
55 del cell['metadata']
59 del cell['metadata']
56
60
57 with nt.assert_raises(ValidationError):
61 with nt.assert_raises(ValidationError):
58 validate(cell, 'markdown_cell')
62 validate4(cell, 'markdown_cell')
59
63
60 cell = new_markdown_cell()
64 cell = new_markdown_cell()
61 del cell['source']
65 del cell['source']
62
66
63 with nt.assert_raises(ValidationError):
67 with nt.assert_raises(ValidationError):
64 validate(cell, 'markdown_cell')
68 validate4(cell, 'markdown_cell')
65
69
66 cell = new_markdown_cell()
70 cell = new_markdown_cell()
67 del cell['cell_type']
71 del cell['cell_type']
68
72
69 with nt.assert_raises(ValidationError):
73 with nt.assert_raises(ValidationError):
70 validate(cell, 'markdown_cell')
74 validate4(cell, 'markdown_cell')
71
75
72 def test_invalid_heading_cell():
76 def test_invalid_heading_cell():
73 cell = new_heading_cell()
77 cell = new_heading_cell()
74
78
75 cell['source'] = 5
79 cell['source'] = 5
76 with nt.assert_raises(ValidationError):
80 with nt.assert_raises(ValidationError):
77 validate(cell, 'heading_cell')
81 validate4(cell, 'heading_cell')
78
82
79 cell = new_heading_cell()
83 cell = new_heading_cell()
80 del cell['metadata']
84 del cell['metadata']
81
85
82 with nt.assert_raises(ValidationError):
86 with nt.assert_raises(ValidationError):
83 validate(cell, 'heading_cell')
87 validate4(cell, 'heading_cell')
84
88
85 cell = new_heading_cell()
89 cell = new_heading_cell()
86 del cell['source']
90 del cell['source']
87
91
88 with nt.assert_raises(ValidationError):
92 with nt.assert_raises(ValidationError):
89 validate(cell, 'heading_cell')
93 validate4(cell, 'heading_cell')
90
94
91 cell = new_heading_cell()
95 cell = new_heading_cell()
92 del cell['cell_type']
96 del cell['cell_type']
93
97
94 with nt.assert_raises(ValidationError):
98 with nt.assert_raises(ValidationError):
95 validate(cell, 'heading_cell')
99 validate4(cell, 'heading_cell')
96
100
97 def test_invalid_raw_cell():
101 def test_invalid_raw_cell():
98 cell = new_raw_cell()
102 cell = new_raw_cell()
99
103
100 cell['source'] = 5
104 cell['source'] = 5
101 with nt.assert_raises(ValidationError):
105 with nt.assert_raises(ValidationError):
102 validate(cell, 'raw_cell')
106 validate4(cell, 'raw_cell')
103
107
104 cell = new_raw_cell()
108 cell = new_raw_cell()
105 del cell['metadata']
109 del cell['metadata']
106
110
107 with nt.assert_raises(ValidationError):
111 with nt.assert_raises(ValidationError):
108 validate(cell, 'raw_cell')
112 validate4(cell, 'raw_cell')
109
113
110 cell = new_raw_cell()
114 cell = new_raw_cell()
111 del cell['source']
115 del cell['source']
112
116
113 with nt.assert_raises(ValidationError):
117 with nt.assert_raises(ValidationError):
114 validate(cell, 'raw_cell')
118 validate4(cell, 'raw_cell')
115
119
116 cell = new_raw_cell()
120 cell = new_raw_cell()
117 del cell['cell_type']
121 del cell['cell_type']
118
122
119 with nt.assert_raises(ValidationError):
123 with nt.assert_raises(ValidationError):
120 validate(cell, 'raw_cell')
124 validate4(cell, 'raw_cell')
121
125
122 def test_sample_notebook():
126 def test_sample_notebook():
123 here = os.path.dirname(__file__)
127 here = os.path.dirname(__file__)
124 with io.open(os.path.join(here, "v4-test.ipynb"), encoding='utf-8') as f:
128 with io.open(os.path.join(here, "v4-test.ipynb"), encoding='utf-8') as f:
125 nb = reads(f.read())
129 nb = reads(f.read())
126 validate(nb)
130 validate4(nb)
@@ -199,6 +199,7 b' def find_package_data():'
199 'IPython.nbformat' : [
199 'IPython.nbformat' : [
200 'tests/*.ipynb',
200 'tests/*.ipynb',
201 'v3/nbformat.v3.schema.json',
201 'v3/nbformat.v3.schema.json',
202 'v4/nbformat.v4.schema.json',
202 ]
203 ]
203 }
204 }
204
205
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