Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
00ba1848
Commit
00ba1848
authored
Feb 06, 2019
by
Jason Stafford
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
selenium tests for webworkers
parent
4d97a5b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
138 additions
and
2 deletions
+138
-2
Makefile
Makefile
+8
-1
src/webworker.js
src/webworker.js
+1
-1
test/conftest.py
test/conftest.py
+60
-0
test/test_webworker.py
test/test_webworker.py
+69
-0
No files found.
Makefile
View file @
00ba1848
...
...
@@ -58,7 +58,8 @@ all: build/pyodide.asm.js \
build/test.data
\
build/packages.json
\
build/test.html
\
build/webworker.js
build/webworker.js
\
build/webworker_dev.js
build/pyodide.asm.js
:
src/main.bc src/jsimport.bc src/jsproxy.bc src/js2python.bc
\
...
...
@@ -115,6 +116,12 @@ build/renderedhtml.css: src/renderedhtml.less
build/webworker.js
:
src/webworker.js
cp
$<
$@
sed
-i
-e
's#{{DEPLOY}}#https://iodide.io/pyodide-demo/#g'
$@
build/webworker_dev.js
:
src/webworker.js
cp
$<
$@
sed
-i
-e
"s#{{DEPLOY}}##g"
$@
sed
-i
-e
"s#pyodide.js#pyodide_dev.js#g"
$@
test
:
all
pytest
test
/
-v
...
...
src/webworker.js
View file @
00ba1848
self
.
languagePluginUrl
=
'
http://localhost:8000/
'
self
.
languagePluginUrl
=
'
{{DEPLOY}}
'
importScripts
(
'
./pyodide.js
'
)
var
onmessage
=
function
(
e
)
{
// eslint-disable-line no-unused-vars
...
...
test/conftest.py
View file @
00ba1848
...
...
@@ -143,6 +143,66 @@ class SeleniumWrapper:
catch (error) {{ console.log(error.stack); throw error; }}"""
return
self
.
driver
.
execute_script
(
catch
)
def
initWebWorker
(
self
):
url
=
f'http://
{
self
.
server_hostname
}
:
{
self
.
server_port
}
/webworker_dev.js'
self
.
run_js
(
f"""
window.done = false;
window.pyodideWorker = new Worker( '
{
url
}
' );
window.pyodideWorker.onerror = function(e) {{
window.output = e;
window.error = true;
window.done = true;
}};
window.pyodideWorker.onmessage = function(e) {{
if (e.data.results) {{
window.output = e.data.results;
window.error = false;
}} else {{
window.output = e.data.error;
window.error = true;
}}
window.done = true;
}};
"""
)
def
run_webworker
(
self
,
code
):
from
selenium.common.exceptions
import
TimeoutException
self
.
initWebWorker
()
if
isinstance
(
code
,
str
)
and
code
.
startswith
(
'
\
n
'
):
# we have a multiline string, fix indentation
code
=
textwrap
.
dedent
(
code
)
self
.
run_js
(
"""
var data = {{
python: {!r}
}};
window.pyodideWorker.postMessage(data);
"""
.
format
(
code
)
)
try
:
self
.
wait
.
until
(
PackageLoaded
())
except
TimeoutException
:
_display_driver_logs
(
self
.
browser
,
self
.
driver
)
print
(
self
.
logs
)
raise
TimeoutException
(
'run_webworker timed out'
)
return
self
.
run_js
(
"""
if (window.error) {
if (window.output instanceof Error) {
throw window.output;
} else {
throw new Error(String(window.output))
}
}
return window.output;
"""
)
def
load_package
(
self
,
packages
):
self
.
run_js
(
'window.done = false
\
n
'
+
...
...
test/test_webworker.py
0 → 100644
View file @
00ba1848
def
test_runwebworker
(
selenium_standalone
):
output
=
selenium_standalone
.
run_webworker
(
"""
import numpy as np
x = np.zeros(5)
str(x)
"""
)
assert
output
==
'[0. 0. 0. 0. 0.]'
def
test_runwebworker_different_package_name
(
selenium_standalone
):
output
=
selenium_standalone
.
run_webworker
(
"""
import dateutil
dateutil.__version__
"""
)
assert
isinstance
(
output
,
str
)
def
test_runwebworker_no_imports
(
selenium_standalone
):
output
=
selenium_standalone
.
run_webworker
(
"""
42
"""
)
assert
output
==
42
def
test_runwebworker_missing_import
(
selenium_standalone
):
try
:
selenium_standalone
.
run_webworker
(
"""
import foo
"""
)
except
selenium_standalone
.
JavascriptException
as
e
:
assert
"ModuleNotFoundError"
in
str
(
e
)
else
:
assert
False
def
test_runwebworker_exception
(
selenium_standalone
):
try
:
selenium_standalone
.
run_webworker
(
"""
42 / 0
"""
)
except
selenium_standalone
.
JavascriptException
as
e
:
assert
"ZeroDivisionError"
in
str
(
e
)
else
:
assert
False
def
test_runwebworker_exception_after_import
(
selenium_standalone
):
try
:
selenium_standalone
.
run_webworker
(
"""
import numpy as np
x = np.empty(5)
42 / 0
"""
)
except
selenium_standalone
.
JavascriptException
as
e
:
assert
"ZeroDivisionError"
in
str
(
e
)
else
:
assert
False
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment