mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-23 13:45:10 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
00a85a6969
commit
4be007670c
@ -7,47 +7,49 @@ from pybind11_tests import numpy_scalars as m
|
|||||||
|
|
||||||
np = pytest.importorskip("numpy")
|
np = pytest.importorskip("numpy")
|
||||||
|
|
||||||
SCALAR_TYPES = dict([
|
SCALAR_TYPES = dict(
|
||||||
(np.bool_, False),
|
[
|
||||||
(np.int8, -7),
|
(np.bool_, False),
|
||||||
(np.int16, -15),
|
(np.int8, -7),
|
||||||
(np.int32, -31),
|
(np.int16, -15),
|
||||||
(np.int64, -63),
|
(np.int32, -31),
|
||||||
(np.uint8, 9),
|
(np.int64, -63),
|
||||||
(np.uint16, 17),
|
(np.uint8, 9),
|
||||||
(np.uint32, 33),
|
(np.uint16, 17),
|
||||||
(np.uint64, 65),
|
(np.uint32, 33),
|
||||||
(np.single, 1.125),
|
(np.uint64, 65),
|
||||||
(np.double, 1.25),
|
(np.single, 1.125),
|
||||||
(np.complex64, 1 - 0.125j),
|
(np.double, 1.25),
|
||||||
(np.complex128, 1 - 0.25j),
|
(np.complex64, 1 - 0.125j),
|
||||||
])
|
(np.complex128, 1 - 0.25j),
|
||||||
|
]
|
||||||
|
)
|
||||||
ALL_TYPES = [int, bool, float, bytes, str] + list(SCALAR_TYPES)
|
ALL_TYPES = [int, bool, float, bytes, str] + list(SCALAR_TYPES)
|
||||||
|
|
||||||
|
|
||||||
def type_name(tp):
|
def type_name(tp):
|
||||||
try:
|
try:
|
||||||
return tp.__name__.rstrip('_')
|
return tp.__name__.rstrip("_")
|
||||||
except BaseException:
|
except BaseException:
|
||||||
# no numpy
|
# no numpy
|
||||||
return str(tp)
|
return str(tp)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module', params=list(SCALAR_TYPES), ids=type_name)
|
@pytest.fixture(scope="module", params=list(SCALAR_TYPES), ids=type_name)
|
||||||
def scalar_type(request):
|
def scalar_type(request):
|
||||||
return request.param
|
return request.param
|
||||||
|
|
||||||
|
|
||||||
def expected_signature(tp):
|
def expected_signature(tp):
|
||||||
s = 'str' if sys.version_info[0] >= 3 else 'unicode'
|
s = "str" if sys.version_info[0] >= 3 else "unicode"
|
||||||
t = type_name(tp)
|
t = type_name(tp)
|
||||||
return 'test_{t}(x: {t}) -> Tuple[{s}, {t}]\n'.format(s=s, t=t)
|
return "test_{t}(x: {t}) -> Tuple[{s}, {t}]\n".format(s=s, t=t)
|
||||||
|
|
||||||
|
|
||||||
def test_numpy_scalars(scalar_type):
|
def test_numpy_scalars(scalar_type):
|
||||||
expected = SCALAR_TYPES[scalar_type]
|
expected = SCALAR_TYPES[scalar_type]
|
||||||
name = type_name(scalar_type)
|
name = type_name(scalar_type)
|
||||||
func = getattr(m, 'test_' + name)
|
func = getattr(m, "test_" + name)
|
||||||
assert func.__doc__ == expected_signature(scalar_type)
|
assert func.__doc__ == expected_signature(scalar_type)
|
||||||
for tp in ALL_TYPES:
|
for tp in ALL_TYPES:
|
||||||
value = tp(1)
|
value = tp(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user