From d635525aef56ec30a1282897d8f8b47989cd5400 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 14 Mar 2017 10:03:59 -0700 Subject: [PATCH 1/6] Make mime bundle accessible to renderers --- notebook/static/notebook/js/outputarea.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/notebook/static/notebook/js/outputarea.js b/notebook/static/notebook/js/outputarea.js index 33a5ffa89..ddd341360 100644 --- a/notebook/static/notebook/js/outputarea.js +++ b/notebook/static/notebook/js/outputarea.js @@ -324,6 +324,10 @@ define([ console.log("unrecognized output type: " + json.output_type); this.append_unrecognized(json); } + + if (record_output) { + this.outputs.push(json); + } if (json.output_type === 'display_data') { var that = this; @@ -331,10 +335,6 @@ define([ } else { this.handle_appended(); } - - if (record_output) { - this.outputs.push(json); - } }; OutputArea.prototype.handle_appended = function () { From f510806ff22e102ca6fb10ef97ce24d037d32942 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 15 Mar 2017 10:20:29 +0100 Subject: [PATCH 2/6] fix wait condition in display_id test it was always waiting the maximum time because the condition was never met --- notebook/tests/notebook/display_id.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/notebook/tests/notebook/display_id.js b/notebook/tests/notebook/display_id.js index 6df29f0c4..6f515b3a0 100644 --- a/notebook/tests/notebook/display_id.js +++ b/notebook/tests/notebook/display_id.js @@ -110,7 +110,12 @@ casper.notebook_test(function () { kernel.output_callback_overrides_push(msg_id, callback_id); }); - this.wait_for_output(3); + this.waitFor(function () { + return this.evaluate(function () { + var cell = IPython.notebook.get_cell(3); + return cell.iopub_messages.length >= 2; + }); + }); this.wait_for_idle(); this.then(function () { From 273e8f9bbef5d57e81f760131c0c721fa805bdff Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 15 Mar 2017 10:21:03 +0100 Subject: [PATCH 3/6] display_id target index is now outputs.length - 1 since item has been appended to outputs before calling instead of after --- notebook/static/notebook/js/outputarea.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/notebook/static/notebook/js/outputarea.js b/notebook/static/notebook/js/outputarea.js index ddd341360..a6d35d24d 100644 --- a/notebook/static/notebook/js/outputarea.js +++ b/notebook/static/notebook/js/outputarea.js @@ -621,7 +621,9 @@ define([ targets = this._display_id_targets[display_id] = []; } targets.push({ - index: this.outputs.length, + // output has been appended when this is called, + // so use the index of the last item. + index: this.outputs.length - 1, element: element, }); }; From 7756fd34a9f6d16f1bfb11a90516e6993ea048c3 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 15 Mar 2017 10:49:54 +0100 Subject: [PATCH 4/6] restore append-after-render so all output types are handled consistently --- notebook/static/notebook/js/outputarea.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/notebook/static/notebook/js/outputarea.js b/notebook/static/notebook/js/outputarea.js index a6d35d24d..226d72114 100644 --- a/notebook/static/notebook/js/outputarea.js +++ b/notebook/static/notebook/js/outputarea.js @@ -324,10 +324,6 @@ define([ console.log("unrecognized output type: " + json.output_type); this.append_unrecognized(json); } - - if (record_output) { - this.outputs.push(json); - } if (json.output_type === 'display_data') { var that = this; @@ -335,6 +331,10 @@ define([ } else { this.handle_appended(); } + + if (record_output) { + this.outputs.push(json); + } }; OutputArea.prototype.handle_appended = function () { @@ -621,9 +621,7 @@ define([ targets = this._display_id_targets[display_id] = []; } targets.push({ - // output has been appended when this is called, - // so use the index of the last item. - index: this.outputs.length - 1, + index: this.outputs.length, element: element, }); }; From 93d8f3fe0fb9aceb113e6575540c90edbe57aed6 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 15 Mar 2017 10:53:32 +0100 Subject: [PATCH 5/6] add output_added.OutputArea event --- notebook/static/notebook/js/outputarea.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/notebook/static/notebook/js/outputarea.js b/notebook/static/notebook/js/outputarea.js index 226d72114..873cd01f8 100644 --- a/notebook/static/notebook/js/outputarea.js +++ b/notebook/static/notebook/js/outputarea.js @@ -335,6 +335,11 @@ define([ if (record_output) { this.outputs.push(json); } + + this.events.trigger('output_added.OutputArea', { + output: json, + output_area: this, + }); }; OutputArea.prototype.handle_appended = function () { From 96044f6c80852289d759a7ff013059792f98ead8 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 15 Mar 2017 11:07:06 +0100 Subject: [PATCH 6/6] test updating execute_result --- notebook/tests/notebook/display_id.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/notebook/tests/notebook/display_id.js b/notebook/tests/notebook/display_id.js index 6f515b3a0..3b062ea0c 100644 --- a/notebook/tests/notebook/display_id.js +++ b/notebook/tests/notebook/display_id.js @@ -18,13 +18,17 @@ casper.notebook_test(function () { cell.set_text([ "ip = get_ipython()", "from IPython.display import display", - "def display_with_id(obj, display_id, update=False):", + "def display_with_id(obj, display_id, update=False, execute_result=False):", " iopub = ip.kernel.iopub_socket", " session = get_ipython().kernel.session", " data, md = ip.display_formatter.format(obj)", " transient = {'display_id': display_id}", " content = {'data': data, 'metadata': md, 'transient': transient}", - " msg_type = 'update_display_data' if update else 'display_data'", + " if execute_result:", + " msg_type = 'execute_result'", + " content['execution_count'] = ip.execution_count", + " else:", + " msg_type = 'update_display_data' if update else 'display_data'", " session.send(iopub, msg_type, content, parent=ip.parent_header)", "", ].join('\n')); @@ -141,11 +145,21 @@ casper.notebook_test(function () { cell.set_text([ "display_with_id(7, 'here')", "display_with_id(8, 'here', update=True)", + "display_with_id(9, 'result', execute_result=True)" + ].join('\n')); + cell.execute(); + + Jupyter.notebook.insert_cell_at_index("code", 5); + var cell = Jupyter.notebook.get_cell(5); + cell.set_text([ + "display_with_id(10, 'result', update=True)", + "1", ].join('\n')); cell.execute(); }); this.wait_for_output(4); + this.wait_for_output(5); this.wait_for_idle(); this.then(function () { @@ -156,7 +170,7 @@ casper.notebook_test(function () { })); var cell_results = returned[0]; var callback_results = returned[1]; - this.test.assertEquals(cell_results.length, 1, "correct number of cell outputs"); + this.test.assertEquals(cell_results.length, 2, "correct number of cell outputs"); this.test.assertEquals(callback_results.length, 4, "correct number of callback outputs"); this.test.assertEquals(callback_results[0].output_type, 'display_data', 'check output_type 0'); this.test.assertEquals(callback_results[0].transient.display_id, 'here', 'check display id 0'); @@ -170,6 +184,8 @@ casper.notebook_test(function () { this.test.assertEquals(callback_results[3].output_type, 'update_display_data', 'check output_type 3'); this.test.assertEquals(callback_results[3].transient.display_id, 'here', 'display id 3'); this.test.assertEquals(callback_results[3].data['text/plain'], '8', 'value'); + + this.test.assertEquals(cell_results[1].data['text/plain'], '10', 'update execute_result') });