Skip to content

Commit c29a72b

Browse files
committed
start fleshing out stuff from lab
1 parent 071d23f commit c29a72b

File tree

12 files changed

+165
-12
lines changed

12 files changed

+165
-12
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
include LICENSE README.md
2+
recursive-include src/JupyterLibrary *.robot

atest/acceptance/01_server/00_basic.robot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@ Start three servers
2929
Should Not Contain ${log3} The Jupyter Notebook is running msg=Unawaited server log should not contain expected status message
3030
${terminated} = Terminate All Jupyter Servers
3131
Should be equal as integers ${terminated} 0 msg=No servers should have been terminated
32-
Run Keyword And Expect Error Only 0 of 3* Wait for Jupyter Server to be Ready ${nb2} ${nb1} ${nb3}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*** Settings ***
2+
Suite Setup Wait for New Jupyter Server to be Ready
3+
Test Teardown Close All Browsers
4+
Library JupyterLibrary
5+
Library Process
6+
Resource JupyterLibrary/resources/jupyterlab/Shell.robot
7+
8+
*** Test Cases ***
9+
Open JupyterLab
10+
Open JupyterLab
11+
12+
Get Help
13+
Open JupyterLab
14+
Click JupyterLab Menu Help
15+
Click JupyterLab Menu Item About JupyterLab
16+
Click Element css:${JLAB CSS ACCEPT}
17+
18+
*** Keywords ***
19+
Clean Up Everything
20+
Close All Browsers
21+
Terminate All Processes

atest/acceptance/__init__.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*** Settings ***
2+
Suite Teardown Terminate All Processes
3+
Library Process

setup.cfg

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,5 @@ exclude = .git,__pycache__,envs
5454
max-complexity = 10
5555

5656
[isort]
57-
force_alphabetical_sort = True
58-
force_single_line = True
5957
lines_after_imports = 2
60-
line_length = 200
61-
not_skip = __init__.py
58+
line_length = 88

src/JupyterLibrary/core.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
from .keywords import server
1+
from glob import glob
2+
from os.path import basename, dirname, join
3+
4+
from robot.libraries.BuiltIn import BuiltIn
25
from SeleniumLibrary import SeleniumLibrary
36

7+
from .keywords import server
8+
9+
10+
RESOURCES = join(dirname(__file__), "resources")
11+
412

513
class JupyterLibrary(SeleniumLibrary):
614
"""JupyterLibrary is a Jupyter testing library for Robot Framework."""
@@ -30,3 +38,6 @@ def __init__(
3038
screenshot_root_directory=None,
3139
)
3240
self.add_library_components([server.ServerKeywords(self)])
41+
for path in glob(join(RESOURCES, "jupyterlab", "*.robot")):
42+
resource = "JupyterLibrary/resources/jupyterlab/" + basename(path)
43+
BuiltIn().import_resource(resource)

src/JupyterLibrary/keywords/server.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import subprocess
2+
import time
3+
14
from robot.libraries.BuiltIn import BuiltIn
2-
from SeleniumLibrary.base import keyword
3-
from SeleniumLibrary.base import LibraryComponent
5+
from SeleniumLibrary.base import LibraryComponent, keyword
46
from six.moves.urllib.request import urlopen
57
from tornado.escape import json_decode
68

7-
import subprocess
8-
import time
9-
109

1110
class NBServer(object):
1211
process = None
@@ -63,11 +62,21 @@ def wait_for_jupyter_server_to_be_ready(self, *nbservers, **kwargs):
6362
time.sleep(interval)
6463
last_error = err
6564

