##// END OF EJS Templates
save and restore ps1/ps2
save and restore ps1/ps2

File last commit:

r18251:8601054f
r18763:995f4b27
Show More
test_validator.py
54 lines | 1.8 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
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431 from ..current 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
#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
class TestValidator(TestsBase):
def test_nb2(self):
"""Test that a v2 notebook converted to v3 passes validation"""
with self.fopen(u'test2.ipynb', u'r') as f:
nb = read(f, u'json')
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:
nb = read(f, u'json')
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_invalid(self):
"""Test than an invalid notebook does not pass validation"""
# this notebook has a few different errors:
# - the name is an integer, rather than a string
Jessica B. Hamrick
Fix broken test for the invalid notebook
r16434 # - one cell is missing its source
Jessica B. Hamrick
Add some tests for the JSON validation code
r16431 # - one cell has an invalid level
with self.fopen(u'invalid.ipynb', u'r') as f:
nb = read(f, u'json')
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"""
with self.fopen(u'test3plus.ipynb', u'r') as f:
nb = read(f)
with self.assertRaises(ValidationError):
validate(nb, version=3)
self.assertEqual(isvalid(nb, version=3), False)
self.assertEqual(isvalid(nb), True)