1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
''' Test keyboard invoked execution '''
from selenium.webdriver.common.keys import Keys
from .utils import shift, cmdtrl, alt, validate_dualmode_state
INITIAL_CELLS = ['', 'print("a")', 'print("b")', 'print("c")']
def test_dualmode_execute(prefill_notebook):
notebook = prefill_notebook(INITIAL_CELLS)
for i in range(1, 4):
notebook.execute_cell(i)
#shift-enter
#last cell in notebook
base_index = 3
notebook.focus_cell(base_index)
shift(notebook.browser, Keys.ENTER) #creates one cell
validate_dualmode_state(notebook, 'edit', base_index + 1)
#Not last cell in notebook & starts in edit mode
notebook.focus_cell(base_index)
notebook.body.send_keys(Keys.ENTER) #Enter edit mode
validate_dualmode_state(notebook, 'edit', base_index)
shift(notebook.browser, Keys.ENTER) #creates one cell
validate_dualmode_state(notebook, 'command', base_index + 1)
#Starts in command mode
notebook.body.send_keys('k')
validate_dualmode_state(notebook, 'command', base_index)
shift(notebook.browser, Keys.ENTER) #creates one cell
validate_dualmode_state(notebook, 'command', base_index + 1)
#Ctrl-enter
#Last cell in notebook
base_index += 1
cmdtrl(notebook.browser, Keys.ENTER)
validate_dualmode_state(notebook, 'command', base_index)
#Not last cell in notebook & stats in edit mode
notebook.focus_cell(base_index - 1)
notebook.body.send_keys(Keys.ENTER) #Enter edit mode
validate_dualmode_state(notebook, 'edit', base_index - 1)
cmdtrl(notebook.browser, Keys.ENTER)
#Starts in command mode
notebook.body.send_keys('j')
validate_dualmode_state(notebook, 'command', base_index)
cmdtrl(notebook.browser, Keys.ENTER)
validate_dualmode_state(notebook, 'command', base_index)
#Alt-enter
#Last cell in notebook
alt(notebook.browser, Keys.ENTER)
validate_dualmode_state(notebook, 'edit', base_index + 1)
#Not last cell in notebook &starts in edit mode
notebook.focus_cell(base_index)
notebook.body.send_keys(Keys.ENTER) #Enter edit mode
validate_dualmode_state(notebook, 'edit', base_index)
alt(notebook.browser, Keys.ENTER)
validate_dualmode_state(notebook, 'edit', base_index + 1)
#starts in command mode
notebook.body.send_keys(Keys.ESCAPE, 'k')
validate_dualmode_state(notebook, 'command', base_index)
alt(notebook.browser, Keys.ENTER)
validate_dualmode_state(notebook, 'edit', base_index + 1)
#Notebook will now have 8 cells, the index of the last cell will be 7
assert len(notebook) == 8 #Cells where added
notebook.focus_cell(7)
validate_dualmode_state(notebook, 'command', 7)
|