##// END OF EJS Templates
Merge pull request #7604 from minrk/print-smh...
Merge pull request #7604 from minrk/print-smh set height: auto on #site for print

File last commit:

r18603:cd1bfb05
r20205:52adecf1 merge
Show More
test_validator.py
58 lines | 1.9 KiB | text/x-python | PythonLexer
MinRK
Use Draft4 JSON Schema for both v3 and v4...
r18243 """Test nbformat.validator"""
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431
MinRK
Use Draft4 JSON Schema for both v3 and v4...
r18243 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431
import os
from .base import TestsBase
MinRK
Use Draft4 JSON Schema for both v3 and v4...
r18243 from jsonschema import ValidationError
MinRK
Add top-level IPython.nbformat API...
r18603 from IPython.nbformat import read
MinRK
Use Draft4 JSON Schema for both v3 and v4...
r18243 from ..validator import isvalid, validate
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431
class TestValidator(TestsBase):
def test_nb2(self):
MinRK
update nbformat.current to v4
r18579 """Test that a v2 notebook converted to current passes validation"""
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431 with self.fopen(u'test2.ipynb', u'r') as f:
MinRK
Add top-level IPython.nbformat API...
r18603 nb = read(f, as_version=4)
MinRK
Use Draft4 JSON Schema for both v3 and v4...
r18243 validate(nb)
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431 self.assertEqual(isvalid(nb), True)
def test_nb3(self):
"""Test that a v3 notebook passes validation"""
with self.fopen(u'test3.ipynb', u'r') as f:
MinRK
Add top-level IPython.nbformat API...
r18603 nb = read(f, as_version=4)
MinRK
Use Draft4 JSON Schema for both v3 and v4...
r18243 validate(nb)
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431 self.assertEqual(isvalid(nb), True)
MinRK
update nbformat.current to v4
r18579 def test_nb4(self):
MinRK
remove heading cells in v4
r18596 """Test that a v4 notebook passes validation"""
MinRK
update nbformat.current to v4
r18579 with self.fopen(u'test4.ipynb', u'r') as f:
MinRK
Add top-level IPython.nbformat API...
r18603 nb = read(f, as_version=4)
MinRK
update nbformat.current to v4
r18579 validate(nb)
self.assertEqual(isvalid(nb), True)
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431 def test_invalid(self):
"""Test than an invalid notebook does not pass validation"""
# this notebook has a few different errors:
Jessica B. Hamrick
Fix broken test for the invalid notebook
r16434 # - one cell is missing its source
MinRK
remove heading cells in v4
r18596 # - invalid cell type
# - invalid output_type
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431 with self.fopen(u'invalid.ipynb', u'r') as f:
MinRK
Add top-level IPython.nbformat API...
r18603 nb = read(f, as_version=4)
MinRK
Use Draft4 JSON Schema for both v3 and v4...
r18243 with self.assertRaises(ValidationError):
validate(nb)
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431 self.assertEqual(isvalid(nb), False)
MinRK
skip additionalProperties validation on notebooks from the future...
r18251 def test_future(self):
"""Test than a notebook from the future with extra keys passes validation"""
MinRK
use v4 for test validation from the future
r18599 with self.fopen(u'test4plus.ipynb', u'r') as f:
MinRK
Add top-level IPython.nbformat API...
r18603 nb = read(f, as_version=4)
MinRK
skip additionalProperties validation on notebooks from the future...
r18251 with self.assertRaises(ValidationError):
MinRK
use v4 for test validation from the future
r18599 validate(nb, version=4)
self.assertEqual(isvalid(nb, version=4), False)
MinRK
skip additionalProperties validation on notebooks from the future...
r18251 self.assertEqual(isvalid(nb), True)
MinRK
use v4 for test validation from the future
r18599