mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-18 11:55:46 +08:00
Move some utility functions from the test module to the utils.py module
This commit is contained in:
parent
413cca8cbd
commit
14acb8d7e9
@ -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')
|
||||
|
@ -127,6 +127,14 @@ class Notebook:
|
||||
wait = WebDriverWait(self.browser, 10)
|
||||
element = wait.until(EC.staleness_of(cell))
|
||||
|
||||
def get_cells_contents(self):
|
||||
JS = 'return Jupyter.notebook.get_cells().map(function(c) {return c.get_text();})'
|
||||
return self.browser.execute_script(JS)
|
||||
|
||||
def set_cell_metadata(self, index, key, value):
|
||||
JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value)
|
||||
return self.browser.execute_script(JS)
|
||||
|
||||
def edit_cell(self, cell=None, index=0, content="", render=False):
|
||||
"""Set the contents of a cell to *content*, by cell object or by index
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user