|
|
|
|
@ -1,14 +1,6 @@
|
|
|
|
|
import os
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
def get_cells_contents(nb):
|
|
|
|
|
JS = 'return Jupyter.notebook.get_cells().map(function(c) {return c.get_text();})'
|
|
|
|
|
return nb.browser.execute_script(JS)
|
|
|
|
|
|
|
|
|
|
def set_cell_metadata(nb, index, key, value):
|
|
|
|
|
JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value)
|
|
|
|
|
return nb.browser.execute_script(JS)
|
|
|
|
|
|
|
|
|
|
def cell_is_deletable(nb, index):
|
|
|
|
|
JS = 'return Jupyter.notebook.get_cell({}).is_deletable();'.format(index)
|
|
|
|
|
return nb.browser.execute_script(JS)
|
|
|
|
|
@ -28,12 +20,12 @@ def test_delete_cells(notebook):
|
|
|
|
|
notebook.to_command_mode()
|
|
|
|
|
|
|
|
|
|
# Validate initial state
|
|
|
|
|
assert get_cells_contents(notebook) == [a, b, c]
|
|
|
|
|
assert notebook.get_cells_contents() == [a, b, c]
|
|
|
|
|
for cell in range(0, 3):
|
|
|
|
|
assert cell_is_deletable(notebook, cell)
|
|
|
|
|
|
|
|
|
|
set_cell_metadata(notebook, 0, 'deletable', 'false')
|
|
|
|
|
set_cell_metadata(notebook, 1, 'deletable', 0
|
|
|
|
|
notebook.set_cell_metadata(0, 'deletable', 'false')
|
|
|
|
|
notebook.set_cell_metadata(1, 'deletable', 0
|
|
|
|
|
)
|
|
|
|
|
assert not cell_is_deletable(notebook, 0)
|
|
|
|
|
assert cell_is_deletable(notebook, 1)
|
|
|
|
|
@ -41,18 +33,18 @@ def test_delete_cells(notebook):
|
|
|
|
|
|
|
|
|
|
# Try to delete cell a (should not be deleted)
|
|
|
|
|
delete_cell(notebook, 0)
|
|
|
|
|
assert get_cells_contents(notebook) == [a, b, c]
|
|
|
|
|
assert notebook.get_cells_contents() == [a, b, c]
|
|
|
|
|
|
|
|
|
|
# Try to delete cell b (should succeed)
|
|
|
|
|
delete_cell(notebook, 1)
|
|
|
|
|
assert get_cells_contents(notebook) == [a, c]
|
|
|
|
|
assert notebook.get_cells_contents() == [a, c]
|
|
|
|
|
|
|
|
|
|
# Try to delete cell c (should succeed)
|
|
|
|
|
delete_cell(notebook, 1)
|
|
|
|
|
assert get_cells_contents(notebook) == [a]
|
|
|
|
|
assert notebook.get_cells_contents() == [a]
|
|
|
|
|
|
|
|
|
|
# Change the deletable state of cell a
|
|
|
|
|
set_cell_metadata(notebook, 0, 'deletable', 'true')
|
|
|
|
|
notebook.set_cell_metadata(0, 'deletable', 'true')
|
|
|
|
|
|
|
|
|
|
# Try to delete cell a (should succeed)
|
|
|
|
|
delete_cell(notebook, 0)
|
|
|
|
|
@ -60,7 +52,7 @@ def test_delete_cells(notebook):
|
|
|
|
|
|
|
|
|
|
# Make sure copied cells are deletable
|
|
|
|
|
notebook.edit_cell(index=0, content=a)
|
|
|
|
|
set_cell_metadata(notebook, 0, 'deletable', 'false')
|
|
|
|
|
notebook.set_cell_metadata(0, 'deletable', 'false')
|
|
|
|
|
assert not cell_is_deletable(notebook, 0)
|
|
|
|
|
notebook.to_command_mode()
|
|
|
|
|
notebook.current_cell.send_keys('cv')
|
|
|
|
|
|