66-
assert ready == len(nbservers), "Only {} of {} servers were ready: {}".format(
65+
assert ready == len(
66+
nbservers
67+
), "Only {} of {} servers were ready. Last error: {}".format(
6768
ready, len(nbservers), last_error
6869
)
6970
return ready
7071

72+
@keyword
73+
def wait_for_new_jupyter_server_to_be_ready(
74+
self, command=None, *arguments, **configuration
75+
):
76+
handle = self.start_new_jupyter_server(command, *arguments, **configuration)
77+
self.wait_for_jupyter_server_to_be_ready(handle)
78+
return handle
79+
7180
@keyword
7281
def terminate_all_jupyter_servers(self, kill=False):
7382
""" Close all Jupyter servers started by JupyterLibrary
@@ -82,6 +91,14 @@ def terminate_all_jupyter_servers(self, kill=False):
8291

8392
return terminated
8493

94+
@keyword
95+
def get_jupyter_server_info(self, nbserver=None):
96+
nbserver = nbserver or self._nbserver_handles[-1]
97+
plib = BuiltIn().get_library_instance("Process")
98+
nbpopen = plib.get_process_object(nbserver)
99+
nbj = self.get_jupyter_servers()[nbpopen.pid]
100+
return nbj
101+
85102
def get_jupyter_servers(self):
86103
nbservers = list(
87104
map(
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*** Settings ***
2+
Documentation Run JupyterLab commands
3+
Resource JupyterLibrary/resources/jupyterlab/Selectors.robot
4+
5+
6+
*** Keywords ***
7+
Execute JupyterLab Command
8+
[Arguments] ${command} ${accept}=${True} ${close}=${True}
9+
[Documentation] Use the JupyterLab Command Palette to run a command
10+
Maybe accept a prompt
11+
Maybe Open JupyterLab Sidebar command-palette
12+
Input Text css:${JLAB CSS CMD INPUT} ${command}
13+
Wait Until Page Contains Element css:${JLAB CSS CMD ITEM}
14+
Click Element css:${JLAB CSS CMD ITEM}
15+
Run Keyword If ${accept} Maybe Accept a Prompt
16+
Run Keyword If ${close} Maybe Close Sidebar
17+
18+
Reset Application State and Close
19+
[Documentation] Try to clean up after doing some things to the JupyterLab state
20+
Execute JupyterLab Command Reset Application State
21+
Close Browser
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*** Settings ***
2+
Documentation Interact with the JupyterLab Launcher
3+
Resource JupyterLibrary/resources/jupyterlab/Selectors.robot
4+
5+
*** Keywords ***
6+
Launch a new Document
7+
[Arguments] ${kernel}=Python3 ${category}=Notebook
8+
[Documentation] Use the JupyterLab launcher to launch Notebook or Console
9+
Click Element ${JLAB XP CARD}[@title='${kernel}'][@data-category='${category}']
10+
Wait Until Page Does Not Contain Element css:${JLAB CSS SPINNER}
11+
Wait Until Page Contains Element css:${JLAB CSS CELL}
12+
Sleep 0.1s
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*** Variables ***
2+
${JLAB ID SPLASH} jupyterlab-splash
3+
4+
${JLAB CSS CELL} .jp-Notebook .jp-Cell:last-of-type .jp-InputArea-editor .CodeMirror
5+
${JLAB CSS SPINNER} .jp-Spinner
6+
${JLAB CSS CMD PALETTE} li[data-id="command-palette"]
7+
${JLAB CSS CMD INPUT} .p-CommandPalette-input
8+
${JLAB CSS CMD ITEM} .p-CommandPalette-item
9+
${JLAB CSS ACCEPT} .jp-mod-accept
10+
${JLAB CSS ACTIVE SIDEBAR} .jp-SideBar .p-TabBar-tab.p-mod-current
11+
${JLAB CSS SIDEBAR TAB} .jp-SideBar .p-TabBar-tab
12+
13+
${JLAB XP TOP} //div[@id='jp-top-panel']
14+
${JLAB XP MENU LABEL} //div[@class='p-MenuBar-itemLabel']
15+
${JLAB XP MENU ITEM LABEL} //div[@class='p-Menu-itemLabel']
16+
${JLAB XP CARD} //div[@class='jp-LauncherCard']
17+
${JLAB XP DOCK} //div[@id='jp-main-dock-panel']

0 commit comments

Comments
 (0)