2018-10-11 10:03:32 +00:00
|
|
|
from pathlib import Path
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
from textwrap import dedent
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2018-10-24 11:24:39 +00:00
|
|
|
sys.path.append(str(Path(__file__).parents[2]))
|
2018-10-11 10:03:32 +00:00
|
|
|
|
|
|
|
from pyodide_build.common import HOSTPYTHON # noqa: E402
|
|
|
|
|
|
|
|
|
2018-10-15 14:36:06 +00:00
|
|
|
def test_scipy_import(selenium_standalone, request):
|
2018-10-11 10:03:32 +00:00
|
|
|
from selenium.common.exceptions import JavascriptException
|
|
|
|
selenium = selenium_standalone
|
2018-10-15 14:36:06 +00:00
|
|
|
|
|
|
|
if selenium.browser == 'chrome':
|
|
|
|
request.applymarker(pytest.mark.xfail(
|
|
|
|
run=False, reason='chrome not supported'))
|
2018-10-11 10:03:32 +00:00
|
|
|
selenium.load_package("scipy")
|
|
|
|
selenium.run("""
|
|
|
|
import scipy
|
|
|
|
""")
|
|
|
|
|
|
|
|
# supported modules
|
2018-10-18 15:19:20 +00:00
|
|
|
for module in ['cluster', 'constants', 'fftpack', 'odr', 'sparse',
|
2018-10-25 11:37:13 +00:00
|
|
|
'interpolate', 'integrate',
|
2018-10-18 15:19:20 +00:00
|
|
|
'linalg',
|
|
|
|
'misc', 'ndimage', 'spatial', 'special'
|
2018-10-24 11:24:39 +00:00
|
|
|
]:
|
2018-10-11 10:03:32 +00:00
|
|
|
selenium.run(f"import scipy.{module}")
|
|
|
|
|
|
|
|
# not yet built modules
|
2018-10-25 11:37:13 +00:00
|
|
|
for module in []:
|
2018-10-11 10:03:32 +00:00
|
|
|
print(module)
|
|
|
|
with pytest.raises(JavascriptException) as err:
|
|
|
|
selenium.run(f"import scipy.{module}")
|
|
|
|
assert ('ModuleNotFoundError' in str(err.value)
|
|
|
|
or 'ImportError' in str(err.value))
|
|
|
|
|
|
|
|
print(selenium.logs)
|
|
|
|
|
|
|
|
|
|
|
|
def test_built_so(selenium_standalone):
|
|
|
|
selenium = selenium_standalone
|
|
|
|
selenium.load_package("scipy")
|
|
|
|
|
|
|
|
cmd = dedent(r"""
|
|
|
|
import scipy as sp
|
|
|
|
import os
|
|
|
|
|
|
|
|
base_dir = os.path.dirname(sp.__file__)
|
|
|
|
|
|
|
|
out = []
|
|
|
|
for (dirpath, dirnames, filenames) in os.walk(base_dir):
|
|
|
|
for path in filenames:
|
|
|
|
if path.endswith('.so'):
|
|
|
|
rel_path = os.path.relpath(dirpath, base_dir)
|
|
|
|
out.append(os.path.join(rel_path, path))
|
|
|
|
print("\n".join(out))
|
|
|
|
out
|
|
|
|
""")
|
|
|
|
|
|
|
|
out = subprocess.check_output(
|
|
|
|
[HOSTPYTHON / 'bin' / 'python3', '-c', cmd])
|
|
|
|
modules_host = out.decode('utf-8').split('\n')
|
|
|
|
|
|
|
|
def _get_modules_name(modules):
|
|
|
|
return set([path.split('.')[0] for path in modules if path])
|
|
|
|
|
|
|
|
modules_host = _get_modules_name(modules_host)
|
|
|
|
|
|
|
|
modules_target = selenium.run(cmd)
|
|
|
|
modules_target = _get_modules_name(modules_target)
|
|
|
|
|
|
|
|
print(f'Included modules: {len(modules_target)}')
|
|
|
|
print(f' {modules_target} ')
|
|
|
|
print(f'\nMissing modules: {len(modules_host.difference(modules_target))}')
|
|
|
|
print(f' {modules_host.difference(modules_target)}')
|