execute_code.js
78 lines
| 2.3 KiB
| application/javascript
|
JavascriptLexer
David Wyde
|
r13249 | // | ||
// Test code cell execution. | ||||
// | ||||
Paul Ivanov
|
r13275 | casper.notebook_test(function () { | ||
David Wyde
|
r13249 | this.evaluate(function () { | ||
Paul Ivanov
|
r13260 | var cell = IPython.notebook.get_cell(0); | ||
Thomas Kluyver
|
r13278 | cell.set_text('a=10; print(a)'); | ||
David Wyde
|
r13249 | cell.execute(); | ||
}); | ||||
Paul Ivanov
|
r13294 | this.wait_for_output(0); | ||
David Wyde
|
r13249 | |||
Paul Ivanov
|
r13299 | // refactor this into just a get_output(0) | ||
David Wyde
|
r13253 | this.then(function () { | ||
Paul Ivanov
|
r13299 | var result = this.get_output_cell(0); | ||
Paul Ivanov
|
r13300 | this.test.assertEquals(result.text, '10\n', 'cell execute (using js)'); | ||
Paul Ivanov
|
r13292 | }); | ||
// do it again with the keyboard shortcut | ||||
this.thenEvaluate(function () { | ||||
var cell = IPython.notebook.get_cell(0); | ||||
cell.set_text('a=11; print(a)'); | ||||
Paul Ivanov
|
r13300 | cell.clear_output(); | ||
Paul Ivanov
|
r13292 | }); | ||
Jonathan Frederic
|
r15940 | this.then(function(){ | ||
Jonathan Frederic
|
r15941 | this.trigger_keydown('shift-enter'); | ||
Jonathan Frederic
|
r15940 | }); | ||
Paul Ivanov
|
r13294 | this.wait_for_output(0); | ||
Paul Ivanov
|
r13292 | |||
this.then(function () { | ||||
Paul Ivanov
|
r13299 | var result = this.get_output_cell(0); | ||
Paul Ivanov
|
r13300 | var num_cells = this.get_cells_length(); | ||
this.test.assertEquals(result.text, '11\n', 'cell execute (using ctrl-enter)'); | ||||
Brian E. Granger
|
r14947 | this.test.assertEquals(num_cells, 2, 'shift-enter adds a new cell at the bottom') | ||
David Wyde
|
r13253 | }); | ||
Paul Ivanov
|
r13293 | |||
// do it again with the keyboard shortcut | ||||
this.thenEvaluate(function () { | ||||
Brian E. Granger
|
r14081 | IPython.notebook.select(1); | ||
IPython.notebook.delete_cell(); | ||||
Paul Ivanov
|
r13293 | var cell = IPython.notebook.get_cell(0); | ||
cell.set_text('a=12; print(a)'); | ||||
Paul Ivanov
|
r13300 | cell.clear_output(); | ||
Jonathan Frederic
|
r15941 | }); | ||
this.then(function(){ | ||||
this.trigger_keydown('ctrl-enter'); | ||||
Paul Ivanov
|
r13293 | }); | ||
Paul Ivanov
|
r13294 | this.wait_for_output(0); | ||
Paul Ivanov
|
r13293 | |||
this.then(function () { | ||||
Paul Ivanov
|
r13299 | var result = this.get_output_cell(0); | ||
Paul Ivanov
|
r13300 | var num_cells = this.get_cells_length(); | ||
this.test.assertEquals(result.text, '12\n', 'cell execute (using shift-enter)'); | ||||
Brian E. Granger
|
r14947 | this.test.assertEquals(num_cells, 1, 'ctrl-enter adds no new cell at the bottom') | ||
Paul Ivanov
|
r13293 | }); | ||
Paul Ivanov
|
r13301 | |||
// 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)'); | ||||
Bussonnier Matthias
|
r19480 | $("button[data-jupyter-action='ipython.run-select-next']")[0].click() | ||
Paul Ivanov
|
r13301 | }); | ||
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)') | ||||
}); | ||||
David Wyde
|
r13249 | }); | ||