diff options
Diffstat (limited to 'numpy/tests')
| -rw-r--r-- | numpy/tests/test_numpy_config.py | 44 | ||||
| -rw-r--r-- | numpy/tests/test_public_api.py | 34 | ||||
| -rw-r--r-- | numpy/tests/test_reloading.py | 10 | ||||
| -rw-r--r-- | numpy/tests/test_scripts.py | 3 |
4 files changed, 84 insertions, 7 deletions
diff --git a/numpy/tests/test_numpy_config.py b/numpy/tests/test_numpy_config.py new file mode 100644 index 000000000..82c1ad70b --- /dev/null +++ b/numpy/tests/test_numpy_config.py @@ -0,0 +1,44 @@ +""" +Check the numpy config is valid. +""" +import numpy as np +import pytest +from unittest.mock import Mock, patch + +pytestmark = pytest.mark.skipif( + not hasattr(np.__config__, "_built_with_meson"), + reason="Requires Meson builds", +) + + +class TestNumPyConfigs: + REQUIRED_CONFIG_KEYS = [ + "Compilers", + "Machine Information", + "Python Information", + ] + + @patch("numpy.__config__._check_pyyaml") + def test_pyyaml_not_found(self, mock_yaml_importer): + mock_yaml_importer.side_effect = ModuleNotFoundError() + with pytest.warns(UserWarning): + np.show_config() + + def test_dict_mode(self): + config = np.show_config(mode="dicts") + + assert isinstance(config, dict) + assert all([key in config for key in self.REQUIRED_CONFIG_KEYS]), ( + "Required key missing," + " see index of `False` with `REQUIRED_CONFIG_KEYS`" + ) + + def test_invalid_mode(self): + with pytest.raises(AttributeError): + np.show_config(mode="foo") + + def test_warn_to_add_tests(self): + assert len(np.__config__.DisplayModes) == 2, ( + "New mode detected," + " please add UT if applicable and increment this count" + ) diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py index 92a34bf91..eaa89aa6f 100644 --- a/numpy/tests/test_public_api.py +++ b/numpy/tests/test_public_api.py @@ -9,6 +9,7 @@ import warnings import numpy as np import numpy import pytest +from numpy.testing import IS_WASM try: import ctypes @@ -33,7 +34,6 @@ def test_numpy_namespace(): # None of these objects are publicly documented to be part of the main # NumPy namespace (some are useful though, others need to be cleaned up) undocumented = { - 'Tester': 'numpy.testing._private.nosetester.NoseTester', '_add_newdoc_ufunc': 'numpy.core._multiarray_umath._add_newdoc_ufunc', 'add_docstring': 'numpy.core._multiarray_umath.add_docstring', 'add_newdoc': 'numpy.core.function_base.add_newdoc', @@ -62,7 +62,8 @@ def test_numpy_namespace(): assert bad_results == allowlist -@pytest.mark.parametrize('name', ['testing', 'Tester']) +@pytest.mark.skipif(IS_WASM, reason="can't start subprocess") +@pytest.mark.parametrize('name', ['testing']) def test_import_lazy_import(name): """Make sure we can actually use the modules we lazy load. @@ -135,6 +136,8 @@ PUBLIC_MODULES = ['numpy.' + s for s in [ "doc", "doc.constants", "doc.ufuncs", + "dtypes", + "exceptions", "f2py", "fft", "lib", @@ -157,6 +160,7 @@ PUBLIC_MODULES = ['numpy.' + s for s in [ "polynomial.polynomial", "random", "testing", + "testing.overrides", "typing", "typing.mypy_plugin", "version", @@ -191,6 +195,7 @@ PRIVATE_BUT_PRESENT_MODULES = ['numpy.' + s for s in [ "core.umath", "core.umath_tests", "distutils.armccompiler", + "distutils.fujitsuccompiler", "distutils.ccompiler", 'distutils.ccompiler_opt', "distutils.command", @@ -244,7 +249,6 @@ PRIVATE_BUT_PRESENT_MODULES = ['numpy.' + s for s in [ "distutils.numpy_distribution", "distutils.pathccompiler", "distutils.unixccompiler", - "dual", "f2py.auxfuncs", "f2py.capi_maps", "f2py.cb_rules", @@ -276,7 +280,6 @@ PRIVATE_BUT_PRESENT_MODULES = ['numpy.' + s for s in [ "lib.utils", "linalg.lapack_lite", "linalg.linalg", - "ma.bench", "ma.core", "ma.testutils", "ma.timer_comparison", @@ -286,7 +289,6 @@ PRIVATE_BUT_PRESENT_MODULES = ['numpy.' + s for s in [ "random.mtrand", "random.bit_generator", "testing.print_coercion_tables", - "testing.utils", ]] @@ -318,6 +320,7 @@ SKIP_LIST = [ "numpy.core.code_generators.generate_ufunc_api", "numpy.core.code_generators.numpy_api", "numpy.core.code_generators.generate_umath_doc", + "numpy.core.code_generators.verify_c_api_version", "numpy.core.cversions", "numpy.core.generate_numpy_api", "numpy.distutils.msvc9compiler", @@ -349,6 +352,8 @@ def test_all_modules_are_expected(): SKIP_LIST_2 = [ 'numpy.math', 'numpy.distutils.log.sys', + 'numpy.distutils.log.logging', + 'numpy.distutils.log.warnings', 'numpy.doc.constants.re', 'numpy.doc.constants.textwrap', 'numpy.lib.emath', @@ -356,6 +361,7 @@ SKIP_LIST_2 = [ 'numpy.matlib.char', 'numpy.matlib.rec', 'numpy.matlib.emath', + 'numpy.matlib.exceptions', 'numpy.matlib.math', 'numpy.matlib.linalg', 'numpy.matlib.fft', @@ -466,6 +472,10 @@ def test_api_importable(): @pytest.mark.xfail( + hasattr(np.__config__, "_built_with_meson"), + reason = "Meson does not yet support entry points via pyproject.toml", +) +@pytest.mark.xfail( sysconfig.get_config_var("Py_DEBUG") is not None, reason=( "NumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, " @@ -500,3 +510,17 @@ def test_array_api_entry_point(): "does not point to our Array API implementation" ) assert xp is numpy.array_api, msg + + +@pytest.mark.parametrize("name", [ + 'ModuleDeprecationWarning', 'VisibleDeprecationWarning', + 'ComplexWarning', 'TooHardError', 'AxisError']) +def test_moved_exceptions(name): + # These were moved to the exceptions namespace, but currently still + # available + assert name in np.__all__ + assert name not in np.__dir__() + # Fetching works, but __module__ is set correctly: + assert getattr(np, name).__module__ == "numpy.exceptions" + assert name in np.exceptions.__all__ + getattr(np.exceptions, name) diff --git a/numpy/tests/test_reloading.py b/numpy/tests/test_reloading.py index 8d8c8aa34..a1f360089 100644 --- a/numpy/tests/test_reloading.py +++ b/numpy/tests/test_reloading.py @@ -1,6 +1,13 @@ -from numpy.testing import assert_raises, assert_warns, assert_, assert_equal +from numpy.testing import ( + assert_raises, + assert_warns, + assert_, + assert_equal, + IS_WASM, +) from numpy.compat import pickle +import pytest import sys import subprocess import textwrap @@ -37,6 +44,7 @@ def test_novalue(): protocol=proto)) is np._NoValue) +@pytest.mark.skipif(IS_WASM, reason="can't start subprocess") def test_full_reimport(): """At the time of writing this, it is *not* truly supported, but apparently enough users rely on it, for it to be an annoying change diff --git a/numpy/tests/test_scripts.py b/numpy/tests/test_scripts.py index 5aa8191bb..892c04eef 100644 --- a/numpy/tests/test_scripts.py +++ b/numpy/tests/test_scripts.py @@ -9,7 +9,7 @@ from os.path import join as pathjoin, isfile, dirname import subprocess import numpy as np -from numpy.testing import assert_equal +from numpy.testing import assert_equal, IS_WASM is_inplace = isfile(pathjoin(dirname(np.__file__), '..', 'setup.py')) @@ -41,6 +41,7 @@ def test_f2py(f2py_cmd): assert_equal(stdout.strip(), np.__version__.encode('ascii')) +@pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess") def test_pep338(): stdout = subprocess.check_output([sys.executable, '-mnumpy.f2py', '-v']) assert_equal(stdout.strip(), np.__version__.encode('ascii')) |
