|
60 | 60 | @pytest.mark.parametrize("kind_str", dtype_categories.keys())
|
61 | 61 | @pytest.mark.parametrize("dtype_str", list_dtypes)
|
62 | 62 | def test_isdtype_kind_str(dtype_str, kind_str):
|
63 |
| - if dtype_str in dtype_categories[kind_str]: |
64 |
| - assert dpt.isdtype(dpt.dtype(dtype_str), kind_str) |
65 |
| - else: |
66 |
| - assert not dpt.isdtype(dpt.dtype(dtype_str), kind_str) |
| 63 | + dt = dpt.dtype(dtype_str) |
| 64 | + is_in_kind = dpt.isdtype(dt, kind_str) |
| 65 | + expected = dtype_str in dtype_categories[kind_str] |
| 66 | + assert is_in_kind == expected |
67 | 67 |
|
68 | 68 |
|
69 | 69 | @pytest.mark.parametrize("dtype_str", list_dtypes)
|
70 | 70 | def test_isdtype_kind_tuple(dtype_str):
|
| 71 | + dt = dpt.dtype(dtype_str) |
71 | 72 | if dtype_str.startswith("bool"):
|
72 |
| - assert dpt.isdtype(dpt.dtype(dtype_str), ("real floating", "bool")) |
| 73 | + assert dpt.isdtype(dt, ("real floating", "bool")) |
73 | 74 | assert not dpt.isdtype(
|
74 |
| - dpt.dtype(dtype_str), |
75 |
| - ("integral", "real floating", "complex floating"), |
| 75 | + dt, ("integral", "real floating", "complex floating") |
76 | 76 | )
|
77 | 77 | elif dtype_str.startswith("int"):
|
78 |
| - assert dpt.isdtype( |
79 |
| - dpt.dtype(dtype_str), ("real floating", "signed integer") |
80 |
| - ) |
| 78 | + assert dpt.isdtype(dt, ("real floating", "signed integer")) |
81 | 79 | assert not dpt.isdtype(
|
82 |
| - dpt.dtype(dtype_str), ("bool", "unsigned integer", "real floating") |
| 80 | + dt, ("bool", "unsigned integer", "real floating") |
83 | 81 | )
|
84 | 82 | elif dtype_str.startswith("uint"):
|
85 |
| - assert dpt.isdtype(dpt.dtype(dtype_str), ("bool", "unsigned integer")) |
86 |
| - assert not dpt.isdtype( |
87 |
| - dpt.dtype(dtype_str), ("real floating", "complex floating") |
88 |
| - ) |
| 83 | + assert dpt.isdtype(dt, ("bool", "unsigned integer")) |
| 84 | + assert not dpt.isdtype(dt, ("real floating", "complex floating")) |
89 | 85 | elif dtype_str.startswith("float"):
|
90 |
| - assert dpt.isdtype( |
91 |
| - dpt.dtype(dtype_str), ("complex floating", "real floating") |
92 |
| - ) |
93 |
| - assert not dpt.isdtype( |
94 |
| - dpt.dtype(dtype_str), ("integral", "complex floating") |
95 |
| - ) |
| 86 | + assert dpt.isdtype(dt, ("complex floating", "real floating")) |
| 87 | + assert not dpt.isdtype(dt, ("integral", "complex floating", "bool")) |
96 | 88 | else:
|
97 |
| - assert dpt.isdtype( |
98 |
| - dpt.dtype(dtype_str), ("integral", "complex floating") |
99 |
| - ) |
100 |
| - assert not dpt.isdtype( |
101 |
| - dpt.dtype(dtype_str), ("bool", "integral", "real floating") |
102 |
| - ) |
| 89 | + assert dpt.isdtype(dt, ("integral", "complex floating")) |
| 90 | + assert not dpt.isdtype(dt, ("bool", "integral", "real floating")) |
103 | 91 |
|
104 | 92 |
|
105 | 93 | @pytest.mark.parametrize("dtype_str", list_dtypes)
|
106 | 94 | def test_isdtype_kind_tuple_dtypes(dtype_str):
|
| 95 | + dt = dpt.dtype(dtype_str) |
107 | 96 | if dtype_str.startswith("bool"):
|
108 |
| - assert dpt.isdtype(dpt.dtype(dtype_str), (dpt.int32, dpt.bool)) |
109 |
| - assert not dpt.isdtype( |
110 |
| - dpt.dtype(dtype_str), (dpt.int16, dpt.uint32, dpt.float64) |
111 |
| - ) |
| 97 | + assert dpt.isdtype(dt, (dpt.int32, dpt.bool)) |
| 98 | + assert not dpt.isdtype(dt, (dpt.int16, dpt.uint32, dpt.float64)) |
| 99 | + |
112 | 100 | elif dtype_str.startswith("int"):
|
113 |
| - assert dpt.isdtype( |
114 |
| - dpt.dtype(dtype_str), (dpt.int8, dpt.int16, dpt.int32, dpt.int64) |
115 |
| - ) |
116 |
| - assert not dpt.isdtype( |
117 |
| - dpt.dtype(dtype_str), (dpt.bool, dpt.float32, dpt.complex64) |
118 |
| - ) |
| 101 | + assert dpt.isdtype(dt, (dpt.int8, dpt.int16, dpt.int32, dpt.int64)) |
| 102 | + assert not dpt.isdtype(dt, (dpt.bool, dpt.float32, dpt.complex64)) |
| 103 | + |
119 | 104 | elif dtype_str.startswith("uint"):
|
120 |
| - assert dpt.isdtype( |
121 |
| - dpt.dtype(dtype_str), |
122 |
| - (dpt.uint8, dpt.uint16, dpt.uint32, dpt.uint64), |
123 |
| - ) |
124 |
| - assert not dpt.isdtype( |
125 |
| - dpt.dtype(dtype_str), (dpt.bool, dpt.int32, dpt.float32) |
126 |
| - ) |
| 105 | + assert dpt.isdtype(dt, (dpt.uint8, dpt.uint16, dpt.uint32, dpt.uint64)) |
| 106 | + assert not dpt.isdtype(dt, (dpt.bool, dpt.int32, dpt.float32)) |
| 107 | + |
127 | 108 | elif dtype_str.startswith("float"):
|
128 |
| - assert dpt.isdtype( |
129 |
| - dpt.dtype(dtype_str), (dpt.float16, dpt.float32, dpt.float64) |
130 |
| - ) |
131 |
| - assert not dpt.isdtype( |
132 |
| - dpt.dtype(dtype_str), (dpt.bool, dpt.complex64, dpt.int8) |
133 |
| - ) |
| 109 | + assert dpt.isdtype(dt, (dpt.float16, dpt.float32, dpt.float64)) |
| 110 | + assert not dpt.isdtype(dt, (dpt.bool, dpt.complex64, dpt.int8)) |
| 111 | + |
134 | 112 | else:
|
135 |
| - assert dpt.isdtype( |
136 |
| - dpt.dtype(dtype_str), (dpt.complex64, dpt.complex128) |
137 |
| - ) |
138 |
| - assert not dpt.isdtype( |
139 |
| - dpt.dtype(dtype_str), (dpt.bool, dpt.uint64, dpt.int8) |
140 |
| - ) |
| 113 | + assert dpt.isdtype(dt, (dpt.complex64, dpt.complex128)) |
| 114 | + assert not dpt.isdtype(dt, (dpt.bool, dpt.uint64, dpt.int8)) |
141 | 115 |
|
142 | 116 |
|
143 | 117 | @pytest.mark.parametrize(
|
|
0 commit comments