File: test_multiselect_toggle.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 (43 lines) | stat: -rw-r--r-- 2,066 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
37
38
39
40
41
42
43
INITIAL_CELLS = ['print("a")', 'print("b")', 'print("c")']
def test_multiselect_toggle(prefill_notebook):
    notebook = prefill_notebook(INITIAL_CELLS)
    def extend_selection_by(delta):
        notebook.browser.execute_script(
            "Jupyter.notebook.extend_selection_by(arguments[0]);", delta)

    def n_selected_cells():
        return notebook.browser.execute_script(
            "return Jupyter.notebook.get_selected_cells().length;")

    def select_cells():
        notebook.focus_cell(0)
        extend_selection_by(2)

    # Test that cells, which start off not collapsed, are collapsed after
    # calling the multiselected cell toggle.
    select_cells()
    assert n_selected_cells() == 3
    notebook.browser.execute_script("Jupyter.notebook.execute_selected_cells();")
    select_cells()
    notebook.browser.execute_script("Jupyter.notebook.toggle_cells_outputs();")
    cell_output_states = notebook.browser.execute_script(
        "return Jupyter.notebook.get_cells().map(c => c.collapsed)")
    assert cell_output_states == [False] * 3, "ensure that all cells are not collapsed"

    # Test that cells, which start off not scrolled are scrolled after
    # calling the multiselected scroll toggle.
    select_cells()
    assert n_selected_cells() == 3
    notebook.browser.execute_script("Jupyter.notebook.toggle_cells_outputs_scroll();")
    cell_scrolled_states = notebook.browser.execute_script(
        "return Jupyter.notebook.get_cells().map(c => c.output_area.scroll_state)")
    assert all(cell_scrolled_states), "ensure that all have scrolling enabled"

    # Test that cells, which start off not cleared are cleared after
    # calling the multiselected scroll toggle.
    select_cells()
    assert n_selected_cells() == 3
    notebook.browser.execute_script("Jupyter.notebook.clear_cells_outputs();")
    cell_outputs_cleared = notebook.browser.execute_script(
        "return Jupyter.notebook.get_cells().map(c => c.output_area.element.html())")
    assert cell_outputs_cleared == [""] * 3, "ensure that all cells are cleared"