Skip to content

Commit bc3a8cb

Browse files
committed
Convert test for saving with complex name to Selenium
1 parent e00a86c commit bc3a8cb

File tree

2 files changed

+65
-112
lines changed

2 files changed

+65
-112
lines changed

notebook/tests/notebook/save.js

Lines changed: 0 additions & 112 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Test saving a notebook with escaped characters
2+
"""
3+
4+
from urllib.parse import quote
5+
from .utils import wait_for_selector, new_window
6+
7+
promise_js = """
8+
var done = arguments[arguments.length - 1];
9+
%s.then(
10+
data => { done(["success", data]); },
11+
error => { done(["error", error]); }
12+
);
13+
"""
14+
15+
def execute_promise(js, browser):
16+
state, data = browser.execute_async_script(promise_js % js)
17+
if state == 'success':
18+
return data
19+
raise Exception(data)
20+
21+
22+
def test_save(notebook):
23+
# don't use unicode with ambiguous composed/decomposed normalization
24+
# because the filesystem may use a different normalization than literals.
25+
# This causes no actual problems, but will break string comparison.
26+
nbname = "has#hash and space and unicø∂e.ipynb"
27+
escaped_name = quote(nbname)
28+
29+
notebook.edit_cell(index=0, content="s = '??'")
30+
31+
notebook.browser.execute_script("Jupyter.notebook.set_notebook_name(arguments[0])", nbname)
32+
33+
model = execute_promise("Jupyter.notebook.save_notebook()", notebook.browser)
34+
assert model['name'] == nbname
35+
36+
current_name = notebook.browser.execute_script("return Jupyter.notebook.notebook_name")
37+
assert current_name == nbname
38+
39+
current_path = notebook.browser.execute_script("return Jupyter.notebook.notebook_path")
40+
assert current_path == nbname
41+
42+
displayed_name = notebook.browser.find_element_by_id('notebook_name').text
43+
assert displayed_name + '.ipynb' == nbname
44+
45+
execute_promise("Jupyter.notebook.save_checkpoint()", notebook.browser)
46+
47+
checkpoints = notebook.browser.execute_script("return Jupyter.notebook.checkpoints")
48+
assert len(checkpoints) == 1
49+
50+
notebook.browser.find_element_by_css_selector('#ipython_notebook a').click()
51+
hrefs_nonmatch = []
52+
for link in wait_for_selector(notebook.browser, 'a.item_link'):
53+
href = link.get_attribute('href')
54+
if escaped_name in href:
55+
print("Opening", href)
56+
notebook.browser.get(href)
57+
wait_for_selector(notebook.browser, '.cell')
58+
break
59+
hrefs_nonmatch.append(href)
60+
else:
61+
raise AssertionError("{!r} not found in {!r}"
62+
.format(escaped_name, hrefs_nonmatch))
63+
64+
current_name = notebook.browser.execute_script("return Jupyter.notebook.notebook_name")
65+
assert current_name == nbname

0 commit comments

Comments
 (0)