Skip to content

Commit

Permalink
Merge pull request #43 from rgbkrk/custom-json-mimetype
Browse files Browse the repository at this point in the history
Allow custom mimetypes with +json suffix
  • Loading branch information
minrk committed Sep 6, 2016
2 parents 9ffcc3e + 2321277 commit 65ccddb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
52 changes: 52 additions & 0 deletions nbformat/tests/test4custom.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/vnd.raw.v1+json": {
"apples": [
"🍎",
"🍏"
],
"bananas": 2,
"oranges": "apples"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import IPython\n",
"\n",
"bundle = {}\n",
"bundle['application/vnd.raw.v1+json'] = {\n",
" 'apples': ['🍎', '🍏'],\n",
" 'bananas': 2,\n",
" 'oranges': 'apples'\n",
"}\n",
"\n",
"IPython.display.display(bundle, raw=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
},
"nbformat": 4,
"nbformat_minor": 0
}
11 changes: 9 additions & 2 deletions nbformat/tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def test_nb4(self):
validate(nb)
self.assertEqual(isvalid(nb), True)

def test_nb4custom(self):
"""Test that a notebook with a custom JSON mimetype passes validation"""
with self.fopen(u'test4custom.ipynb', u'r') as f:
nb = read(f, as_version=4)
validate(nb)
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:
Expand All @@ -52,10 +59,10 @@ def test_future(self):
nb = read(f, as_version=4)
with self.assertRaises(ValidationError):
validate(nb, version=4)

self.assertEqual(isvalid(nb, version=4), False)
self.assertEqual(isvalid(nb), True)

def test_validation_error(self):
with self.fopen(u'invalid.ipynb', u'r') as f:
nb = read(f, as_version=4)
Expand Down
14 changes: 6 additions & 8 deletions nbformat/v4/nbformat.v4.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,14 @@
"mimebundle": {
"description": "A mime-type keyed dictionary of data",
"type": "object",
"additionalProperties": false,
"properties": {
"application/json": {
"type": "object"
}
"additionalProperties": {
"description": "mimetype output (e.g. text/plain), represented as either an array of strings or a string.",
"$ref": "#/definitions/misc/multiline_string"
},
"patternProperties": {
"^(?!application/json$)[a-zA-Z0-9]+/[a-zA-Z0-9\\-\\+\\.]+$": {
"description": "mimetype output (e.g. text/plain), represented as either an array of strings or a string.",
"$ref": "#/definitions/misc/multiline_string"
"^application/([a-zA-Z0-9.]+\\+)?json$": {
"description": "Mimetypes with JSON output, can be an object",
"type": "object"
}
}
},
Expand Down

0 comments on commit 65ccddb

Please sign in to comment.