Skip to content

Commit 528a942

Browse files
committed
make tests isomorphic to source code
1 parent a1deda6 commit 528a942

File tree

3 files changed

+83
-84
lines changed

3 files changed

+83
-84
lines changed

tests/test_dtype/test_npy/test_sized.py

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
from tests.test_dtype.test_wrapper import _TestZDType
88
from zarr.core.dtype import (
9-
FixedLengthASCII,
109
FixedLengthBytes,
11-
FixedLengthUTF32,
1210
Float16,
1311
Float64,
1412
Int32,
@@ -17,48 +15,6 @@
1715
)
1816

1917

20-
class TestFixedLengthAscii(_TestZDType):
21-
test_cls = FixedLengthASCII
22-
valid_dtype = (np.dtype("|S10"), np.dtype("|S4"))
23-
invalid_dtype = (
24-
np.dtype(np.int8),
25-
np.dtype(np.float64),
26-
np.dtype("|U10"),
27-
)
28-
valid_json_v2 = ("|S0", "|S2", "|S4")
29-
valid_json_v3 = ({"name": "numpy.fixed_length_ascii", "configuration": {"length_bytes": 10}},)
30-
invalid_json_v2 = (
31-
"|S",
32-
"|U10",
33-
"|f8",
34-
)
35-
invalid_json_v3 = (
36-
{"name": "numpy.fixed_length_ascii", "configuration": {"length_bits": 0}},
37-
{"name": "numpy.fixed_length_ascii", "configuration": {"length_bits": "invalid"}},
38-
)
39-
40-
scalar_v2_params = (
41-
(FixedLengthASCII(length=0), ""),
42-
(FixedLengthASCII(length=2), "YWI="),
43-
(FixedLengthASCII(length=4), "YWJjZA=="),
44-
)
45-
scalar_v3_params = (
46-
(FixedLengthASCII(length=0), ""),
47-
(FixedLengthASCII(length=2), "YWI="),
48-
(FixedLengthASCII(length=4), "YWJjZA=="),
49-
)
50-
cast_value_params = (
51-
(FixedLengthASCII(length=0), "", np.bytes_("")),
52-
(FixedLengthASCII(length=2), "ab", np.bytes_("ab")),
53-
(FixedLengthASCII(length=4), "abcd", np.bytes_("abcd")),
54-
)
55-
item_size_params = (
56-
FixedLengthASCII(length=0),
57-
FixedLengthASCII(length=4),
58-
FixedLengthASCII(length=10),
59-
)
60-
61-
6218
class TestFixedLengthBytes(_TestZDType):
6319
test_cls = FixedLengthBytes
6420
valid_dtype = (np.dtype("|V10"),)
@@ -105,45 +61,6 @@ class TestFixedLengthBytes(_TestZDType):
10561
)
10662

10763

108-
class TestFixedLengthUTF32(_TestZDType):
109-
test_cls = FixedLengthUTF32
110-
valid_dtype = (np.dtype(">U10"), np.dtype("<U10"))
111-
invalid_dtype = (
112-
np.dtype(np.int8),
113-
np.dtype(np.float64),
114-
np.dtype("|S10"),
115-
)
116-
valid_json_v2 = (">U10", "<U10")
117-
valid_json_v3 = ({"name": "numpy.fixed_length_utf32", "configuration": {"length_bytes": 320}},)
118-
invalid_json_v2 = (
119-
"|U",
120-
"|S10",
121-
"|f8",
122-
)
123-
invalid_json_v3 = (
124-
{"name": "numpy.fixed_length_utf32", "configuration": {"length_bits": 0}},
125-
{"name": "numpy.fixed_length_utf32", "configuration": {"length_bits": "invalid"}},
126-
)
127-
128-
scalar_v2_params = ((FixedLengthUTF32(length=0), ""), (FixedLengthUTF32(length=2), "hi"))
129-
scalar_v3_params = (
130-
(FixedLengthUTF32(length=0), ""),
131-
(FixedLengthUTF32(length=2), "hi"),
132-
(FixedLengthUTF32(length=4), "hihi"),
133-
)
134-
135-
cast_value_params = (
136-
(FixedLengthUTF32(length=0), "", np.str_("")),
137-
(FixedLengthUTF32(length=2), "hi", np.str_("hi")),
138-
(FixedLengthUTF32(length=4), "hihi", np.str_("hihi")),
139-
)
140-
item_size_params = (
141-
FixedLengthUTF32(length=0),
142-
FixedLengthUTF32(length=4),
143-
FixedLengthUTF32(length=10),
144-
)
145-
146-
14764
class TestStructured(_TestZDType):
14865
test_cls = Structured
14966
valid_dtype = (

tests/test_dtype/test_npy/test_string.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44

55
from tests.test_dtype.test_wrapper import _TestZDType
6+
from zarr.core.dtype import FixedLengthASCII, FixedLengthUTF32
67
from zarr.core.dtype.npy.string import _NUMPY_SUPPORTS_VLEN_STRING, VariableLengthString
78

89
if _NUMPY_SUPPORTS_VLEN_STRING:
@@ -73,3 +74,84 @@ class TestVariableLengthString(_TestZDType): # type: ignore[no-redef]
7374
)
7475

