File: test_merge_cells.py

package info (click to toggle)
jupyter-notebook 6.4.13-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,860 kB
  • sloc: javascript: 20,765; python: 15,658; makefile: 255; sh: 160
file content (36 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Tests the merge cell api."""

INITIAL_CELLS = [
    "foo = 5",
    "bar = 10",
    "baz = 15",
    "print(foo)",
    "print(bar)",
    "print(baz)",
]

def test_merge_cells(prefill_notebook):
    notebook = prefill_notebook(INITIAL_CELLS)
    a, b, c, d, e, f = INITIAL_CELLS

    # Before merging, there are 6 separate cells
    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 = f"{a}\n\n{b}"
    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 = f"{c}\n\n{d}"
    assert notebook.get_cells_contents() == [merged_a_b, merged_c_d, e, f]

    # Merge everything down to a single cell with selected cells
    notebook.select_cell_range(0,3)
    notebook.browser.execute_script("Jupyter.notebook.merge_selected_cells();")
    merged_all = f"{merged_a_b}\n\n{merged_c_d}\n\n{e}\n\n{f}"
    assert notebook.get_cells_contents() == [merged_all]