Skip to content

Commit cf644e8

Browse files
bollwyvldatakurre
authored andcommitted
first steps at testing as-installed opencv (#63)
Fix OpenCV on Linux and add tests for OpenCV
1 parent a6fede6 commit cf644e8

File tree

13 files changed

+142
-24
lines changed

13 files changed

+142
-24
lines changed

anaconda-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ env_specs:
121121

122122
robotlab-test:
123123
channels:
124-
- https://conda.anaconda.org/anaconda
125124
- https://conda.anaconda.org/conda-forge
125+
- https://conda.anaconda.org/anaconda
126126
- ./_artifacts/conda-bld
127127
packages:
128128
- robotlab

ci/env-combine.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: robotlab-combine
22

33
channels:
4-
- https://conda.anaconda.org/anaconda
54
- https://conda.anaconda.org/conda-forge
5+
- https://conda.anaconda.org/anaconda
66

77
dependencies:
88
- robotframework

ci/env-lab.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: robotlab-lab
22

33
channels:
4-
- https://conda.anaconda.org/anaconda
54
- https://conda.anaconda.org/conda-forge
5+
- https://conda.anaconda.org/anaconda
66

77
dependencies:
88
- black

recipes/robotlab/builder.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pathlib import Path
2-
import os, sys, shutil, json
2+
import os, sys, shutil, json, platform, re
3+
4+
PLATFORM = platform.system().lower()
35

46
SRC_DIR = Path(os.environ["SRC_DIR"])
57
PREFIX = Path(os.environ["PREFIX"])
@@ -19,6 +21,13 @@
1921
}
2022
SVG = SRC_DIR / "robotlab" / "src" / "robotlab" / "icons" / "starter.svg"
2123

24+
OPENCV_OSX = """
25+
${prefix} = Evaluate __import__("sys").prefix
26+
Create WebDriver Firefox executable_path=${prefix}${/}bin${/}geckodriver firefox_binary=${prefix}${/}bin${/}firefox
27+
Go To https://www.google.com/?hl=en
28+
"""
29+
30+
2231
print("making directories...")
2332
[d.mkdir(exist_ok=True, parents=True) for d in [SHARE, ETC, WWW]]
2433

@@ -33,6 +42,22 @@
3342
for dest, src in NOTEBOOKS.items()
3443
]
3544

45+
print("hacking OpenCV Notebook on OSX")
46+
47+
if PLATFORM == "darwin":
48+
opencv = EXAMPLES / "OpenCV.ipynb"
49+
nb = json.loads(opencv.read_text())
50+
for cell in nb["cells"]:
51+
if cell["cell_type"] == "code":
52+
lines = cell["source"]
53+
for i, line in enumerate(lines):
54+
if re.findall(r"\s+Open browser", line, flags=re.I):
55+
lines[i] = OPENCV_OSX
56+
print(lines)
57+
cell["source"] = lines
58+
59+
opencv.write_text(json.dumps(nb, indent=2))
60+
3661

