pyodide/packages/test_packages_common.py

99 lines
2.8 KiB
Python
Raw Normal View History

import functools
2022-02-21 22:27:03 +00:00
import os
import pytest
from conftest import ROOT_PATH, package_is_built
2021-01-11 07:59:22 +00:00
from pyodide_build.io import parse_package_config
2018-08-03 11:57:51 +00:00
PKG_DIR = ROOT_PATH / "packages"
2018-08-03 11:57:51 +00:00
@functools.cache
2022-02-20 22:13:37 +00:00
def registered_packages() -> list[str]:
"""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)
2018-08-03 11:57:51 +00:00
return packages
2022-02-20 22:13:37 +00:00
UNSUPPORTED_PACKAGES: dict[str, list[str]] = {
"chrome": [],
"firefox": [],
"node": ["cmyt", "yt", "galpy"],
}
2022-04-09 01:42:45 +00:00
if "CI" in os.environ:
UNSUPPORTED_PACKAGES["chrome"].extend(["statsmodels"])
@pytest.mark.parametrize("name", registered_packages())
def test_parse_package(name):
# check that we can parse the meta.yaml
2021-01-11 07:59:22 +00:00
meta = parse_package_config(PKG_DIR / name / "meta.yaml")
sharedlibrary = meta.get("build", {}).get("sharedlibrary", False)
if name == "sharedlib-test":
assert sharedlibrary is True
elif name == "sharedlib-test-py":
assert sharedlibrary is False
@pytest.mark.skip_refcount_check
2022-04-20 07:50:33 +00:00
@pytest.mark.driver_timeout(60)
@pytest.mark.parametrize("name", registered_packages())
def test_import(name, selenium_standalone):
if not package_is_built(name):
raise AssertionError(
"Implementation error. Test for an unbuilt package "
"should have been skipped in selenium_standalone fixture"
)
2021-01-11 07:59:22 +00:00
meta = parse_package_config(PKG_DIR / name / "meta.yaml")
2018-08-03 11:57:51 +00:00
if name in UNSUPPORTED_PACKAGES[selenium_standalone.browser]:
pytest.xfail(
"{} fails to load and is not supported on {}.".format(
name, selenium_standalone.browser
)
)
selenium_standalone.run("import glob, os, site")
2018-11-08 20:03:30 +00:00
baseline_pyc = selenium_standalone.run(
"""
2018-11-08 20:03:30 +00:00
len(list(glob.glob(
site.getsitepackages()[0] + '/**/*.pyc',
2018-11-08 20:03:30 +00:00
recursive=True)
))
"""
)
for import_name in meta.get("test", {}).get("imports", []):
selenium_standalone.run_async("import %s" % import_name)
2018-11-08 20:25:21 +00:00
# Make sure that even after importing, there are no additional .pyc
# files
assert (
selenium_standalone.run(
"""
len(list(glob.glob(
site.getsitepackages()[0] + '/**/*.pyc',
recursive=True)
))
"""
)
== baseline_pyc
)
# Make sure no exe files were loaded!
assert (
selenium_standalone.run(
"""
len(list(glob.glob(
site.getsitepackages()[0] + '/**/*.exe',
recursive=True)
))
"""
)
== 0
)