forked from data-apis/array-api-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_has_names.py
37 lines (33 loc) · 1.52 KB
/
test_has_names.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
This is a very basic test to see what names are defined in a library. It
does not even require functioning hypothesis array_api support.
"""
import pytest
from . import xp
from .stubs import (array_attributes, array_methods, category_to_funcs,
extension_to_funcs, EXTENSIONS)
has_name_params = []
for ext, stubs in extension_to_funcs.items():
for stub in stubs:
has_name_params.append(pytest.param(ext, stub.__name__))
for cat, stubs in category_to_funcs.items():
for stub in stubs:
has_name_params.append(pytest.param(cat, stub.__name__))
for meth in array_methods:
has_name_params.append(pytest.param('array_method', meth.__name__))
for attr in array_attributes:
has_name_params.append(pytest.param('array_attribute', attr))
@pytest.mark.parametrize("category, name", has_name_params)
def test_has_names(category, name):
if category in EXTENSIONS:
ext_mod = getattr(xp, category)
assert hasattr(ext_mod, name), f"{xp.__name__} is missing the {category} extension function {name}()"
elif category.startswith('array_'):
# TODO: This would fail if ones() is missing.
arr = xp.ones((1, 1))
if category == 'array_attribute':
assert hasattr(arr, name), f"The {xp.__name__} array object is missing the attribute {name}"
else:
assert hasattr(arr, name), f"The {xp.__name__} array object is missing the method {name}()"
else:
assert hasattr(xp, name), f"{xp.__name__} is missing the {category} function {name}()"