diff --git a/nbconvert/preprocessors/execute.py b/nbconvert/preprocessors/execute.py index 301389762..8057c9aef 100644 --- a/nbconvert/preprocessors/execute.py +++ b/nbconvert/preprocessors/execute.py @@ -510,9 +510,10 @@ def run_cell(self, cell, cell_index=0): continue elif msg_type.startswith('comm'): data = content['data'] - self.widget_state.setdefault(content['comm_id'], {}).update(data['state']) - if 'buffer_paths' in data and data['buffer_paths']: - self.widget_buffers[content['comm_id']] = _get_buffer_data(msg) + if 'state' in data: # ignore custom msg'es + self.widget_state.setdefault(content['comm_id'], {}).update(data['state']) + if 'buffer_paths' in data and data['buffer_paths']: + self.widget_buffers[content['comm_id']] = _get_buffer_data(msg) continue display_id = None diff --git a/nbconvert/preprocessors/tests/files/widget-hello-world.ipynb b/nbconvert/preprocessors/tests/files/JupyterWidgets.ipynb similarity index 71% rename from nbconvert/preprocessors/tests/files/widget-hello-world.ipynb rename to nbconvert/preprocessors/tests/files/JupyterWidgets.ipynb index a491abd60..b2020ce0b 100644 --- a/nbconvert/preprocessors/tests/files/widget-hello-world.ipynb +++ b/nbconvert/preprocessors/tests/files/JupyterWidgets.ipynb @@ -2,47 +2,43 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "a72770a4f541425f8fe85833a3dc2a8e", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Label(value=u'Hello World')" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "import ipywidgets\n", - "ipywidgets.Label('Hello World')" + "label = ipywidgets.Label('Hello World')\n", + "label" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# it should also handle custom msg'es\n", + "label.send({'msg': 'Hello'})" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.14" + "pygments_lexer": "ipython3", + "version": "3.6.4" }, "widgets": { "application/vnd.jupyter.widget-state+json": { diff --git a/nbconvert/preprocessors/tests/test_execute.py b/nbconvert/preprocessors/tests/test_execute.py index 56b2e1585..fbf5b56f3 100644 --- a/nbconvert/preprocessors/tests/test_execute.py +++ b/nbconvert/preprocessors/tests/test_execute.py @@ -284,7 +284,7 @@ def test_execute_function(self): def test_widgets(self): """Runs a test notebook with widgets and checks the widget state is saved.""" - input_file = os.path.join(current_dir, 'files', 'widget-hello-world.ipynb') + input_file = os.path.join(current_dir, 'files', 'JupyterWidgets.ipynb') opts = dict(kernel_name="python") res = self.build_resources() res['metadata']['path'] = os.path.dirname(input_file)