|
| 1 | +import pytest |
1 | 2 | from hypothesis import given
|
2 | 3 |
|
3 | 4 | from . import _array_module as xp
|
| 5 | +from . import dtype_helpers as dh |
4 | 6 | from . import hypothesis_helpers as hh
|
5 | 7 | 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 |
6 | 45 |
|
7 | 46 |
|
8 | 47 | @given(hh.mutually_promotable_dtypes(None))
|
|
0 commit comments