|
1 | 1 | import sys |
| 2 | +import sysconfig |
2 | 3 | import subprocess |
3 | 4 | import pkgutil |
4 | 5 | import types |
@@ -458,3 +459,40 @@ def check_importable(module_name): |
458 | 459 | raise AssertionError("Modules that are not really public but looked " |
459 | 460 | "public and can not be imported: " |
460 | 461 | "{}".format(module_names)) |
| 462 | + |
| 463 | + |
| 464 | +@pytest.mark.xfail( |
| 465 | + sysconfig.get_config_var("Py_DEBUG") is not None, |
| 466 | + reason=( |
| 467 | + "NumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, " |
| 468 | + "which does not expose the `array_api` entry point. " |
| 469 | + "See https://github.com/numpy/numpy/pull/19800" |
| 470 | + ), |
| 471 | +) |
| 472 | +def test_array_api_entry_point(): |
| 473 | + """ |
| 474 | + Entry point for Array API implementation can be found with importlib and |
| 475 | + returns the numpy.array_api namespace. |
| 476 | + """ |
| 477 | + eps = importlib.metadata.entry_points() |
| 478 | + try: |
| 479 | + xp_eps = eps.select(group="array_api") |
| 480 | + except AttributeError: |
| 481 | + # The select interface for entry_points was introduced in py3.10, |
| 482 | + # deprecating its dict interface. We fallback to dict keys for finding |
| 483 | + # Array API entry points so that running this test in <=3.9 will |
| 484 | + # still work - see https://github.com/numpy/numpy/pull/19800. |
| 485 | + xp_eps = eps.get("array_api", []) |
| 486 | + assert len(xp_eps) > 0, "No entry points for 'array_api' found" |
| 487 | + |
| 488 | + try: |
| 489 | + ep = next(ep for ep in xp_eps if ep.name == "numpy") |
| 490 | + except StopIteration: |
| 491 | + raise AssertionError("'numpy' not in array_api entry points") from None |
| 492 | + |
| 493 | + xp = ep.load() |
| 494 | + msg = ( |
| 495 | + f"numpy entry point value '{ep.value}' " |
| 496 | + "does not point to our Array API implementation" |
| 497 | + ) |
| 498 | + assert xp is numpy.array_api, msg |
0 commit comments