From 2f50bf99807bcac5f3b703f136b27c819d3ab47c Mon Sep 17 00:00:00 2001 From: Juergen Hasch Date: Wed, 24 Dec 2014 13:15:54 +0100 Subject: [PATCH] Skip exceptions --- IPython/html/static/notebook/js/codecell.js | 11 +++++-- IPython/html/tests/notebook/execute_code.js | 35 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 1404956f2..527b9ca2a 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -403,14 +403,18 @@ define([ * Execute current code cell to the kernel * @method execute */ - CodeCell.prototype.execute = function () { + CodeCell.prototype.execute = function (skip_exceptions) { if (!this.kernel || !this.kernel.is_connected()) { console.log("Can't execute, kernel is not connected."); return; } this.active_output_area.clear_output(false, true); - + + if (skip_exceptions === undefined) { + skip_exceptions = false; + } + // Clear widget area for (var i = 0; i < this.widget_views.length; i++) { var view = this.widget_views[i]; @@ -434,7 +438,8 @@ define([ var callbacks = this.get_callbacks(); var old_msg_id = this.last_msg_id; - this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true}); + this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true, + skip_exceptions : skip_exceptions}); if (old_msg_id) { delete CodeCell.msg_cells[old_msg_id]; } diff --git a/IPython/html/tests/notebook/execute_code.js b/IPython/html/tests/notebook/execute_code.js index 8374fc188..ca80b9ff5 100644 --- a/IPython/html/tests/notebook/execute_code.js +++ b/IPython/html/tests/notebook/execute_code.js @@ -75,4 +75,39 @@ casper.notebook_test(function () { var result = this.get_output_cell(0); this.test.assertEquals(result.text, '13\n', 'cell execute (using "play" toolbar button)') }); + + // run code with skip_exception + this.thenEvaluate(function () { + var cell0 = IPython.notebook.get_cell(0); + cell0.set_text('raise IOError'); + IPython.notebook.insert_cell_below('code',0); + var cell1 = IPython.notebook.get_cell(1); + cell1.set_text('a=14; print(a)'); + cell0.execute(skip_exception=true); + cell1.execute(); + }); + + this.wait_for_output(1); + + this.then(function () { + var result = this.get_output_cell(1); + this.test.assertEquals(result.text, '14\n', 'cell execute, skip exceptions'); + }); + + this.thenEvaluate(function () { + var cell0 = IPython.notebook.get_cell(0); + cell0.set_text('raise IOError'); + IPython.notebook.insert_cell_below('code',0); + var cell1 = IPython.notebook.get_cell(1); + cell1.set_text('a=14; print(a)'); + cell0.execute(); + cell1.execute(); + }); + + this.wait_for_output(1); + + this.then(function () { + var result = this.get_output_cell(1); + this.test.assertNotEquals(result.text, '14\n', 'cell execute, skip exceptions'); + }); });