Skip to content

Commit c43ef0f

Browse files
committed
add nteract_on_jupyter
1 parent 39cd76e commit c43ef0f

File tree

9 files changed

+124
-88
lines changed

9 files changed

+124
-88
lines changed

atest/acceptance/classic/10_notebook.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Library JupyterLibrary
55
Library Process
66

77
*** Test Cases ***
8-
IPython Notebook
8+
IPython Notebook on Classic
99
Open Notebook Classic
1010
Launch a new Notebook Classic Notebook
1111
Add and Run Notebook Classic Code Cell
1212
Wait Until Notebook Classic Kernel Is Idle
13-
Capture Page Screenshot ipython.png
13+
Capture Page Screenshot clasic${/}ipython.png

atest/acceptance/lab/10_notebook.robot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ Library JupyterLibrary
66
Library Process
77

88
*** Test Cases ***
9-
IPython Notebook
9+
IPython Notebook on Lab
1010
Open JupyterLab
1111
Launch a new JupyterLab Document
1212
Add and Run JupyterLab Code Cell print("hello world")
1313
Wait Until JupyterLab Kernel Is Idle
14-
Capture Page Screenshot ipython.png
14+
Capture Page Screenshot lab${/}ipython.png
1515

16-
IPython Notebook Outputs
16+
IPython Notebook Outputs on Lab
1717
Open JupyterLab
1818
Launch a new JupyterLab Document
1919
: FOR ${i} IN RANGE ${10}
2020
\ Add and Run JupyterLab Code Cell print("${i} hello world " * ${i ** 2})
2121
Wait Until JupyterLab Kernel Is Idle
22-
Screenshot Each Output of Active JupyterLab Document ipython_outputs${/}
22+
Screenshot Each Output of Active JupyterLab Document lab${/}ipython_outputs${/}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*** Settings ***
2+
Test Teardown Close All Browsers
3+
Default Tags notebook
4+
Library JupyterLibrary
5+
Library Process
6+
7+
*** Test Cases ***
8+
IPython Notebook on nteract
9+
Open nteract
10+
Launch a new nteract Notebook
11+
Add and Run nteract Code Cell
12+
Wait Until nteract Kernel Is Idle
13+
Capture Page Screenshot nteract${/}ipython.png
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*** Settings ***
2+
Suite Setup Wait for New Jupyter Server to be Ready
3+
Suite Teardown Terminate All Jupyter Servers
4+
Force Tags nteract
5+
Library JupyterLibrary

docs/KEYWORDS.ipynb

