Skip to content

Commit 3ed56a9

Browse files
committed
Test finfo and iinfo attributes
1 parent eafe8b6 commit 3ed56a9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

array_api_tests/test_data_type_functions.py

+39
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
1+
import pytest
12
from hypothesis import given
23

34
from . import _array_module as xp
5+
from . import dtype_helpers as dh
46
from . import hypothesis_helpers as hh
57
from . import pytest_helpers as ph
8+
from .typing import DataType
9+
10+
11+
def make_dtype_id(dtype: DataType) -> str:
12+
return dh.dtype_to_name[dtype]
13+
14+
15+
@pytest.mark.parametrize("dtype", dh.float_dtypes, ids=make_dtype_id)
16+
def test_finfo(dtype):
17+
out = xp.finfo(dtype)
18+
f_func = f"[finfo({dh.dtype_to_name[dtype]})]"
19+
for attr, stype in [
20+
("bits", int),
21+
("eps", float),
22+
("max", float),
23+
("min", float),
24+
("smallest_normal", float),
25+
]:
26+
assert hasattr(out, attr), f"out has no attribute '{attr}' {f_func}"
27+
value = getattr(out, attr)
28+
assert isinstance(
29+
value, stype
30+
), f"type(out.{attr})={type(value)!r}, but should be {stype.__name__} {f_func}"
31+
# TODO: test values
32+
33+
34+
@pytest.mark.parametrize("dtype", dh.all_int_dtypes, ids=make_dtype_id)
35+
def test_iinfo(dtype):
36+
out = xp.iinfo(dtype)
37+
f_func = f"[iinfo({dh.dtype_to_name[dtype]})]"
38+
for attr in ["bits", "max", "min"]:
39+
assert hasattr(out, attr), f"out has no attribute '{attr}' {f_func}"
40+
value = getattr(out, attr)
41+
assert isinstance(
42+
value, int
43+
), f"type(out.{attr})={type(value)!r}, but should be int {f_func}"
44+
# TODO: test values
645

746

847
@given(hh.mutually_promotable_dtypes(None))

0 commit comments

Comments
 (0)