forked from phorward/pyodide
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_common.py
91 lines (75 loc) · 2.69 KB
/
test_common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pytest
import os
from pathlib import Path
from pyodide_build.common import _parse_package_subset
from pyodide_build.io import parse_package_config
PKG_DIR = Path(__file__).parent
def registered_packages():
"""Returns a list of registered package names"""
packages = []
for name in os.listdir(PKG_DIR):
if (PKG_DIR / name).is_dir() and (PKG_DIR / name / "meta.yaml").exists():
packages.append(name)
return packages
def registered_packages_meta():
"""Returns a dictionary with the contents of `meta.yaml`
for each registered package
"""
packages = registered_packages
return {
name: parse_package_config(PKG_DIR / name / "meta.yaml") for name in packages
}
UNSUPPORTED_PACKAGES: dict = {
"chrome": ["scikit-image", "statsmodels"],
"firefox": [],
"node": ["scikit-image", "statsmodels"],
}
@pytest.mark.parametrize("name", registered_packages())
def test_parse_package(name):
# check that we can parse the meta.yaml
meta = parse_package_config(PKG_DIR / name / "meta.yaml")
skip_host = meta.get("build", {}).get("skip_host", True)
if name == "numpy":
assert skip_host is False
elif name == "pandas":
assert skip_host is True
@pytest.mark.skip_refcount_check
@pytest.mark.driver_timeout(40)
@pytest.mark.parametrize("name", registered_packages())
def test_import(name, selenium_standalone):
# check that we can parse the meta.yaml
meta = parse_package_config(PKG_DIR / name / "meta.yaml")
if name in UNSUPPORTED_PACKAGES[selenium_standalone.browser]:
pytest.xfail(
"{} fails to load and is not supported on {}.".format(
name, selenium_standalone.browser
)
)
built_packages = _parse_package_subset(os.environ.get("PYODIDE_PACKAGES"))
# only a subset of packages were built
if built_packages is not None and name not in built_packages:
pytest.skip(f"{name} was skipped due to PYODIDE_PACKAGES")
selenium_standalone.run("import glob, os")
baseline_pyc = selenium_standalone.run(
"""
len(list(glob.glob(
'/lib/python3.9/site-packages/**/*.pyc',
recursive=True)
))
"""
)
for import_name in meta.get("test", {}).get("imports", []):
selenium_standalone.run_async("import %s" % import_name)
# Make sure that even after importing, there are no additional .pyc
# files
assert (
selenium_standalone.run(
"""
len(list(glob.glob(
'/lib/python3.9/site-packages/**/*.pyc',
recursive=True)
))
"""
)
== baseline_pyc
)