##// END OF EJS Templates
Fix #4777 and #7887...
Fix #4777 and #7887 The function in charge of actually converting cursor offset to CodeMirror line number and character number was actually crashing when the cursor was at the last character (loop until undefined, then access length of variable, which is undefined). This was hiding a bug in which when you would completer to a single completion pressing tab after as-you-type filtering, the completion would be completed twice. The logic that was supposed to detect whether or not all completions had a common prefix was actually faulty as the common prefix used to be a string but was then changed to an object. Hence the logic to check whether or not there was actually a common prefix was always true, even for empty string, leading to the deletion of the line (replace by '') in some cases.

File last commit:

r19987:da0fef15
r20538:ae7f6d6a
Show More
execute_code.js
115 lines | 3.5 KiB | application/javascript | JavascriptLexer
//
// Test code cell execution.
//
casper.notebook_test(function () {
this.evaluate(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('a=10; print(a)');
cell.execute();
});
this.wait_for_output(0);
// refactor this into just a get_output(0)
this.then(function () {
var result = this.get_output_cell(0);
this.test.assertEquals(result.text, '10\n', 'cell execute (using js)');
});
// do it again with the keyboard shortcut
this.thenEvaluate(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('a=11; print(a)');
cell.clear_output();
});
this.then(function(){
this.trigger_keydown('shift-enter');
});
this.wait_for_output(0);
this.then(function () {
var result = this.get_output_cell(0);
var num_cells = this.get_cells_length();
this.test.assertEquals(result.text, '11\n', 'cell execute (using ctrl-enter)');
this.test.assertEquals(num_cells, 2, 'shift-enter adds a new cell at the bottom')
});
// do it again with the keyboard shortcut
this.thenEvaluate(function () {
IPython.notebook.select(1);
IPython.notebook.delete_cell();
var cell = IPython.notebook.get_cell(0);
cell.set_text('a=12; print(a)');
cell.clear_output();
});
this.then(function(){
this.trigger_keydown('ctrl-enter');
});
this.wait_for_output(0);
this.then(function () {
var result = this.get_output_cell(0);
var num_cells = this.get_cells_length();
this.test.assertEquals(result.text, '12\n', 'cell execute (using shift-enter)');
this.test.assertEquals(num_cells, 1, 'ctrl-enter adds no new cell at the bottom')
});
// press the "play" triangle button in the toolbar
this.thenEvaluate(function () {
var cell = IPython.notebook.get_cell(0);
IPython.notebook.select(0);
cell.clear_output();
cell.set_text('a=13; print(a)');
$("button[data-jupyter-action='ipython.run-select-next']")[0].click()
});
this.wait_for_output(0);
this.then(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)');
});
});