Skip to content

Commit

Permalink
Merge pull request #124 from plotly/fail-invalid-notebook-validation
Browse files Browse the repository at this point in the history
Fail invalid notebook validation
  • Loading branch information
takluyver committed Apr 27, 2018
2 parents ff68dff + a7a3478 commit 3af03b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions nbformat/tests/test_validator.py
Expand Up @@ -68,8 +68,9 @@ def test_invalid(self):
self.assertEqual(isvalid(nb), False)

def test_validate_empty(self):
"""Test that an empty dict can be validated without error"""
validate({})
"""Test that an empty notebook (invalid) fails validation"""
with self.assertRaises(ValidationError) as e:
validate({})

def test_future(self):
"""Test than a notebook from the future with extra keys passes validation"""
Expand Down Expand Up @@ -101,4 +102,12 @@ def test_iter_validation_error(self):
assert {e.ref for e in errors} == {'markdown_cell', 'heading_cell', 'bad stream'}

def test_iter_validation_empty(self):
assert list(iter_validate({})) == list()
"""Test that an empty notebook (invalid) fails validation via iter_validate"""
errors = list(iter_validate({}))
assert len(errors) == 1
assert type(errors[0]) == ValidationError

def test_validation_no_version(self):
"""Test that an invalid notebook with no version fails validation"""
with self.assertRaises(ValidationError) as e:
validate({'invalid': 'notebook'})
2 changes: 1 addition & 1 deletion nbformat/validator.py
Expand Up @@ -283,7 +283,7 @@ def iter_validate(nbdict=None, ref=None, version=None, version_minor=None,

if validator is None:
# no validator
warnings.warn("No schema for validating v%s notebooks" % version, UserWarning)
yield ValidationError("No schema for validating v%s notebooks" % version)
return

if ref:
Expand Down

0 comments on commit 3af03b7

Please sign in to comment.