Skip to content

Commit

Permalink
test pyodide
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed May 26, 2022
1 parent 6ea48db commit 47ba142
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ jobs:
- run: pip install mpmath
- run: bin/test --force-colors --split=2/2

# -------------------- Test Pyodide on node ---------------------- #

test-pyodide:
needs: code-quality

runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
- run: python3 setup.py bdist_wheel
- run: python3 -m http.server &
- run: node bin/test_pyodide.mjs 2>/dev/null # ignore node exception

# -------------------- Optional dependency tests ----------------- #

optional-dependencies:
Expand Down
13 changes: 13 additions & 0 deletions bin/test_pyodide.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pyodide_pkg from 'pyodide/pyodide.js'

const pyodide = await pyodide_pkg.loadPyodide()
await pyodide.loadPackage([
'https://files.pythonhosted.org/packages/d4/cf/3965bddbb4f1a61c49aacae0e78fd1fe36b5dc36c797b31f30cf07dcbbb7/mpmath-1.2.1-py3-none-any.whl', // latest mpmath on PyPI
'https://cdn.jsdelivr.net/pyodide/v0.20.0/full/numpy-1.22.3-cp310-cp310-emscripten_wasm32.whl', // latest numpy built by pyodide
'http://localhost:8000/dist/sympy-1.11.dev0-py3-none-any.whl' // git version sympy
])
pyodide.runPython(`
import sympy
if not sympy.test(subprocess=False):
exit(1)
`)
6 changes: 6 additions & 0 deletions sympy/matrices/tests/test_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
from sympy.assumptions import Q
from sympy.tensor.array import Array
from sympy.matrices.expressions import MatPow
from sympy.external import import_module

from sympy.abc import a, b, c, d, x, y, z, t

pyodide_js = import_module('pyodide_js')

# don't re-order this list
classes = (Matrix, SparseMatrix, ImmutableMatrix, ImmutableSparseMatrix)

Expand Down Expand Up @@ -2984,6 +2987,9 @@ def test_func():


def test_issue_19809():
if pyodide_js:
skip("can't run on pyodide")

def f():
assert _dotprodsimp_state.state == None
m = Matrix([[1]])
Expand Down
2 changes: 1 addition & 1 deletion sympy/testing/tests/test_code_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def test_this_file(fname, test_file):
"%(sep)sutilities%(sep)sbenchmarking.py" % sepd,
}
check_files(top_level_files, test)
check_directory_tree(BIN_PATH, test, {"~", ".pyc", ".sh"}, "*")
check_directory_tree(BIN_PATH, test, {"~", ".pyc", ".sh", ".mjs"}, "*")
check_directory_tree(SYMPY_PATH, test, exclude)
check_directory_tree(EXAMPLES_PATH, test, exclude)

Expand Down
7 changes: 6 additions & 1 deletion sympy/utilities/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import os

from sympy.core.singleton import S
from sympy.testing.pytest import raises, warns_deprecated_sympy
from sympy.testing.pytest import raises, warns_deprecated_sympy, skip
from sympy.utilities.misc import (translate, replace, ordinal, rawlines,
strlines, as_int, find_executable)
from sympy.external import import_module

pyodide_js = import_module('pyodide_js')


def test_translate():
Expand Down Expand Up @@ -112,6 +115,8 @@ def test_translate_args():


def test_debug_output():
if pyodide_js:
skip("can't run on pyodide")
env = os.environ.copy()
env['SYMPY_DEBUG'] = 'True'
cmd = 'from sympy import *; x = Symbol("x"); print(integrate((1-cos(x))/x, x))'
Expand Down

0 comments on commit 47ba142

Please sign in to comment.