-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_dtypes.py
More file actions
executable file
·47 lines (31 loc) · 1.11 KB
/
test_dtypes.py
File metadata and controls
executable file
·47 lines (31 loc) · 1.11 KB
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
38
39
40
41
42
43
44
45
46
47
import ctypes
import pytest
from arrayfire.dtypes import Dtype, float32, int16, int32, s16, str_to_dtype, uint16
def test_dtype_str_representation() -> None:
assert str(float32) == "float32"
def test_dtype_repr_representation() -> None:
assert repr(float32) == "arrayfire.float32(typecode<f>)"
def test_dtype_equality() -> None:
dt1 = Dtype("float32", "f", ctypes.c_float, "float", 0)
dt2 = float32
assert dt1 == dt2
def test_dtype_inequality() -> None:
assert float32 != int16
@pytest.mark.parametrize(
"value,expected_dtype",
[
("short int", s16),
("int", int32),
("uint16", uint16),
("float", float32),
],
)
def test_str_to_dtype(value: str, expected_dtype: Dtype) -> None:
result_dtype = str_to_dtype(value)
assert result_dtype == expected_dtype
def test_str_to_dtype_raises_error() -> None:
with pytest.raises(TypeError):
str_to_dtype("invalid_dtype")
def test_str_to_dtype_raises_error_case_insensitive() -> None:
with pytest.raises(TypeError):
str_to_dtype("Int")