mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-06 11:35:24 +08:00
Modifications to test JS funcion in test_merge_cells.py
This commit is contained in:
parent
2af744075f
commit
1c87821dc1
@ -4,29 +4,31 @@ def test_merge_cells(notebook):
|
||||
# Add cells to notebook
|
||||
a = "foo = 5"
|
||||
b = "bar = 10"
|
||||
c = "print(foo)"
|
||||
d = "print(bar)"
|
||||
c = "baz = 15"
|
||||
d = "print(foo)"
|
||||
e = "print(bar)"
|
||||
f = "print(baz)"
|
||||
notebook.edit_cell(index=0, content=a)
|
||||
notebook.append(b, c, d)
|
||||
notebook.append(b, c, d, e, f)
|
||||
|
||||
# Before merging, there are 4 separate cells
|
||||
assert notebook.get_cells_contents() == [a, b, c, d]
|
||||
assert notebook.get_cells_contents() == [a, b, c, d, e, f]
|
||||
|
||||
# Focus on the second cell and merge it with the cell above
|
||||
notebook.focus_cell(1)
|
||||
notebook.browser.execute_script("Jupyter.notebook.merge_cell_above();")
|
||||
merged_a_b = "%s\n\n%s" % (a, b)
|
||||
assert notebook.get_cells_contents() == [merged_a_b, c, d]
|
||||
assert notebook.get_cells_contents() == [merged_a_b, c, d, e, f]
|
||||
|
||||
# Focus on the second cell and merge it with the cell below
|
||||
notebook.focus_cell(1)
|
||||
notebook.browser.execute_script("Jupyter.notebook.merge_cell_below();")
|
||||
merged_c_d = "%s\n\n%s" % (c, d)
|
||||
assert notebook.get_cells_contents() == [merged_a_b, merged_c_d]
|
||||
assert notebook.get_cells_contents() == [merged_a_b, merged_c_d, e, f]
|
||||
|
||||
# Merge everything down to a single cell
|
||||
notebook.focus_cell(0)
|
||||
notebook.browser.execute_script("Jupyter.notebook.merge_cell_below();")
|
||||
merged_all = "%s\n\n%s" % (merged_a_b, merged_c_d)
|
||||
notebook.select_command_lines(0,3)
|
||||
notebook.browser.execute_script("Jupyter.notebook.merge_selected_cells();")
|
||||
merged_all = "%s\n\n%s\n\n%s\n\n%s" % (merged_a_b, merged_c_d, e, f)
|
||||
assert notebook.get_cells_contents() == [merged_all]
|
||||
|
||||
|
@ -69,6 +69,13 @@ class Notebook:
|
||||
|
||||
"""
|
||||
return self.browser.find_elements_by_class_name("cell")
|
||||
|
||||
@property
|
||||
def inputs(self):
|
||||
"""Gets all inputs once they are visible.
|
||||
|
||||
"""
|
||||
return self.browser.find_elements_by_class_name("input")
|
||||
|
||||
@property
|
||||
def current_index(self):
|
||||
@ -99,6 +106,12 @@ class Notebook:
|
||||
cell.click()
|
||||
self.to_command_mode()
|
||||
self.current_cell = cell
|
||||
|
||||
def select_command_lines(self, initial_index=0, final_index=0):
|
||||
self.focus_cell(initial_index)
|
||||
self.to_command_mode()
|
||||
for i in range(final_index - initial_index):
|
||||
shift(self.browser, 'j')
|
||||
|
||||
def find_and_replace(self, index=0, find_txt='', replace_txt=''):
|
||||
self.focus_cell(index)
|
||||
|
Loading…
Reference in New Issue
Block a user