3762
print("making starters...")
3863
(ETC / "robotlab-starters.json").write_text(json.dumps({
@@ -45,6 +70,13 @@
4570
"py_src": "robotkernel",
4671
"src": "resources/starter/quickstart-starter.ipynb"
4772
},
73+
"robotkernel-examples": {
74+
"type": "copy",
75+
"label": "More Robot Kernel Examples",
76+
"description": "Examples of using robotkernel",
77+
"icon": SVG.read_text().replace("jp-icon2", "jp-icon-contrast1"),
78+
"src": str(EXAMPLES)
79+
},
4880
"robotkernel-tutorial": {
4981
"label": "Tutorial",
5082
"description": "Tutorial for Robot Framework on Jupyter",

recipes/robotlab/meta.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ requirements:
4848
- jupyter-starters {{ robot_starters }}
4949
- jupyterlab {{ robot_jupyterlab }}
5050
- jupytext >=1.3.1
51-
- matplotlib >=3.1.2
51+
- matplotlib-base >=3.1.2
5252
- nodejs {{ robot_node }}
53-
- opencv
53+
- py-opencv
5454
- pyshortcuts
5555
- python
5656
- pywinpty {{ robot_pywinpty }} # [win]
@@ -75,8 +75,11 @@ test:
7575
commands:
7676
- robotlab --version
7777
- robotlab-extension list
78-
- robotlab-examples
7978
- robotlab-tutorial
79+
- robotlab-examples
80+
- cd robotkernel-examples
81+
- jupyter nbconvert --execute --ExecutePreprocessor.timeout=600 OpenCV.ipynb # [not osx]
82+
- cd ..
8083
- mkdir Desktop # [unix]
8184
- HOME=$(pwd) robotlab-shortcuts # [unix]
8285

scripts/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
"--cache-dir",
5757
CONDA_CACHE,
5858
"-c",
59-
"https://conda.anaconda.org/anaconda",
60-
"-c",
6159
"https://conda.anaconda.org/conda-forge",
60+
"-c",
61+
"https://conda.anaconda.org/anaconda",
6262
"--python",
6363
PY_MIN,
6464
]

tests/acceptance/RobotLab/1_CLI/10_examples.robot

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22
Documentation robotlab-examples
33
Force Tags app:robotlab-examples
44
Resource ../../../resources/CLI.robot
5+
Library Process
6+
7+
*** Variables ***
8+
${NBCONVERT} jupyter nbconvert --execute --ExecutePreprocessor.timeout=600
59

610
*** Test Cases ***
711
Can I install the examples?
812
[Documentation] Does robotlab-examples work?
13+
[Tags] example:opencv
914
Check a RobotLab CLI command robotlab-examples check_dir=robotkernel-examples
15+
16+
Can I run the examples?
17+
[Documentation] Will they nbconvert?
18+
[Tags] example:opencv
19+
${log} = Set Variable ${OUTPUT DIR}${/}robotlab-example-nbconvert-opencv.log
20+
${proc} = Run Process ${ACTIVATE} && ${NBCONVERT} OpenCV.ipynb shell=True cwd=${OUTPUT DIR}${/}robotkernel-examples stdout=${log} stderr=STDOUT
21+
... env:PS1=[:|]
22+
Should Be Equal As Numbers ${proc.rc} 0
23+
Copy File ${OUTPUT DIR}${/}robotkernel-examples${/}OpenCV.html ${OUTPUT DIR}${/}nbconvert-OpenCV.html

tests/acceptance/RobotLab/2_Lab/20_Robot_Notebook.robot

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,3 @@ Can RobotLab make a Robot Notebook?
2121
Execute JupyterLab Command Save Notebook
2222
Sleep 2s
2323
Capture Page Screenshot ${prefix}_09_save.png
24-
25-
*** Keywords ***
26-
The Robot Popup Should Contain
27-
[Arguments] ${prefix} ${document} ${msg}
28-
[Documentation] With an open Robot Notebook, take a look at the log or report
29-
Click Link ${document}
30-
Sleep 1s
31-
Select Window Jupyter ${document}
32-
Page Should Contain ${msg}
33-
Capture Page Screenshot ${prefix}_10_${document.lower()}.png
34-
Close Window
35-
Select Window RobotLab

tests/acceptance/RobotLab/2_Lab/30_Tutorial.robot

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Resource ../../../resources/Browser.robot
66
Resource ../../../resources/Selectors.robot
77

88
*** Variables ***
9+
${KERNEL LANGUAGE} Python 3
910
${TOKEN CELL 00} .jp-CodeCell:nth-child(3) .CodeMirror
1011

1112
*** Test Cases ***
@@ -46,7 +47,7 @@ Open the Tutorial Notebook
4647
Wait Until Page Contains Element ${XP FILE TREE TUTORIAL 00} timeout=10s
4748
Double Click Element ${XP FILE TREE TUTORIAL 00}
4849
Wait Until Page Contains Element css:.jp-Notebook table timeout=10s
49-
Wait Until Page Contains Python 3 | Idle timeout=3s
50+
Wait Until Page Contains ${KERNEL LANGUAGE} | Idle timeout=3s
5051
Capture Page Screenshot ${prefix}_2_after_launch.png
5152
Execute JupyterLab Command Clear All Outputs
5253

@@ -60,6 +61,6 @@ Run the Tutorial Notebook
6061
Click Element ${CSS NOTEBOOK SAVE}
6162
Execute JupyterLab Command Run All Cells
6263
Wait Until Page Does Not Contain [*] timeout=20s
63-
Wait Until Page Contains Python 3 | Idle timeout=3s
64+
Wait Until Page Contains ${KERNEL LANGUAGE} | Idle timeout=3s
6465
Click Element ${CSS NOTEBOOK SAVE}
6566
Execute JupyterLab Command Close All
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
*** Settings ***
2+
Documentation Try the Examples
3+
Force Tags starter:example
4+
Library JupyterLibrary
5+
Resource ../../../resources/Browser.robot
6+
Resource ../../../resources/Lab.robot
7+
Resource ../../../resources/Selectors.robot
8+
9+
*** Variables ***
10+
${KERNEL LANGUAGE} Robot Framework
11+
12+
*** Test Cases ***
13+
Will the Example Starter Launch?
14+
[Documentation] Start the Example
15+
[Tags] example:opencv
16+
Open RobotLab
17+
${prefix} = Set Variable example_
18+
Execute JupyterLab Command Close All
19+
Wait Until Page Contains Element ${XP LAUNCH SECTION}
20+
Capture Page Screenshot ${prefix}_0_before_starter.png
21+
Click Element ${CSS LAUNCH CARD EXAMPLES}
22+
Wait Until Page Contains Element ${XP FILE TREE EXAMPLE OPENCV} timeout=10s
23+
Capture Page Screenshot ${prefix}_1_after_starter.png
24+
25+
Will the OpenCV Notebook Run?
26+
[Documentation] Run the OpenCV Tutorial Notebook
27+
[Tags] example:opencv
28+
Open RobotLab
29+
${prefix} = Set Variable example_opencv_
30+
Open the Example Folder ${prefix}
31+
Open the Example Notebook ${prefix} ${XP FILE TREE EXAMPLE OPENCV}
32+
Run the Example Notebook ${prefix}
33+
Capture Page Screenshot ${prefix}_6_after_run_all.png
34+
The Robot Popup Should Contain ${prefix} Log passed, 0 failed
35+
The Robot Popup Should Contain ${prefix} Report All tests passed
36+
Capture Page Screenshot ${prefix}_7_reported.png
37+
Screenshot Each Output of Active JupyterLab Document ${prefix}_8_all_
38+
39+
*** Keywords ***
40+
Open the Example Folder
41+
[Arguments] ${prefix}
42+
[Documentation] Open the example folder
43+
Execute JupyterLab Command Close All
44+
Maybe Open JupyterLab Sidebar File Browser
45+
Click Element ${CRUMBS HOME}
46+
Double Click Element ${XP FILE TREE EXAMPLE}
47+
Capture Page Screenshot ${prefix}_1_in_folder.png
48+
49+
Open the Example Notebook
50+
[Arguments] ${prefix} ${example}
51+
[Documentation] Open and prepare the example notebook
52+
Wait Until Page Contains Element ${example} timeout=10s
53+
Double Click Element ${example}
54+
Wait Until Page Contains ${KERNEL LANGUAGE} | Idle timeout=10s
55+
Capture Page Screenshot ${prefix}_2_after_launch.png
56+
Execute JupyterLab Command Clear All Outputs
57+
Sleep 1s
58+
Capture Page Screenshot ${prefix}_3_after_clean.png
59+
60+
Run the Example Notebook
61+
[Arguments] ${prefix}
62+
[Documentation] Actually run the example notebook
63+
Execute JupyterLab Command Run All Cells
64+
Wait Until Page Does Not Contain [*] timeout=120s
65+
Wait Until Page Contains ${KERNEL LANGUAGE} | Idle timeout=120s
66+
Capture Page Screenshot ${prefix}_4_after_run.png

0 commit comments

Comments
 (0)