summaryrefslogtreecommitdiff
path: root/numpy/tests/test_public_api.py
diff options
context:
space:
mode:
authorDeveloper-Ecosystem-Engineering <65677710+Developer-Ecosystem-Engineering@users.noreply.github.com>2021-11-18 14:31:58 -0800
committerGitHub <noreply@github.com>2021-11-18 14:31:58 -0800
commit5e9ce0c0529e3085498ac892941a020a65c7369a (patch)
treea70d9e941549b4a51b493f1b170ef33ce0d5a217 /numpy/tests/test_public_api.py
parent2ff7ab64d4e7d5928e96ca95b85350aa9caa2b63 (diff)
parent056abda14dab7fa8daf7a1ab44144aeb2250c216 (diff)
downloadnumpy-5e9ce0c0529e3085498ac892941a020a65c7369a.tar.gz
Merge branch 'numpy:main' into as_min_max
Diffstat (limited to 'numpy/tests/test_public_api.py')
-rw-r--r--numpy/tests/test_public_api.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py
index 73a93f489..0754df402 100644
--- a/numpy/tests/test_public_api.py
+++ b/numpy/tests/test_public_api.py
@@ -1,4 +1,5 @@
import sys
+import sysconfig
import subprocess
import pkgutil
import types
@@ -122,6 +123,7 @@ def test_NPY_NO_EXPORT():
# private, to clean up our public API and avoid confusion.
PUBLIC_MODULES = ['numpy.' + s for s in [
"array_api",
+ "array_api.linalg",
"ctypeslib",
"distutils",
"distutils.cpuinfo",
@@ -178,7 +180,6 @@ PRIVATE_BUT_PRESENT_MODULES = ['numpy.' + s for s in [
"core.fromnumeric",
"core.function_base",
"core.getlimits",
- "core.machar",
"core.memmap",
"core.multiarray",
"core.numeric",
@@ -459,3 +460,40 @@ def test_api_importable():
raise AssertionError("Modules that are not really public but looked "
"public and can not be imported: "
"{}".format(module_names))
+
+
+@pytest.mark.xfail(
+ sysconfig.get_config_var("Py_DEBUG") is not None,
+ reason=(
+ "NumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, "
+ "which does not expose the `array_api` entry point. "
+ "See https://github.com/numpy/numpy/pull/19800"
+ ),
+)
+def test_array_api_entry_point():
+ """
+ Entry point for Array API implementation can be found with importlib and
+ returns the numpy.array_api namespace.
+ """
+ eps = importlib.metadata.entry_points()
+ try:
+ xp_eps = eps.select(group="array_api")
+ except AttributeError:
+ # The select interface for entry_points was introduced in py3.10,
+ # deprecating its dict interface. We fallback to dict keys for finding
+ # Array API entry points so that running this test in <=3.9 will
+ # still work - see https://github.com/numpy/numpy/pull/19800.
+ xp_eps = eps.get("array_api", [])
+ assert len(xp_eps) > 0, "No entry points for 'array_api' found"
+
+ try:
+ ep = next(ep for ep in xp_eps if ep.name == "numpy")
+ except StopIteration:
+ raise AssertionError("'numpy' not in array_api entry points") from None
+
+ xp = ep.load()
+ msg = (
+ f"numpy entry point value '{ep.value}' "
+ "does not point to our Array API implementation"
+ )
+ assert xp is numpy.array_api, msg