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
068906bb
Commit
068906bb
authored
Aug 22, 2018
by
Roman Yurchak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit tests for loading packages from user defined URLs
parent
b2156caa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
3 deletions
+53
-3
src/pyodide.js
src/pyodide.js
+3
-3
test/test_package_loading.py
test/test_package_loading.py
+50
-0
No files found.
src/pyodide.js
View file @
068906bb
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
// Regexp for validating package name and URI
// Regexp for validating package name and URI
var
package_name_regexp
=
'
[a-zA-Z0-9_
\
-]+
'
var
package_name_regexp
=
'
[a-zA-Z0-9_
\
-]+
'
var
package_uri_regexp
=
new
RegExp
(
var
package_uri_regexp
=
new
RegExp
(
'
^
(?:https?|file)
://.*?(
'
+
package_name_regexp
+
'
).js$
'
);
'
^
https?
://.*?(
'
+
package_name_regexp
+
'
).js$
'
);
var
package_name_regexp
=
new
RegExp
(
'
^
'
+
package_name_regexp
+
'
$
'
);
var
package_name_regexp
=
new
RegExp
(
'
^
'
+
package_name_regexp
+
'
$
'
);
...
@@ -41,7 +41,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -41,7 +41,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
let
queue
=
new
Array
(
names
);
let
queue
=
new
Array
(
names
);
let
toLoad
=
new
Array
();
let
toLoad
=
new
Array
();
while
(
queue
.
length
)
{
while
(
queue
.
length
)
{
var
package_uri
=
queue
.
pop
();
let
package_uri
=
queue
.
pop
();
const
package
=
_uri_to_package_name
(
package_uri
);
const
package
=
_uri_to_package_name
(
package_uri
);
...
@@ -57,7 +57,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -57,7 +57,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
if
(
package
in
loadedPackages
)
{
if
(
package
in
loadedPackages
)
{
if
(
package_uri
!=
loadedPackages
[
package
])
{
if
(
package_uri
!=
loadedPackages
[
package
])
{
console
.
log
(
`Error: URI mismatch, attempting to load package `
+
console
.
log
(
`Error: URI mismatch, attempting to load package `
+
`
${
package
}
from
${
package_uri
}
while is already `
+
`
${
package
}
from
${
package_uri
}
while i
t i
s already `
+
`loaded from
${
loadedPackages
[
package
]}
!`
);
`loaded from
${
loadedPackages
[
package
]}
!`
);
}
}
}
else
{
}
else
{
...
...
test/test_package_loading.py
0 → 100644
View file @
068906bb
import
os
from
pathlib
import
Path
import
time
from
http.server
import
HTTPServer
,
SimpleHTTPRequestHandler
import
threading
import
pytest
@
pytest
.
fixture
def
static_web_server
():
# serve artefacts from a different port
build_dir
=
Path
(
__file__
).
parent
.
parent
/
'build'
os
.
chdir
(
build_dir
)
try
:
url
,
port
=
(
'127.0.0.1'
,
8888
)
server
=
HTTPServer
((
url
,
port
),
SimpleHTTPRequestHandler
)
thread
=
threading
.
Thread
(
target
=
server
.
serve_forever
)
thread
.
start
()
yield
url
,
port
finally
:
server
.
shutdown
()
def
test_load_from_url
(
selenium_standalone
,
static_web_server
):
url
,
port
=
static_web_server
selenium_standalone
.
load_package
(
f"http://
{
url
}
:
{
port
}
/pyparsing.js"
)
assert
"Invalid package name or URI"
not
in
selenium_standalone
.
logs
selenium_standalone
.
run
(
"from pyparsing import Word, alphas"
)
selenium_standalone
.
run
(
"Word(alphas).parseString('hello')"
)
def
test_uri_mismatch
(
selenium_standalone
):
selenium_standalone
.
load_package
(
'pyparsing'
)
selenium_standalone
.
load_package
(
'http://some_url/pyparsing.js'
)
assert
"Invalid package name or URI"
not
in
selenium_standalone
.
logs
assert
(
"URI mismatch, attempting "
"to load package pyparsing"
)
in
selenium_standalone
.
logs
def
test_invalid_package_name
(
selenium
):
selenium
.
load_package
(
'wrong name+$'
)
assert
"Invalid package name or URI"
in
selenium
.
logs
selenium
.
clean_logs
()
selenium
.
load_package
(
'tcp://some_url'
)
assert
"Invalid package name or URI"
in
selenium
.
logs
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