Lines changed: 38 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 6,
28+
"execution_count": null,
2929
"metadata": {
3030
"jupyter": {
3131
"source_hidden": true
@@ -38,35 +38,13 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": 7,
41+
"execution_count": null,
4242
"metadata": {
4343
"jupyter": {
4444
"source_hidden": true
4545
}
4646
},
47-
"outputs": [
48-
{
49-
"data": {
50-
"text/html": [
51-
"\n",
52-
" <iframe\n",
53-
" width=\"100%\"\n",
54-
" height=\"\"\n",
55-
" src=\"_static/JupyterLibrary.html\"\n",
56-
" frameborder=\"0\"\n",
57-
" allowfullscreen\n",
58-
" ></iframe>\n",
59-
" "
60-
],
61-
"text/plain": [
62-
"<IPython.lib.display.IFrame at 0x7fda84204be0>"
63-
]
64-
},
65-
"execution_count": 7,
66-
"metadata": {},
67-
"output_type": "execute_result"
68-
}
69-
],
47+
"outputs": [],
7048
"source": [
7149
"iframe(\"JupyterLibrary\")"
7250
]
@@ -75,41 +53,27 @@
7553
"cell_type": "markdown",
7654
"metadata": {},
7755
"source": [
78-
"## Jupyter Notebook Classic\n",
79-
"The Jupyter Notebook Classic keywords are themselves defined in `.robot` files, and are loaded dynamically. They all include _Notebook Classic_ in the keyword name."
56+
"## Clients\n",
57+
"\n",
58+
"The Jupyter client keywords are themselves defined in `.robot` files, and are loaded dynamically. They all include the name of the client in the keyword name."
59+
]
60+
},
61+
{
62+
"cell_type": "markdown",
63+
"metadata": {},
64+
"source": [
65+
"### Jupyter Notebook Classic"
8066
]
8167
},
8268
{
8369
"cell_type": "code",
84-
"execution_count": 8,
70+
"execution_count": null,
8571
"metadata": {
8672
"jupyter": {
8773
"source_hidden": true
8874
}
8975
},
90-
"outputs": [
91-
{
92-
"data": {
93-
"text/html": [
94-
"\n",
95-
" <iframe\n",
96-
" width=\"100%\"\n",
97-
" height=\"\"\n",
98-
" src=\"_static/notebook.html\"\n",
99-
" frameborder=\"0\"\n",
100-
" allowfullscreen\n",
101-
" ></iframe>\n",
102-
" "
103-
],
104-
"text/plain": [
105-
"<IPython.lib.display.IFrame at 0x7fda84204a58>"
106-
]
107-
},
108-
"execution_count": 8,
109-
"metadata": {},
110-
"output_type": "execute_result"
111-
}
112-
],
76+
"outputs": [],
11377
"source": [
11478
"iframe(\"notebook\")"
11579
]
@@ -118,44 +82,41 @@
11882
"cell_type": "markdown",
11983
"metadata": {},
12084
"source": [
121-
"## JupyterLab\n",
122-
"The JupyterLab keywords are themselves defined in `.robot` files, and are loaded dynamically. They all include _JupyterLab_ in the keyword name."
85+
"### JupyterLab"
12386
]
12487
},
12588
{
12689
"cell_type": "code",
127-
"execution_count": 9,
90+
"execution_count": null,
12891
"metadata": {
12992
"jupyter": {
13093
"source_hidden": true
13194
}
13295
},
133-
"outputs": [
134-
{
135-
"data": {
136-
"text/html": [
137-
"\n",
138-
" <iframe\n",
139-
" width=\"100%\"\n",
140-
" height=\"\"\n",
141-
" src=\"_static/jupyterlab.html\"\n",
142-
" frameborder=\"0\"\n",
143-
" allowfullscreen\n",
144-
" ></iframe>\n",
145-
" "
146-
],
147-
"text/plain": [
148-
"<IPython.lib.display.IFrame at 0x7fda842042b0>"
149-
]
150-
},
151-
"execution_count": 9,
152-
"metadata": {},
153-
"output_type": "execute_result"
154-
}
155-
],
96+
"outputs": [],
15697
"source": [
15798
"iframe(\"jupyterlab\")"
15899
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"metadata": {},
104+
"source": [
105+
"### nteract on Jupyter"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": null,
111+
"metadata": {
112+
"jupyter": {
113+
"source_hidden": true
114+
}
115+
},
116+
"outputs": [],
117+
"source": [
118+
"iframe(\"nteract_on_jupyter\")"
119+
]
159120
}
160121
],
161122
"metadata": {

scripts/lint.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ def lint():
1616
for src in RF_SRC:
1717
check_call(["python", "-m", "robot.tidy", "-r", src])
1818

19-
for nbp in (Path(__file__).parent / "docs").rglob("*.ipynb"):
20-
nbf = read(nbp, NO_CONVERT)
19+
for nbp in (Path(__file__).parent.parent / "docs").rglob("*.ipynb"):
20+
nbf = read(str(nbp), NO_CONVERT)
2121
changed = False
22-
for cell in nbf:
23-
if cell.cell_type == "code_cell":
22+
for cell in nbf.cells:
23+
if cell.cell_type == "code":
2424
if cell.outputs:
2525
cell.outputs = []
2626
changed = True
2727
if cell.execution_count:
2828
cell.execution_count = None
2929
changed = True
3030
if changed:
31-
write(nbf, nbp)
31+
print(f"Overwriting {nbp}")
32+
write(nbf, str(nbp))
3233

3334

3435
if __name__ == "__main__":
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*** Settings ***
2+
Resource JupyterLibrary/clients/nteract_on_jupyter/Selectors.robot
3+
Library JupyterLibrary
4+
5+
*** Keywords ***
6+
Add and Run nteract Code Cell
7+
[Arguments] ${code}=print("hello world")
8+
[Documentation] Add a ``code`` cell to the currently active notebook and run it.
9+
${creators} = Get WebElements css:${NOJ CSS CREATOR}
10+
Mouse Over ${creators[-1]}
11+
Click Element css:${NOJ CSS CREATOR}:hover ${NOJ CSS ADD CODE CELL}
12+
Click Element css:${NOJ CSS CELL INPUT}
13+
Execute JavaScript document.querySelector("${NOJ CSS CELL INPUT}").CodeMirror.setValue(`${code}`)
14+
Click Element css:${NOJ CSS EXECUTE}
15+
16+
Wait Until nteract Kernel Is Idle
17+
[Documentation] Wait for a kernel to be busy, and then stop being busy
18+
Wait Until Page Does Not Contain ${NOJ TEXT BUSY PROMPT}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*** Variables ***
2+
${NOJ CSS TREE LIST} .listing-root
3+
${NOJ CSS CARD} .new-notebook
4+
${NOJ CSS CARD KERNEL} ${NOJ CSS CARD} .display-name-long
5+
${NOJ CSS CELL} .cell
6+
${NOJ CSS CELL INPUT} .cell .CodeMirror .CodeMirror
7+
${NOJ CSS CREATOR} .creator-hover-region
8+
${NOJ CSS ADD CODE CELL} .add-code-cell
9+
${NOJ CSS CELL TOOLBAR} .cell-toolbar
10+
${NOJ CSS EXECUTE} ${NOJ CSS CELL TOOLBAR} .executeButton
11+
${NOJ TEXT BUSY PROMPT} [*]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
*** Settings ***
2+
Resource JupyterLibrary/clients/nteract_on_jupyter/Selectors.robot
3+
Documentation Keywords for working with nteract web application
4+
... You should have already started a Jupyter Server, such as with
5+
... *Wait For New Jupyter Server To Be Ready*.
6+
7+
8+
*** Keywords ***
9+
Open nteract
10+
[Arguments] ${browser}=headlessfirefox ${nbserver}=${None} ${url}=${EMPTY} &{configuration}
11+
[Documentation] Open nteract, served from the given (or most-recently-started)
12+
... ``nbserver`` in a ``browser`` (or ``headlessfirefox``) or ``url``,
13+
... then wait for the splash screen.
14+
... Extra ``configuration`` is passed on to SeleniumLibrary's *Open Browser*.
15+
${nbserver_url} = Run Keyword If not "${url}" Get Jupyter Server URL ${nbserver}
16+
${token} = Run Keyword If not "${url}" Get Jupyter Server Token ${nbserver}
17+
${final_url} = Set Variable If "${url}" ${url} ${nbserver_url}nteract?token=${token}
18+
Open Browser url=${final_url} browser=${browser} &{configuration}
19+
Wait Until Page Contains Element css:${NOJ CSS TREE LIST}
20+
21+
Launch a new nteract Notebook
22+
[Arguments] ${kernel}=Python 3
23+
[Documentation] Use the nteract tree to launch a
24+
... Notebook with the given ``kernel``
25+
Click Element css:${NOJ CSS CARD KERNEL}\[title$="${kernel}"]
26+
Select Window NEW
27+
Wait Until Page Contains Element css:${NOJ CSS CELL}

0 commit comments

Comments
 (0)