Skip to content

Commit fdb7ffd

Browse files
committed
Move test_has_names to its own file
That way it can be run even on libraries that fail the hypothesis sanity checks.
1 parent 17b3eab commit fdb7ffd

File tree

2 files changed

+39
-32
lines changed

2 files changed

+39
-32
lines changed

array_api_tests/test_has_names.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
This is a very basic test to see what names are defined in a library. It
3+
does not even require functioning hypothesis array_api support.
4+
"""
5+
6+
import pytest
7+
8+
from ._array_module import mod as xp, mod_name
9+
from .stubs import (array_attributes, array_methods, category_to_funcs,
10+
extension_to_funcs, EXTENSIONS)
11+
12+
has_name_params = []
13+
for ext, stubs in extension_to_funcs.items():
14+
for stub in stubs:
15+
has_name_params.append(pytest.param(ext, stub.__name__))
16+
for cat, stubs in category_to_funcs.items():
17+
for stub in stubs:
18+
has_name_params.append(pytest.param(cat, stub.__name__))
19+
for meth in array_methods:
20+
has_name_params.append(pytest.param('array_method', meth.__name__))
21+
for attr in array_attributes:
22+
has_name_params.append(pytest.param('array_attribute', attr))
23+
24+
@pytest.mark.parametrize("category, name", has_name_params)
25+
def test_has_names(category, name):
26+
if category in EXTENSIONS:
27+
ext_mod = getattr(xp, category)
28+
assert hasattr(ext_mod, name), f"{mod_name} is missing the {category} extension function {name}()"
29+
elif category.startswith('array_'):
30+
# TODO: This would fail if ones() is missing.
31+
arr = xp.ones((1, 1))
32+
if category == 'array_attribute':
33+
assert hasattr(arr, name), f"The {mod_name} array object is missing the attribute {name}"
34+
else:
35+
assert hasattr(arr, name), f"The {mod_name} array object is missing the method {name}()"
36+
else:
37+
assert hasattr(xp, name), f"{mod_name} is missing the {category} function {name}()"

array_api_tests/test_signatures.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ 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, mod as xp, mod_name
36-
from .stubs import (array_attributes, array_methods, category_to_funcs,
37-
extension_to_funcs, EXTENSIONS)
35+
from ._array_module import _UndefinedStub, mod as xp
36+
from .stubs import array_methods, category_to_funcs, extension_to_funcs
3837
from .typing import Array, DataType
3938

4039
pytestmark = pytest.mark.ci
@@ -252,32 +251,3 @@ def test_array_method_signature(stub: FunctionType, data: DataObject):
252251
assert hasattr(x, stub.__name__), f"{stub.__name__} not found in array object {x!r}"
253252
method = getattr(x, stub.__name__)
254253
_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)