Skip to content

Commit 09b8c93

Browse files
authored
Merge pull request #4310 from takluyver/selenium-multiselect
Convert multiselect test to Selenium
2 parents 31c2184 + 9035cb1 commit 09b8c93

File tree

4 files changed

+69
-102
lines changed

4 files changed

+69
-102
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ __pycache__
2727
\#*#
2828
.#*
2929
.coverage
30+
.pytest_cache
3031
src
3132

3233
*.swp
@@ -38,4 +39,5 @@ config.rst
3839
/.project
3940
/.pydevproject
4041

41-
package-lock.json
42+
package-lock.json
43+
geckodriver.log

notebook/tests/notebook/multiselect.js

Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
def test_multiselect(notebook):
2+
def extend_selection_by(delta):
3+
notebook.browser.execute_script(
4+
"Jupyter.notebook.extend_selection_by(arguments[0]);", delta)
5+
6+
def n_selected_cells():
7+
return notebook.browser.execute_script(
8+
"return Jupyter.notebook.get_selected_cells().length;")
9+
10+
a = 'print("a")'
11+
b = 'print("b")'
12+
c = 'print("c")'
13+
notebook.edit_cell(index=0, content=a)
14+
notebook.append(b, c)
15+
16+
notebook.focus_cell(0)
17+
assert n_selected_cells() == 1
18+
19+
# Check that only one cell is selected according to CSS classes as well
20+
selected_css = notebook.browser.find_elements_by_css_selector(
21+
'.cell.jupyter-soft-selected, .cell.selected')
22+
assert len(selected_css) == 1
23+
24+
# Extend the selection down one
25+
extend_selection_by(1)
26+
assert n_selected_cells() == 2
27+
28+
# Contract the selection up one
29+
extend_selection_by(-1)
30+
assert n_selected_cells() == 1
31+
32+
# Extend the selection up one
33+
notebook.focus_cell(1)
34+
extend_selection_by(-1)
35+
assert n_selected_cells() == 2
36+
37+
# Convert selected cells to Markdown
38+
notebook.browser.execute_script("Jupyter.notebook.cells_to_markdown();")
39+
cell_types = notebook.browser.execute_script(
40+
"return Jupyter.notebook.get_cells().map(c => c.cell_type)")
41+
assert cell_types == ['markdown', 'markdown', 'code']
42+
# One cell left selected after conversion
43+
assert n_selected_cells() == 1
44+
45+
# Convert selected cells to raw
46+
notebook.focus_cell(1)
47+
extend_selection_by(1)
48+
assert n_selected_cells() == 2
49+
notebook.browser.execute_script("Jupyter.notebook.cells_to_raw();")
50+
cell_types = notebook.browser.execute_script(
51+
"return Jupyter.notebook.get_cells().map(c => c.cell_type)")
52+
assert cell_types == ['markdown', 'raw', 'raw']
53+
# One cell left selected after conversion
54+
assert n_selected_cells() == 1
55+
56+
# Convert selected cells to code
57+
notebook.focus_cell(0)
58+
extend_selection_by(2)
59+
assert n_selected_cells() == 3
60+
notebook.browser.execute_script("Jupyter.notebook.cells_to_code();")
61+
cell_types = notebook.browser.execute_script(
62+
"return Jupyter.notebook.get_cells().map(c => c.cell_type)")
63+
assert cell_types == ['code'] * 3
64+
# One cell left selected after conversion
65+
assert n_selected_cells() == 1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
zip_safe = False,
9999
install_requires = [
100100
'jinja2',
101-
'tornado>=4',
101+
'tornado>=4, <6',
102102
# pyzmq>=17 is not technically necessary,
103103
# but hopefully avoids incompatibilities with Tornado 5. April 2018
104104
'pyzmq>=17',

0 commit comments

Comments
 (0)