##// END OF EJS Templates
Merge pull request #11211 from dhirschfeld/patch-2...
Matthias Bussonnier -
r24415:def6f901 merge
parent child Browse files
Show More
@@ -24,3 +24,5 b' __pycache__'
24 24 .cache
25 25 .coverage
26 26 *.swp
27 .vscode
28 .pytest_cache
@@ -800,7 +800,7 b' class JSON(DisplayObject):'
800 800 """
801 801 # wrap data in a property, which warns about passing already-serialized JSON
802 802 _data = None
803 def __init__(self, data=None, url=None, filename=None, expanded=False, metadata=None, **kwargs):
803 def __init__(self, data=None, url=None, filename=None, expanded=False, metadata=None, root='root', **kwargs):
804 804 """Create a JSON display object given raw data.
805 805
806 806 Parameters
@@ -817,8 +817,13 b' class JSON(DisplayObject):'
817 817 Metadata to control whether a JSON display component is expanded.
818 818 metadata: dict
819 819 Specify extra metadata to attach to the json display object.
820 root : str
821 The name of the root element of the JSON tree
820 822 """
821 self.metadata = {'expanded': expanded}
823 self.metadata = {
824 'expanded': expanded,
825 'root': root,
826 }
822 827 if metadata:
823 828 self.metadata.update(metadata)
824 829 if kwargs:
@@ -213,31 +213,41 b' def test_progress_iter():'
213 213 def test_json():
214 214 d = {'a': 5}
215 215 lis = [d]
216 md = {'expanded': False}
217 md2 = {'expanded': True}
218 j = display.JSON(d)
219 j2 = display.JSON(d, expanded=True)
220 nt.assert_equal(j._repr_json_(), (d, md))
221 nt.assert_equal(j2._repr_json_(), (d, md2))
216 metadata = [
217 {'expanded': False, 'root': 'root'},
218 {'expanded': True, 'root': 'root'},
219 {'expanded': False, 'root': 'custom'},
220 {'expanded': True, 'root': 'custom'},
221 ]
222 json_objs = [
223 display.JSON(d),
224 display.JSON(d, expanded=True),
225 display.JSON(d, root='custom'),
226 display.JSON(d, expanded=True, root='custom'),
227 ]
228 for j, md in zip(json_objs, metadata):
229 nt.assert_equal(j._repr_json_(), (d, md))
222 230
223 231 with warnings.catch_warnings(record=True) as w:
224 232 warnings.simplefilter("always")
225 233 j = display.JSON(json.dumps(d))
226 234 nt.assert_equal(len(w), 1)
227 nt.assert_equal(j._repr_json_(), (d, md))
228 nt.assert_equal(j2._repr_json_(), (d, md2))
229
230 j = display.JSON(lis)
231 j2 = display.JSON(lis, expanded=True)
232 nt.assert_equal(j._repr_json_(), (lis, md))
233 nt.assert_equal(j2._repr_json_(), (lis, md2))
235 nt.assert_equal(j._repr_json_(), (d, metadata[0]))
236
237 json_objs = [
238 display.JSON(lis),
239 display.JSON(lis, expanded=True),
240 display.JSON(lis, root='custom'),
241 display.JSON(lis, expanded=True, root='custom'),
242 ]
243 for j, md in zip(json_objs, metadata):
244 nt.assert_equal(j._repr_json_(), (lis, md))
234 245
235 246 with warnings.catch_warnings(record=True) as w:
236 247 warnings.simplefilter("always")
237 248 j = display.JSON(json.dumps(lis))
238 249 nt.assert_equal(len(w), 1)
239 nt.assert_equal(j._repr_json_(), (lis, md))
240 nt.assert_equal(j2._repr_json_(), (lis, md2))
250 nt.assert_equal(j._repr_json_(), (lis, metadata[0]))
241 251
242 252 def test_video_embedding():
243 253 """use a tempfile, with dummy-data, to ensure that video embedding doesn't crash"""
General Comments 0
You need to be logged in to leave comments. Login now