2121 "nan" ,
2222 "newaxis" ,
2323 "pi" ,
24- # Creation functions
24+ # Creation Functions
2525 "arange" ,
2626 "asarray" ,
2727 "empty" ,
157157 "nonzero" ,
158158 "searchsorted" ,
159159 "where" ,
160- # Set functions
160+ # Set Functions
161161 "unique_all" ,
162162 "unique_counts" ,
163163 "unique_inverse" ,
239239
240240
241241def all_names (mod ):
242- """Return all names imported by `from mod import *`.
243- This is typically `__all__` but, if not defined, Python
244- implements automated fallbacks.
245- """
246- # Note: this method also makes the test trip if a name is
247- # in __all__ but doesn't actually appear in the module.
242+ """Return all names available in a module."""
248243 objs = {}
249244 exec (f"from { mod .__name__ } import *" , objs )
250- return list (objs )
245+ for n in dir (mod ):
246+ if not n .startswith ("_" ) and hasattr (mod , n ):
247+ objs [n ] = getattr (mod , n )
248+ return set (objs )
251249
252250
253251def get_mod (library , module , * , compat ):
@@ -257,49 +255,46 @@ def get_mod(library, module, *, compat):
257255 return getattr (xp , module ) if module else xp
258256
259257
260- @pytest .mark .parametrize ("func" , [all_names , dir ])
261258@pytest .mark .parametrize ("module" , list (NAMES ))
262259@pytest .mark .parametrize ("library" , wrapped_libraries )
263- def test_array_api_names (library , module , func ):
264- """Test that __all__ and dir() aren 't missing any exports
260+ def test_array_api_names (library , module ):
261+ """Test that __all__ isn 't missing any exports
265262 dictated by the Standard.
266263 """
267264 mod = get_mod (library , module , compat = True )
268- missing = set (NAMES [module ]) - set ( func ( mod ) )
265+ missing = set (NAMES [module ]) - all_names ( mod )
269266 xfail = set (XFAILS .get ((library , module ), []))
270267 xpass = xfail - missing
271268 fails = missing - xfail
272269 assert not xpass , f"Names in XFAILS are defined: { xpass } "
273270 assert not fails , f"Missing exports: { fails } "
274271
275272
276- @pytest .mark .parametrize ("func" , [all_names , dir ])
277273@pytest .mark .parametrize ("module" , list (NAMES ))
278274@pytest .mark .parametrize ("library" , wrapped_libraries )
279- def test_compat_doesnt_hide_names (library , module , func ):
275+ def test_compat_doesnt_hide_names (library , module ):
280276 """The base namespace can have more names than the ones explicitly exported
281277 by array-api-compat. Test that we're not suppressing them.
282278 """
283279 bare_mod = get_mod (library , module , compat = False )
284280 compat_mod = get_mod (library , module , compat = True )
285281
286- missing = set ( func ( bare_mod )) - set ( func ( compat_mod ) )
282+ missing = all_names ( bare_mod ) - all_names ( compat_mod )
287283 missing = {name for name in missing if not name .startswith ("_" )}
288284 assert not missing , f"Non-Array API names have been hidden: { missing } "
289285
290286
291- @pytest .mark .parametrize ("func" , [all_names , dir ])
292287@pytest .mark .parametrize ("module" , list (NAMES ))
293288@pytest .mark .parametrize ("library" , wrapped_libraries )
294- def test_compat_doesnt_add_names (library , module , func ):
289+ def test_compat_doesnt_add_names (library , module ):
295290 """Test that array-api-compat isn't adding names to the namespace
296291 besides those defined by the Array API Standard.
297292 """
298293 bare_mod = get_mod (library , module , compat = False )
299294 compat_mod = get_mod (library , module , compat = True )
300295
301296 aapi_names = set (NAMES [module ])
302- spurious = set ( func ( compat_mod )) - set ( func ( bare_mod )) - aapi_names - { "__all__" }
297+ spurious = all_names ( compat_mod ) - all_names ( bare_mod ) - aapi_names
303298 # Quietly ignore *Result dataclasses
304299 spurious = {name for name in spurious if not name .endswith ("Result" )}
305300 assert not spurious , (
0 commit comments