mirror of https://github.com/pyodide/pyodide.git
Re-use built-in web server
This commit is contained in:
parent
ff45a550a6
commit
5030eae5b7
|
@ -205,5 +205,10 @@ def run_web_server(q):
|
|||
httpd.serve_forever()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def web_server():
|
||||
return '127.0.0.1', PORT
|
||||
|
||||
|
||||
if multiprocessing.current_process().name == 'MainProcess':
|
||||
spawn_web_server()
|
||||
|
|
|
@ -1,30 +1,8 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
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, web_server):
|
||||
|
||||
|
||||
def test_load_from_url(selenium_standalone, static_web_server):
|
||||
|
||||
url, port = static_web_server
|
||||
url, port = web_server
|
||||
|
||||
selenium_standalone.load_package(f"http://{url}:{port}/pyparsing.js")
|
||||
assert "Invalid package name or URI" not in selenium_standalone.logs
|
||||
|
@ -32,6 +10,9 @@ def test_load_from_url(selenium_standalone, static_web_server):
|
|||
selenium_standalone.run("from pyparsing import Word, alphas")
|
||||
selenium_standalone.run("Word(alphas).parseString('hello')")
|
||||
|
||||
selenium_standalone.load_package(f"http://{url}:{port}/numpy.js")
|
||||
selenium_standalone.run("import numpy as np")
|
||||
|
||||
|
||||
def test_uri_mismatch(selenium_standalone):
|
||||
selenium_standalone.load_package('pyparsing')
|
||||
|
|
Loading…
Reference in New Issue