@@ -32,9 +32,9 @@ def squeeze(x, /, axis):
3232from . import dtype_helpers as dh
3333from . import hypothesis_helpers as hh
3434from . 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 )
3838from .typing import Array , DataType
3939
4040pytestmark = 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