Skip to content

Commit

Permalink
TST: Skip irrelevant tests on WASM platforms
Browse files Browse the repository at this point in the history
This commit performs the following:

1. Skip `RuntimeWarnings` on exotic `np.where()` tests on WASM because of the lack of floating point exception support
2. Skip NumPy config tests that use subprocess module on WASM
3. Ignore threaded tests for PRNGs on WASM
4. Remove numpygh-5411 Cython `AttributeError` check. See cython/cython#5411, which is now resolved for Cython>3, and we are at Cython>=3.0.6.
4. For f2py, check compilers only if not on WASM
5. Skip pickle serialisation tests for `stringdtype` on WASM runtimes
  • Loading branch information
agriyakhetarpal committed Feb 27, 2024
1 parent 3117d02 commit 75ffbfa
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
3 changes: 2 additions & 1 deletion numpy/_core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from numpy.testing import (
assert_, assert_raises, assert_warns, assert_equal, assert_almost_equal,
assert_array_equal, assert_raises_regex, assert_array_almost_equal,
assert_allclose, IS_PYPY, IS_PYSTON, HAS_REFCOUNT, assert_array_less,
assert_allclose, IS_PYPY, IS_WASM, IS_PYSTON, HAS_REFCOUNT, assert_array_less,
runstring, temppath, suppress_warnings, break_cycles, _SUPPORTS_SVE,
assert_array_compare,
)
Expand Down Expand Up @@ -8837,6 +8837,7 @@ def test_basic(self):
assert_equal(np.where(c[::-3], d[::-3], e[::-3]), r[::-3])
assert_equal(np.where(c[1::-3], d[1::-3], e[1::-3]), r[1::-3])

@pytest.mark.skipif(IS_WASM, reason="no wasm fp exception support")
def test_exotic(self):
# object
assert_array_equal(np.where(True, None, None), np.array(None))
Expand Down
5 changes: 3 additions & 2 deletions numpy/_core/tests/test_stringdtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from numpy.dtypes import StringDType
from numpy._core.tests._natype import pd_NA
from numpy.testing import assert_array_equal
from numpy.testing import assert_array_equal, IS_WASM


@pytest.fixture
Expand Down Expand Up @@ -349,7 +349,7 @@ def _pickle_load(filename):

return res


@pytest.mark.skipif(IS_WASM, reason="no threading support in wasm")
def test_pickle(dtype, string_list):
arr = np.array(string_list, dtype=dtype)

Expand Down Expand Up @@ -864,6 +864,7 @@ def test_growing_strings(dtype):
assert_array_equal(arr, uarr)


@pytest.mark.skipif(IS_WASM, reason="no threading support in wasm")
def test_threaded_access_and_mutation(dtype, random_string_list):
# this test uses an RNG and may crash or cause deadlocks if there is a
# threading bug
Expand Down
10 changes: 0 additions & 10 deletions numpy/_core/tests/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
from numpy.testing._private.utils import requires_memory


import cython
from packaging.version import parse, Version

# Remove this when cython fixes https://github.com/cython/cython/issues/5411
cython_version = parse(cython.__version__)
BUG_5411 = Version("3.0.0a7") <= cython_version <= Version("3.0.0b3")

UNARY_UFUNCS = [obj for obj in np._core.umath.__dict__.values()
if isinstance(obj, np.ufunc)]
UNARY_OBJECT_UFUNCS = [uf for uf in UNARY_UFUNCS if "O->O" in uf.types]
Expand Down Expand Up @@ -214,9 +207,6 @@ def test_pickle_withstring(self):
b"(S'numpy._core.umath'\np1\nS'cos'\np2\ntp3\nRp4\n.")
assert_(pickle.loads(astring) is np.cos)

@pytest.mark.skipif(BUG_5411,
reason=("cython raises a AttributeError where it should raise a "
"ModuleNotFoundError"))
@pytest.mark.skipif(IS_PYPY, reason="'is' check does not work on PyPy")
def test_pickle_name_is_qualname(self):
# This tests that a simplification of our ufunc pickle code will
Expand Down
8 changes: 8 additions & 0 deletions numpy/f2py/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from numpy.testing import IS_WASM
import pytest

if IS_WASM:
pytest.skip(
"WASM/Pyodide does not use or support Fortran",
allow_module_level=True
)
5 changes: 3 additions & 2 deletions numpy/f2py/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ def check_compilers(self):

self.compilers_checked = True

checker = CompilerChecker()
checker.check_compilers()
if not IS_WASM:
checker = CompilerChecker()
checker.check_compilers()

def has_c_compiler():
return checker.has_c
Expand Down
8 changes: 5 additions & 3 deletions numpy/tests/test_configtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pytest
import numpy as np

from numpy.testing import IS_WASM


is_editable = not bool(np.__path__)
numpy_in_sitepackages = sysconfig.get_path('platlib') in np.__file__
Expand All @@ -20,17 +22,17 @@ def check_numpyconfig(arg):
p.check_returncode()
return p.stdout.strip()


@pytest.mark.skipif(IS_WASM, reason="wasm interpreter cannot start subprocesses")
def test_configtool_version():
stdout = check_numpyconfig('--version')
assert stdout == np.__version__


@pytest.mark.skipif(IS_WASM, reason="wasm interpreter cannot start subprocesses")
def test_configtool_cflags():
stdout = check_numpyconfig('--cflags')
assert stdout.endswith(os.path.join('numpy', '_core', 'include'))


@pytest.mark.skipif(IS_WASM, reason="wasm interpreter cannot start subprocesses")
def test_configtool_pkgconfigdir():
stdout = check_numpyconfig('--pkgconfigdir')
assert stdout.endswith(os.path.join('numpy', '_core', 'lib', 'pkgconfig'))
Expand Down

0 comments on commit 75ffbfa

Please sign in to comment.