2018-08-03 11:57:51 +00:00
|
|
|
import pytest
|
|
|
|
import os
|
|
|
|
from pathlib import Path
|
2018-09-20 17:37:32 +00:00
|
|
|
from pyodide_build.common import parse_package
|
2018-08-03 11:57:51 +00:00
|
|
|
|
|
|
|
BASE_DIR = Path(__file__).parent.parent
|
|
|
|
PKG_DIR = BASE_DIR / 'packages'
|
|
|
|
|
|
|
|
|
|
|
|
def registered_packages():
|
2018-08-03 12:43:40 +00:00
|
|
|
"""Returns a list of registred package names"""
|
2018-08-03 11:57:51 +00:00
|
|
|
packages = [name for name in os.listdir(PKG_DIR)
|
|
|
|
if (PKG_DIR / name).is_dir()]
|
|
|
|
return packages
|
|
|
|
|
|
|
|
|
2018-08-03 12:43:40 +00:00
|
|
|
def registered_packages_meta():
|
|
|
|
"""Returns a dictionary with the contents of `meta.yaml`
|
|
|
|
for each registed package
|
|
|
|
"""
|
|
|
|
packages = registered_packages
|
2018-09-20 17:37:32 +00:00
|
|
|
return {name: parse_package(PKG_DIR / name / 'meta.yaml')
|
2018-08-03 12:43:40 +00:00
|
|
|
for name in packages}
|
|
|
|
|
|
|
|
|
2018-10-22 10:51:03 +00:00
|
|
|
UNSUPPORTED_PACKAGES = {'chrome': ['pandas', 'scipy', 'scikit-learn'],
|
2018-08-20 15:09:23 +00:00
|
|
|
'firefox': []}
|
2018-08-16 09:34:42 +00:00
|
|
|
|
|
|
|
|
2018-10-29 11:52:13 +00:00
|
|
|
@pytest.mark.parametrize('name', registered_packages())
|
|
|
|
def test_parse_package(name):
|
|
|
|
# check that we can parse the meta.yaml
|
|
|
|
meta = parse_package(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
|
|
|
|
|
|
|
|
|
2018-08-03 11:57:51 +00:00
|
|
|
@pytest.mark.parametrize('name', registered_packages())
|
2018-08-20 17:02:12 +00:00
|
|
|
def test_import(name, selenium_standalone):
|
2018-08-03 11:57:51 +00:00
|
|
|
# check that we can parse the meta.yaml
|
2018-09-20 17:37:32 +00:00
|
|
|
meta = parse_package(PKG_DIR / name / 'meta.yaml')
|
2018-08-03 11:57:51 +00:00
|
|
|
|
2018-08-20 15:09:23 +00:00
|
|
|
if name in UNSUPPORTED_PACKAGES[selenium_standalone.browser]:
|
2018-08-16 09:34:42 +00:00
|
|
|
pytest.xfail(
|
2018-08-20 15:09:23 +00:00
|
|
|
'{} fails to load and is not supported on {}.'
|
|
|
|
.format(name, selenium_standalone.browser))
|
2018-08-16 09:34:42 +00:00
|
|
|
|
2018-11-08 20:03:30 +00:00
|
|
|
selenium_standalone.run("import glob, os")
|
|
|
|
|
|
|
|
baseline_pyc = selenium_standalone.run(
|
|
|
|
"""
|
|
|
|
len(list(glob.glob(
|
|
|
|
'/lib/python3.7/site-packages/**/*.pyc',
|
|
|
|
recursive=True)
|
|
|
|
))
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
selenium_standalone.load_package(name)
|
|
|
|
|
|
|
|
# Make sure there are no additional .pyc file
|
|
|
|
assert selenium_standalone.run(
|
|
|
|
"""
|
|
|
|
len(list(glob.glob(
|
|
|
|
'/lib/python3.7/site-packages/**/*.pyc',
|
|
|
|
recursive=True)
|
|
|
|
))
|
|
|
|
"""
|
|
|
|
) == baseline_pyc
|
|
|
|
|
2018-10-31 14:06:08 +00:00
|
|
|
loaded_packages = []
|
2018-08-03 12:43:40 +00:00
|
|
|
for import_name in meta.get('test', {}).get('imports', []):
|
2018-10-31 14:06:08 +00:00
|
|
|
|
|
|
|
if name not in loaded_packages:
|
|
|
|
selenium_standalone.load_package(name)
|
|
|
|
loaded_packages.append(name)
|
2018-07-18 13:26:18 +00:00
|
|
|
try:
|
|
|
|
selenium_standalone.run('import %s' % import_name)
|
2018-10-31 14:06:08 +00:00
|
|
|
except Exception:
|
2018-07-18 13:26:18 +00:00
|
|
|
print(selenium_standalone.logs)
|
2018-10-22 10:53:42 +00:00
|
|
|
raise
|
2018-11-08 20:03:30 +00:00
|
|
|
|
2018-11-08 20:25:21 +00:00
|
|
|
# Make sure that even after importing, there are no additional .pyc
|
|
|
|
# files
|
2018-11-08 20:03:30 +00:00
|
|
|
assert selenium_standalone.run(
|
|
|
|
"""
|
|
|
|
len(list(glob.glob(
|
|
|
|
'/lib/python3.7/site-packages/**/*.pyc',
|
|
|
|
recursive=True)
|
|
|
|
))
|
|
|
|
"""
|
|
|
|
) == baseline_pyc
|