mirror of https://github.com/pyodide/pyodide.git
Add test
This commit is contained in:
parent
bf68705eb7
commit
65817abc7d
7
Makefile
7
Makefile
|
@ -21,7 +21,7 @@ LDFLAGS=\
|
||||||
-s MODULARIZE=1 \
|
-s MODULARIZE=1 \
|
||||||
$(CPYTHONROOT)/installs/python-$(PYVERSION)/lib/libpython$(PYMINOR).a \
|
$(CPYTHONROOT)/installs/python-$(PYVERSION)/lib/libpython$(PYMINOR).a \
|
||||||
-s "BINARYEN_METHOD='native-wasm'" \
|
-s "BINARYEN_METHOD='native-wasm'" \
|
||||||
-s TOTAL_MEMORY=536870912 \
|
-s TOTAL_MEMORY=1073741824 \
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
-s MAIN_MODULE=1 \
|
-s MAIN_MODULE=1 \
|
||||||
-s EMULATED_FUNCTION_POINTERS=1 \
|
-s EMULATED_FUNCTION_POINTERS=1 \
|
||||||
|
@ -51,7 +51,6 @@ all: build/pyodide.asm.js \
|
||||||
build/renderedhtml.css \
|
build/renderedhtml.css \
|
||||||
build/test.data \
|
build/test.data \
|
||||||
build/packages.json \
|
build/packages.json \
|
||||||
build/test_data.txt \
|
|
||||||
build/test.html
|
build/test.html
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,10 +107,6 @@ test: all
|
||||||
pytest test/ -v
|
pytest test/ -v
|
||||||
|
|
||||||
|
|
||||||
build/test_data.txt: test/data.txt
|
|
||||||
cp test/data.txt build/test_data.txt
|
|
||||||
|
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
flake8 src
|
flake8 src
|
||||||
flake8 test
|
flake8 test
|
||||||
|
|
|
@ -214,16 +214,29 @@ def run_web_server(q):
|
||||||
print("Running webserver...")
|
print("Running webserver...")
|
||||||
|
|
||||||
os.chdir(BUILD_PATH)
|
os.chdir(BUILD_PATH)
|
||||||
Handler = http.server.SimpleHTTPRequestHandler
|
|
||||||
Handler.extensions_map['.wasm'] = 'application/wasm'
|
|
||||||
|
|
||||||
def dummy_log(*args, **kwargs):
|
class Handler(http.server.CGIHTTPRequestHandler):
|
||||||
|
def translate_path(self, path):
|
||||||
|
if path.startswith('/test/'):
|
||||||
|
return TEST_PATH / path[6:]
|
||||||
|
return super(Handler, self).translate_path(path)
|
||||||
|
|
||||||
|
def is_cgi(self):
|
||||||
|
if self.path.startswith('/test/') and self.path.endswith('.cgi'):
|
||||||
|
self.cgi_info = '/test', self.path[6:]
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def log_message(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
Handler.log_message = dummy_log
|
|
||||||
|
Handler.extensions_map['.wasm'] = 'application/wasm'
|
||||||
|
|
||||||
with socketserver.TCPServer(("", 0), Handler) as httpd:
|
with socketserver.TCPServer(("", 0), Handler) as httpd:
|
||||||
host, port = httpd.server_address
|
host, port = httpd.server_address
|
||||||
print("serving at port", port)
|
print("serving at port", port)
|
||||||
|
httpd.server_name = 'test-server'
|
||||||
|
httpd.server_port = port
|
||||||
q.put(port)
|
q.put(port)
|
||||||
|
|
||||||
def service_actions():
|
def service_actions():
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
print("Content-Type: text/text")
|
||||||
|
print()
|
||||||
|
print("HELLO")
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import json
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
|
random.seed(0)
|
||||||
|
|
||||||
|
print("Content-Type: application/json")
|
||||||
|
print()
|
||||||
|
|
||||||
|
columns = [
|
||||||
|
('column0', lambda: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'),
|
||||||
|
('column1', lambda: random.choice([
|
||||||
|
'notification-interval-longer', 'notification-interval-short', 'control'])),
|
||||||
|
('column2', lambda: random.choice([True, False])),
|
||||||
|
('column3', lambda: random.randint(0, 4)),
|
||||||
|
('column4', lambda: random.randint(0, 4)),
|
||||||
|
('column5', lambda: random.randint(0, 4)),
|
||||||
|
('column6', lambda: random.randint(0, 4)),
|
||||||
|
('column7', lambda: random.randint(0, 4))
|
||||||
|
]
|
||||||
|
N_ROWS = 91746
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
for name, generator in columns:
|
||||||
|
column = {}
|
||||||
|
for i in range(N_ROWS):
|
||||||
|
column[str(i)] = generator()
|
||||||
|
data[name] = column
|
||||||
|
|
||||||
|
json.dump(data, sys.stdout)
|
|
@ -16,3 +16,22 @@ def test_extra_import(selenium, request):
|
||||||
|
|
||||||
selenium.load_package("pandas")
|
selenium.load_package("pandas")
|
||||||
selenium.run("from pandas import Series, DataFrame, Panel")
|
selenium.run("from pandas import Series, DataFrame, Panel")
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_largish_file(selenium_standalone, request):
|
||||||
|
selenium = selenium_standalone
|
||||||
|
|
||||||
|
if selenium.browser == 'chrome':
|
||||||
|
request.applymarker(pytest.mark.xfail(
|
||||||
|
run=False, reason='chrome not supported'))
|
||||||
|
|
||||||
|
selenium.load_package("pandas")
|
||||||
|
selenium.load_package("matplotlib")
|
||||||
|
|
||||||
|
selenium.run("""
|
||||||
|
import pyodide
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
pd.read_json(pyodide.open_url('test/largish.json.cgi'))
|
||||||
|
""")
|
||||||
|
|
|
@ -317,7 +317,15 @@ def test_open_url(selenium):
|
||||||
assert selenium.run(
|
assert selenium.run(
|
||||||
"""
|
"""
|
||||||
import pyodide
|
import pyodide
|
||||||
pyodide.open_url('test_data.txt').read()
|
pyodide.open_url('test/data.txt').read()
|
||||||
|
""") == 'HELLO\n'
|
||||||
|
|
||||||
|
|
||||||
|
def test_open_url_cgi(selenium):
|
||||||
|
assert selenium.run(
|
||||||
|
"""
|
||||||
|
import pyodide
|
||||||
|
pyodide.open_url('test/data.cgi').read()
|
||||||
""") == 'HELLO\n'
|
""") == 'HELLO\n'
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue