mirror of https://github.com/pyodide/pyodide.git
Unit tests for loading packages from user defined URLs
This commit is contained in:
parent
b2156caa94
commit
068906bbf7
|
@ -5,7 +5,7 @@
|
|||
// Regexp for validating package name and URI
|
||||
var package_name_regexp = '[a-zA-Z0-9_\-]+'
|
||||
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 + '$');
|
||||
|
||||
|
||||
|
@ -41,7 +41,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
|
|||
let queue = new Array(names);
|
||||
let toLoad = new Array();
|
||||
while (queue.length) {
|
||||
var package_uri = queue.pop();
|
||||
let package_uri = queue.pop();
|
||||
|
||||
const package = _uri_to_package_name(package_uri);
|
||||
|
||||
|
@ -57,7 +57,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
|
|||
if (package in loadedPackages) {
|
||||
if (package_uri != loadedPackages[package]) {
|
||||
console.log(`Error: URI mismatch, attempting to load package ` +
|
||||
`${package} from ${package_uri} while is already ` +
|
||||
`${package} from ${package_uri} while it is already ` +
|
||||
`loaded from ${loadedPackages[package]}!`);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
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
|
Loading…
Reference in New Issue