Show More
@@ -24,3 +24,5 __pycache__ | |||||
24 | .cache |
|
24 | .cache | |
25 | .coverage |
|
25 | .coverage | |
26 | *.swp |
|
26 | *.swp | |
|
27 | .vscode | |||
|
28 | .pytest_cache |
@@ -800,7 +800,7 class JSON(DisplayObject): | |||||
800 | """ |
|
800 | """ | |
801 | # wrap data in a property, which warns about passing already-serialized JSON |
|
801 | # wrap data in a property, which warns about passing already-serialized JSON | |
802 | _data = None |
|
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 | """Create a JSON display object given raw data. |
|
804 | """Create a JSON display object given raw data. | |
805 |
|
805 | |||
806 | Parameters |
|
806 | Parameters | |
@@ -817,8 +817,13 class JSON(DisplayObject): | |||||
817 | Metadata to control whether a JSON display component is expanded. |
|
817 | Metadata to control whether a JSON display component is expanded. | |
818 | metadata: dict |
|
818 | metadata: dict | |
819 | Specify extra metadata to attach to the json display object. |
|
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 = { |
|
823 | self.metadata = { | |
|
824 | 'expanded': expanded, | |||
|
825 | 'root': root, | |||
|
826 | } | |||
822 | if metadata: |
|
827 | if metadata: | |
823 | self.metadata.update(metadata) |
|
828 | self.metadata.update(metadata) | |
824 | if kwargs: |
|
829 | if kwargs: |
@@ -213,31 +213,41 def test_progress_iter(): | |||||
213 | def test_json(): |
|
213 | def test_json(): | |
214 | d = {'a': 5} |
|
214 | d = {'a': 5} | |
215 | lis = [d] |
|
215 | lis = [d] | |
216 | md = {'expanded': False} |
|
216 | metadata = [ | |
217 | md2 = {'expanded': True} |
|
217 | {'expanded': False, 'root': 'root'}, | |
218 | j = display.JSON(d) |
|
218 | {'expanded': True, 'root': 'root'}, | |
219 | j2 = display.JSON(d, expanded=True) |
|
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): | |||
220 | nt.assert_equal(j._repr_json_(), (d, md)) |
|
229 | nt.assert_equal(j._repr_json_(), (d, md)) | |
221 | nt.assert_equal(j2._repr_json_(), (d, md2)) |
|
|||
222 |
|
230 | |||
223 | with warnings.catch_warnings(record=True) as w: |
|
231 | with warnings.catch_warnings(record=True) as w: | |
224 | warnings.simplefilter("always") |
|
232 | warnings.simplefilter("always") | |
225 | j = display.JSON(json.dumps(d)) |
|
233 | j = display.JSON(json.dumps(d)) | |
226 | nt.assert_equal(len(w), 1) |
|
234 | nt.assert_equal(len(w), 1) | |
227 | nt.assert_equal(j._repr_json_(), (d, md)) |
|
235 | nt.assert_equal(j._repr_json_(), (d, metadata[0])) | |
228 | nt.assert_equal(j2._repr_json_(), (d, md2)) |
|
236 | ||
229 |
|
237 | json_objs = [ | ||
230 |
|
|
238 | display.JSON(lis), | |
231 |
|
|
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): | |||
232 | nt.assert_equal(j._repr_json_(), (lis, md)) |
|
244 | nt.assert_equal(j._repr_json_(), (lis, md)) | |
233 | nt.assert_equal(j2._repr_json_(), (lis, md2)) |
|
|||
234 |
|
245 | |||
235 | with warnings.catch_warnings(record=True) as w: |
|
246 | with warnings.catch_warnings(record=True) as w: | |
236 | warnings.simplefilter("always") |
|
247 | warnings.simplefilter("always") | |
237 | j = display.JSON(json.dumps(lis)) |
|
248 | j = display.JSON(json.dumps(lis)) | |
238 | nt.assert_equal(len(w), 1) |
|
249 | nt.assert_equal(len(w), 1) | |
239 | nt.assert_equal(j._repr_json_(), (lis, md)) |
|
250 | nt.assert_equal(j._repr_json_(), (lis, metadata[0])) | |
240 | nt.assert_equal(j2._repr_json_(), (lis, md2)) |
|
|||
241 |
|
251 | |||
242 | def test_video_embedding(): |
|
252 | def test_video_embedding(): | |
243 | """use a tempfile, with dummy-data, to ensure that video embedding doesn't crash""" |
|
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