Skip to content

Commit 17b3eab

Browse files
committed
Reintroduce test_has_names
This just tests which names exist without checking anything else. It also doesn't use hypothesis, so it should work even if the library doesn't have proper hypothesis support (assuming the test suite can even run at all in that case, I'm not completely sure).
1 parent 87834dd commit 17b3eab

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

array_api_tests/stubs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
f for n, f in inspect.getmembers(array, predicate=inspect.isfunction)
3535
if n != "__init__" # probably exists for Sphinx
3636
]
37+
array_attributes = [
38+
n for n, f in inspect.getmembers(array, predicate=lambda x: not inspect.isfunction(x))
39+
if n != "__init__" # probably exists for Sphinx
40+
]
3741

3842
category_to_funcs: Dict[str, List[FunctionType]] = {}
3943
for name, mod in name_to_mod.items():

array_api_tests/test_signatures.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def squeeze(x, /, axis):
3232
from . import dtype_helpers as dh
3333
from . import hypothesis_helpers as hh
3434
from . import xps
35-
from ._array_module import _UndefinedStub
36-
from ._array_module import mod as xp
37-
from .stubs import array_methods, category_to_funcs, extension_to_funcs
35+
from ._array_module import _UndefinedStub, mod as xp, mod_name
36+
from .stubs import (array_attributes, array_methods, category_to_funcs,
37+
extension_to_funcs, EXTENSIONS)
3838
from .typing import Array, DataType
3939

4040
pytestmark = pytest.mark.ci
@@ -252,3 +252,32 @@ def test_array_method_signature(stub: FunctionType, data: DataObject):
252252
assert hasattr(x, stub.__name__), f"{stub.__name__} not found in array object {x!r}"
253253
method = getattr(x, stub.__name__)
254254
_test_func_signature(method, stub, array=x)
255+
256+
has_name_params = []
257+
for ext, stubs in extension_to_funcs.items():
258+
for stub in stubs:
259+
has_name_params.append(pytest.param(ext, stub.__name__))
260+
for cat, stubs in category_to_funcs.items():
261+
for stub in stubs:
262+
has_name_params.append(pytest.param(cat, stub.__name__))
263+
for meth in array_methods:
264+
has_name_params.append(pytest.param('array_method', meth.__name__))
265+
for attr in array_attributes:
266+
has_name_params.append(pytest.param('array_attribute', attr))
267+
268+
# This is a very basic test to see what names are defined in a library. It
269+
# does not even require functioning hypothesis array_api support.
270+
@pytest.mark.parametrize("category, name", has_name_params)
271+
def test_has_names(category, name):
272+
if category in EXTENSIONS:
273+
ext_mod = getattr(xp, category)
274+
assert hasattr(ext_mod, name), f"{mod_name} is missing the {category} extension function {name}()"
275+
elif category.startswith('array_'):
276+
# TODO: This would fail if ones() is missing.
277+
arr = xp.ones((1, 1))
278+
if category == 'array_attribute':
279+
assert hasattr(arr, name), f"The {mod_name} array object is missing the attribute {name}"
280+
else:
281+
assert hasattr(arr, name), f"The {mod_name} array object is missing the method {name}()"
282+
else:
283+
assert hasattr(xp, name), f"{mod_name} is missing the {category} function {name}()"

0 commit comments

Comments
 (0)