mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
Merge pull request #7377 from juhasch/skip-exceptions2
make stop_on_error behavior optional
This commit is contained in:
commit
58e355e208
@ -403,7 +403,7 @@ define([
|
||||
* Execute current code cell to the kernel
|
||||
* @method execute
|
||||
*/
|
||||
CodeCell.prototype.execute = function () {
|
||||
CodeCell.prototype.execute = function (stop_on_error) {
|
||||
if (!this.kernel || !this.kernel.is_connected()) {
|
||||
console.log("Can't execute, kernel is not connected.");
|
||||
return;
|
||||
@ -411,6 +411,10 @@ define([
|
||||
|
||||
this.active_output_area.clear_output(false, true);
|
||||
|
||||
if (stop_on_error === undefined) {
|
||||
stop_on_error = true;
|
||||
}
|
||||
|
||||
// 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,
|
||||
stop_on_error : stop_on_error});
|
||||
if (old_msg_id) {
|
||||
delete CodeCell.msg_cells[old_msg_id];
|
||||
}
|
||||
|
@ -75,4 +75,41 @@ 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(false);
|
||||
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, don't stop on error");
|
||||
});
|
||||
|
||||
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(0);
|
||||
|
||||
this.then(function () {
|
||||
var outputs = this.evaluate(function() {
|
||||
return IPython.notebook.get_cell(1).output_area.outputs;
|
||||
})
|
||||
this.test.assertEquals(outputs.length, 0, 'cell execute, stop on error (default)');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user