mirror of https://github.com/pyodide/pyodide.git
80 lines
2.3 KiB
Python
80 lines
2.3 KiB
Python
from typing import Dict
|
|
import random
|
|
|
|
import pytest
|
|
|
|
|
|
def generate_largish_json(n_rows: int = 91746) -> Dict:
|
|
# with n_rows = 91746, the output JSON size will be ~15 MB/10k rows
|
|
|
|
# Note: we don't fix the random seed here, but the actual values
|
|
# shouldn't matter
|
|
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)),
|
|
]
|
|
data = {}
|
|
for name, generator in columns:
|
|
data[name] = [generator() for _ in range(n_rows)]
|
|
return data
|
|
|
|
|
|
def test_pandas(selenium, request):
|
|
if selenium.browser == "chrome":
|
|
request.applymarker(pytest.mark.xfail(run=False, reason="chrome not supported"))
|
|
selenium.load_package("pandas")
|
|
assert len(selenium.run("import pandas\ndir(pandas)")) == 142
|
|
|
|
|
|
def test_extra_import(selenium, request):
|
|
if selenium.browser == "chrome":
|
|
request.applymarker(pytest.mark.xfail(run=False, reason="chrome not supported"))
|
|
|
|
selenium.load_package("pandas")
|
|
selenium.run("from pandas import Series, DataFrame, Panel")
|
|
|
|
|
|
def test_load_largish_file(selenium_standalone, request, httpserver):
|
|
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")
|
|
|
|
n_rows = 91746
|
|
|
|
data = generate_largish_json(n_rows)
|
|
|
|
httpserver.expect_request("/data").respond_with_json(
|
|
data, headers={"Access-Control-Allow-Origin": "*"}
|
|
)
|
|
request_url = httpserver.url_for("/data")
|
|
|
|
selenium.run(
|
|
f"""
|
|
import pyodide
|
|
import matplotlib.pyplot as plt
|
|
import pandas as pd
|
|
|
|
df = pd.read_json(pyodide.open_url('{request_url}'))
|
|
assert df.shape == ({n_rows}, 8)
|
|
"""
|
|
)
|