Add a couple of utility functions to help get a single cell's content and type

pull/3508/head
sheshtawy 8 years ago
parent 95f02a7437
commit 8daa5f51b4

@ -1,4 +1,34 @@
# TODO: Tests for dualmode insert cell functionality
def test_insert_cell():
pass
def test_insert_cell(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()
assert notebook.get_cells_contents() == [a, b, c]
notebook.to_command_mode()
notebook.focus_cell(2)
notebook.convert_cell_type(2, "markdown")
notebook.current_cell.send_keys("a")
assert notebook.get_cell_contents(2) == ''
assert notebook.get_cell_type(2) == 'code'
assert len(notebook.cells) == 4
notebook.current_cell.send_keys('b')
assert notebook.get_cell_contents(2) == ''
assert notebook.get_cell_contents(3) == ''
assert notebook.get_cell_type(3) == 'code'
assert len(notebook.cells) == 5
notebook.focus_cell(2)
notebook.convert_cell_type(2, "markdown")
assert notebook.get_cell_type(2) == "markdown"
notebook.current_cell.send_keys("a")
assert notebook.get_cell_type(3) == "markdown"
notebook.current_cell.send_keys("b")
assert notebook.get_cell_type(4) == "markdown"

@ -131,10 +131,17 @@ class Notebook:
JS = 'return Jupyter.notebook.get_cells().map(function(c) {return c.get_text();})'
return self.browser.execute_script(JS)
def get_cell_contents(self, index=0, selector='div .CodeMirror-code'):
return self.cells[index].find_element_by_css_selector(selector).text
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 get_cell_type(self, index=0):
JS = 'return Jupyter.notebook.get_cell({}).cell_type'.format(index)
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…
Cancel
Save