commit
fd4275cdf6
@ -1,5 +1,3 @@
|
||||
# Licensing terms
|
||||
|
||||
This project is licensed under the terms of the Modified BSD License
|
||||
(also known as New or Revised or 3-Clause BSD), as follows:
|
||||
|
||||
@ -1,115 +0,0 @@
|
||||
//
|
||||
// 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='jupyter-notebook:run-cell-and-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)');
|
||||
});
|
||||
});
|
||||
@ -1,45 +0,0 @@
|
||||
//
|
||||
// Test kernel interrupt
|
||||
//
|
||||
casper.notebook_test(function () {
|
||||
this.evaluate(function () {
|
||||
var cell = IPython.notebook.get_cell(0);
|
||||
cell.set_text(
|
||||
'import time'+
|
||||
'\nfor x in range(3):'+
|
||||
'\n time.sleep(1)'
|
||||
);
|
||||
cell.execute();
|
||||
});
|
||||
|
||||
this.wait_for_busy();
|
||||
|
||||
// interrupt using menu item (Kernel -> Interrupt)
|
||||
this.thenClick('li#int_kernel');
|
||||
|
||||
this.wait_for_output(0);
|
||||
|
||||
this.then(function () {
|
||||
var result = this.get_output_cell(0);
|
||||
this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (mouseclick)');
|
||||
});
|
||||
|
||||
// run cell 0 again, now interrupting using keyboard shortcut
|
||||
this.thenEvaluate(function () {
|
||||
var cell = IPython.notebook.get_cell(0);
|
||||
cell.clear_output();
|
||||
cell.execute();
|
||||
});
|
||||
|
||||
// interrupt using ii keyboard shortcut
|
||||
this.then(function(){
|
||||
this.trigger_keydown('esc', 'i', 'i');
|
||||
});
|
||||
|
||||
this.wait_for_output(0);
|
||||
|
||||
this.then(function () {
|
||||
var result = this.get_output_cell(0);
|
||||
this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (shortcut)');
|
||||
});
|
||||
});
|
||||
@ -1,44 +0,0 @@
|
||||
|
||||
casper.notebook_test(function () {
|
||||
var that = this;
|
||||
|
||||
var menuItems = ['#restart_kernel', '#restart_clear_output', '#restart_run_all', '#shutdown_kernel']
|
||||
var cancelSelector = ".modal-footer button:first-of-type"
|
||||
|
||||
menuItems.forEach( function(selector) {
|
||||
that.thenClick(selector);
|
||||
that.waitForSelector(cancelSelector);
|
||||
that.thenClick(cancelSelector);
|
||||
|
||||
that.waitWhileSelector(".modal-content", function() {
|
||||
that.test.assert(true, selector + " confirmation modal pops up and is cancelable");
|
||||
});
|
||||
});
|
||||
|
||||
var shutdownSelector = menuItems.pop();
|
||||
var confirmSelector = ".modal-footer .btn-danger"
|
||||
|
||||
menuItems.forEach( function(selector) {
|
||||
that.thenClick(shutdownSelector);
|
||||
that.waitForSelector(confirmSelector);
|
||||
that.thenClick(confirmSelector);
|
||||
|
||||
// wait for shutdown to go through
|
||||
that.waitFor(function() { return this.evaluate(function() {
|
||||
return IPython.notebook.kernel.is_connected() === false;
|
||||
})});
|
||||
|
||||
// Click on one of the restarts
|
||||
that.thenClick(selector);
|
||||
|
||||
// Kernel should get connected, no need for confirmation.
|
||||
that.waitFor(function() { return this.evaluate(function() {
|
||||
return IPython.notebook.kernel.is_connected() === true;
|
||||
})});
|
||||
that.then(function() {
|
||||
that.test.assert(true, "no confirmation for " + selector + " after session shutdown")
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from .utils import shift, cmdtrl
|
||||
|
||||
|
||||
def test_execute_code(notebook):
|
||||
browser = notebook.browser
|
||||
|
||||
def clear_outputs():
|
||||
return notebook.browser.execute_script(
|
||||
"Jupyter.notebook.clear_all_output();")
|
||||
|
||||
# Execute cell with Javascript API
|
||||
notebook.edit_cell(index=0, content='a=10; print(a)')
|
||||
browser.execute_script("Jupyter.notebook.get_cell(0).execute();")
|
||||
outputs = notebook.wait_for_cell_output(0)
|
||||
assert outputs[0].text == '10'
|
||||
|
||||
# Execute cell with Shift-Enter
|
||||
notebook.edit_cell(index=0, content='a=11; print(a)')
|
||||
clear_outputs()
|
||||
shift(notebook.browser, Keys.ENTER)
|
||||
outputs = notebook.wait_for_cell_output(0)
|
||||
assert outputs[0].text == '11'
|
||||
notebook.delete_cell(index=1)
|
||||
|
||||
# Execute cell with Ctrl-Enter
|
||||
notebook.edit_cell(index=0, content='a=12; print(a)')
|
||||
clear_outputs()
|
||||
cmdtrl(notebook.browser, Keys.ENTER)
|
||||
outputs = notebook.wait_for_cell_output(0)
|
||||
assert outputs[0].text == '12'
|
||||
|
||||
# Execute cell with toolbar button
|
||||
notebook.edit_cell(index=0, content='a=13; print(a)')
|
||||
clear_outputs()
|
||||
notebook.browser.find_element_by_css_selector(
|
||||
"button[data-jupyter-action='jupyter-notebook:run-cell-and-select-next']").click()
|
||||
outputs = notebook.wait_for_cell_output(0)
|
||||
assert outputs[0].text == '13'
|
||||
|
||||
# Set up two cells to test stopping on error
|
||||
notebook.edit_cell(index=0, content='raise IOError')
|
||||
notebook.edit_cell(index=1, content='a=14; print(a)')
|
||||
|
||||
# Default behaviour: stop on error
|
||||
clear_outputs()
|
||||
browser.execute_script("""
|
||||
var cell0 = Jupyter.notebook.get_cell(0);
|
||||
var cell1 = Jupyter.notebook.get_cell(1);
|
||||
cell0.execute();
|
||||
cell1.execute();
|
||||
""")
|
||||
outputs = notebook.wait_for_cell_output(0)
|
||||
assert notebook.get_cell_output(1) == []
|
||||
|
||||
# Execute a cell with stop_on_error=false
|
||||
clear_outputs()
|
||||
browser.execute_script("""
|
||||
var cell0 = Jupyter.notebook.get_cell(0);
|
||||
var cell1 = Jupyter.notebook.get_cell(1);
|
||||
cell0.execute(false);
|
||||
cell1.execute();
|
||||
""")
|
||||
outputs = notebook.wait_for_cell_output(1)
|
||||
assert outputs[0].text == '14'
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
from .utils import wait_for_selector
|
||||
|
||||
def interrupt_from_menu(notebook):
|
||||
# Click interrupt button in kernel menu
|
||||
notebook.browser.find_element_by_id('kernellink').click()
|
||||
wait_for_selector(notebook.browser, '#int_kernel', single=True).click()
|
||||
|
||||
def interrupt_from_keyboard(notebook):
|
||||
notebook.body.send_keys("ii")
|
||||
|
||||
|
||||
def test_interrupt(notebook):
|
||||
""" Test the interrupt function using both the button in the Kernel menu and the keyboard shortcut "ii"
|
||||
|
||||
Having trouble accessing the Interrupt message when execution is halted. I am assuming that the
|
||||
message does not lie in the "outputs" field of the cell's JSON object. Using a timeout work-around for
|
||||
test with an infinite loop. We know the interrupt function is working if this test passes.
|
||||
Hope this is a good start.
|
||||
"""
|
||||
|
||||
text = ('import time\n'
|
||||
'for x in range(3):\n'
|
||||
' time.sleep(1)')
|
||||
|
||||
notebook.edit_cell(index=0, content=text)
|
||||
|
||||
for interrupt_method in (interrupt_from_menu, interrupt_from_keyboard):
|
||||
notebook.clear_cell_output(0)
|
||||
notebook.to_command_mode()
|
||||
notebook.execute_cell(0)
|
||||
|
||||
interrupt_method(notebook)
|
||||
|
||||
# Wait for an output to appear
|
||||
output = wait_for_selector(notebook.browser, '.output_subarea', single=True)
|
||||
assert 'KeyboardInterrupt' in output.text
|
||||
@ -0,0 +1,60 @@
|
||||
from selenium.common.exceptions import TimeoutException
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from notebook.tests.selenium.utils import wait_for_selector
|
||||
|
||||
restart_selectors = [
|
||||
'#restart_kernel', '#restart_clear_output', '#restart_run_all'
|
||||
]
|
||||
notify_interaction = '#notification_kernel > span'
|
||||
|
||||
shutdown_selector = '#shutdown_kernel'
|
||||
confirm_selector = '.btn-danger'
|
||||
cancel_selector = ".modal-footer button:first-of-type"
|
||||
|
||||
|
||||
def test_cancel_restart_or_shutdown(notebook):
|
||||
"""Click each of the restart options, then cancel the confirmation dialog"""
|
||||
browser = notebook.browser
|
||||
kernel_menu = browser.find_element_by_id('kernellink')
|
||||
|
||||
for menu_item in restart_selectors + [shutdown_selector]:
|
||||
kernel_menu.click()
|
||||
wait_for_selector(browser, menu_item, visible=True, single=True).click()
|
||||
wait_for_selector(browser, cancel_selector, visible=True, single=True).click()
|
||||
WebDriverWait(browser, 3).until(
|
||||
EC.invisibility_of_element((By.CSS_SELECTOR, '.modal-backdrop'))
|
||||
)
|
||||
assert notebook.is_kernel_running()
|
||||
|
||||
|
||||
def test_menu_items(notebook):
|
||||
browser = notebook.browser
|
||||
kernel_menu = browser.find_element_by_id('kernellink')
|
||||
|
||||
for menu_item in restart_selectors:
|
||||
# Shutdown
|
||||
kernel_menu.click()
|
||||
wait_for_selector(browser, shutdown_selector, visible=True, single=True).click()
|
||||
|
||||
# Confirm shutdown
|
||||
wait_for_selector(browser, confirm_selector, visible=True, single=True).click()
|
||||
|
||||
WebDriverWait(browser, 3).until(
|
||||
lambda b: not notebook.is_kernel_running(),
|
||||
message="Kernel did not shut down as expected"
|
||||
)
|
||||
|
||||
# Restart
|
||||
# Selenium can't click the menu while a modal dialog is fading out
|
||||
WebDriverWait(browser, 3).until(
|
||||
EC.invisibility_of_element((By.CSS_SELECTOR, '.modal-backdrop'))
|
||||
)
|
||||
kernel_menu.click()
|
||||
|
||||
wait_for_selector(browser, menu_item, visible=True, single=True).click()
|
||||
WebDriverWait(browser, 10).until(
|
||||
lambda b: notebook.is_kernel_running(),
|
||||
message="Restart (%r) after shutdown did not start kernel" % menu_item
|
||||
)
|
||||
Loading…
Reference in new issue