7576
item_size_params = (VariableLengthString(),)
77+
78+
79+
class TestFixedLengthAscii(_TestZDType):
80+
test_cls = FixedLengthASCII
81+
valid_dtype = (np.dtype("|S10"), np.dtype("|S4"))
82+
invalid_dtype = (
83+
np.dtype(np.int8),
84+
np.dtype(np.float64),
85+
np.dtype("|U10"),
86+
)
87+
valid_json_v2 = ("|S0", "|S2", "|S4")
88+
valid_json_v3 = ({"name": "numpy.fixed_length_ascii", "configuration": {"length_bytes": 10}},)
89+
invalid_json_v2 = (
90+
"|S",
91+
"|U10",
92+
"|f8",
93+
)
94+
invalid_json_v3 = (
95+
{"name": "numpy.fixed_length_ascii", "configuration": {"length_bits": 0}},
96+
{"name": "numpy.fixed_length_ascii", "configuration": {"length_bits": "invalid"}},
97+
)
98+
99+
scalar_v2_params = (
100+
(FixedLengthASCII(length=0), ""),
101+
(FixedLengthASCII(length=2), "YWI="),
102+
(FixedLengthASCII(length=4), "YWJjZA=="),
103+
)
104+
scalar_v3_params = (
105+
(FixedLengthASCII(length=0), ""),
106+
(FixedLengthASCII(length=2), "YWI="),
107+
(FixedLengthASCII(length=4), "YWJjZA=="),
108+
)
109+
cast_value_params = (
110+
(FixedLengthASCII(length=0), "", np.bytes_("")),
111+
(FixedLengthASCII(length=2), "ab", np.bytes_("ab")),
112+
(FixedLengthASCII(length=4), "abcd", np.bytes_("abcd")),
113+
)
114+
item_size_params = (
115+
FixedLengthASCII(length=0),
116+
FixedLengthASCII(length=4),
117+
FixedLengthASCII(length=10),
118+
)
119+
120+
121+
class TestFixedLengthUTF32(_TestZDType):
122+
test_cls = FixedLengthUTF32
123+
valid_dtype = (np.dtype(">U10"), np.dtype("<U10"))
124+
invalid_dtype = (
125+
np.dtype(np.int8),
126+
np.dtype(np.float64),
127+
np.dtype("|S10"),
128+
)
129+
valid_json_v2 = (">U10", "<U10")
130+
valid_json_v3 = ({"name": "numpy.fixed_length_utf32", "configuration": {"length_bytes": 320}},)
131+
invalid_json_v2 = (
132+
"|U",
133+
"|S10",
134+
"|f8",
135+
)
136+
invalid_json_v3 = (
137+
{"name": "numpy.fixed_length_utf32", "configuration": {"length_bits": 0}},
138+
{"name": "numpy.fixed_length_utf32", "configuration": {"length_bits": "invalid"}},
139+
)
140+
141+
scalar_v2_params = ((FixedLengthUTF32(length=0), ""), (FixedLengthUTF32(length=2), "hi"))
142+
scalar_v3_params = (
143+
(FixedLengthUTF32(length=0), ""),
144+
(FixedLengthUTF32(length=2), "hi"),
145+
(FixedLengthUTF32(length=4), "hihi"),
146+
)
147+
148+
cast_value_params = (
149+
(FixedLengthUTF32(length=0), "", np.str_("")),
150+
(FixedLengthUTF32(length=2), "hi", np.str_("hi")),
151+
(FixedLengthUTF32(length=4), "hihi", np.str_("hihi")),
152+
)
153+
item_size_params = (
154+
FixedLengthUTF32(length=0),
155+
FixedLengthUTF32(length=4),
156+
FixedLengthUTF32(length=10),
157+
)

tests/test_dtype/test_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def scalar_equals(self, scalar1: object, scalar2: object) -> bool:
9292
return scalar1 == scalar2
9393

9494
def test_check_dtype_valid(self, valid_dtype: object) -> None:
95-
assert self.test_cls.check_dtype(valid_dtype) # type: ignore[arg-type]
95+
assert self.test_cls.check_dtype(valid_dtype)
9696

9797
def test_check_dtype_invalid(self, invalid_dtype: object) -> None:
9898
assert not self.test_cls.check_dtype(invalid_dtype) # type: ignore[arg-type]

0 commit comments

Comments
 (0)