-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3465 from Sheshtawy/convert-jstest-to-selenium-de…
…letecell Convert jstests to selenium: deletecell.js
- Loading branch information
Showing
3 changed files
with
68 additions
and
107 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
import pytest | ||
|
||
def cell_is_deletable(nb, index): | ||
JS = 'return Jupyter.notebook.get_cell({}).is_deletable();'.format(index) | ||
return nb.browser.execute_script(JS) | ||
|
||
def delete_cell(notebook, index): | ||
notebook.focus_cell(index) | ||
notebook.to_command_mode | ||
notebook.current_cell.send_keys('dd') | ||
|
||
def test_delete_cells(notebook): | ||
a = 'print("a")' | ||
b = 'print("b")' | ||
c = 'print("c")' | ||
|
||
notebook.edit_cell(index=0, content=a) | ||
notebook.append(b, c) | ||
notebook.to_command_mode() | ||
|
||
# Validate initial state | ||
assert notebook.get_cells_contents() == [a, b, c] | ||
for cell in range(0, 3): | ||
assert cell_is_deletable(notebook, cell) | ||
|
||
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) | ||
assert cell_is_deletable(notebook, 2) | ||
|
||
# Try to delete cell a (should not be deleted) | ||
delete_cell(notebook, 0) | ||
assert notebook.get_cells_contents() == [a, b, c] | ||
|
||
# Try to delete cell b (should succeed) | ||
delete_cell(notebook, 1) | ||
assert notebook.get_cells_contents() == [a, c] | ||
|
||
# Try to delete cell c (should succeed) | ||
delete_cell(notebook, 1) | ||
assert notebook.get_cells_contents() == [a] | ||
|
||
# Change the deletable state of cell a | ||
notebook.set_cell_metadata(0, 'deletable', 'true') | ||
|
||
# Try to delete cell a (should succeed) | ||
delete_cell(notebook, 0) | ||
assert len(notebook.cells) == 1 # it contains an empty cell | ||
|
||
# Make sure copied cells are deletable | ||
notebook.edit_cell(index=0, content=a) | ||
notebook.set_cell_metadata(0, 'deletable', 'false') | ||
assert not cell_is_deletable(notebook, 0) | ||
notebook.to_command_mode() | ||
notebook.current_cell.send_keys('cv') | ||
assert len(notebook.cells) == 2 | ||
assert cell_is_deletable(notebook, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters