@@ -15,7 +15,7 @@ class TestNullTerminatedBytes(BaseTestZDType):
15
15
np .dtype ("|U10" ),
16
16
)
17
17
valid_json_v2 = (
18
- {"name" : "|S0 " , "object_codec_id" : None },
18
+ {"name" : "|S1 " , "object_codec_id" : None },
19
19
{"name" : "|S2" , "object_codec_id" : None },
20
20
{"name" : "|S4" , "object_codec_id" : None },
21
21
)
@@ -31,22 +31,22 @@ class TestNullTerminatedBytes(BaseTestZDType):
31
31
)
32
32
33
33
scalar_v2_params = (
34
- (NullTerminatedBytes (length = 0 ), "" ),
34
+ (NullTerminatedBytes (length = 1 ), "MA== " ),
35
35
(NullTerminatedBytes (length = 2 ), "YWI=" ),
36
36
(NullTerminatedBytes (length = 4 ), "YWJjZA==" ),
37
37
)
38
38
scalar_v3_params = (
39
- (NullTerminatedBytes (length = 0 ), "" ),
39
+ (NullTerminatedBytes (length = 1 ), "MA== " ),
40
40
(NullTerminatedBytes (length = 2 ), "YWI=" ),
41
41
(NullTerminatedBytes (length = 4 ), "YWJjZA==" ),
42
42
)
43
43
cast_value_params = (
44
- (NullTerminatedBytes (length = 0 ), "" , np .bytes_ ("" )),
44
+ (NullTerminatedBytes (length = 1 ), "" , np .bytes_ ("" )),
45
45
(NullTerminatedBytes (length = 2 ), "ab" , np .bytes_ ("ab" )),
46
46
(NullTerminatedBytes (length = 4 ), "abcdefg" , np .bytes_ ("abcd" )),
47
47
)
48
48
item_size_params = (
49
- NullTerminatedBytes (length = 0 ),
49
+ NullTerminatedBytes (length = 1 ),
50
50
NullTerminatedBytes (length = 4 ),
51
51
NullTerminatedBytes (length = 10 ),
52
52
)
@@ -62,7 +62,7 @@ class TestRawBytes(BaseTestZDType):
62
62
)
63
63
valid_json_v2 = ({"name" : "|V10" , "object_codec_id" : None },)
64
64
valid_json_v3 = (
65
- {"name" : "raw_bytes" , "configuration" : {"length_bytes" : 0 }},
65
+ {"name" : "raw_bytes" , "configuration" : {"length_bytes" : 1 }},
66
66
{"name" : "raw_bytes" , "configuration" : {"length_bytes" : 8 }},
67
67
)
68
68
@@ -77,22 +77,22 @@ class TestRawBytes(BaseTestZDType):
77
77
)
78
78
79
79
scalar_v2_params = (
80
- (RawBytes (length = 0 ), "" ),
80
+ (RawBytes (length = 1 ), "AA== " ),
81
81
(RawBytes (length = 2 ), "YWI=" ),
82
82
(RawBytes (length = 4 ), "YWJjZA==" ),
83
83
)
84
84
scalar_v3_params = (
85
- (RawBytes (length = 0 ), "" ),
85
+ (RawBytes (length = 1 ), "AA== " ),
86
86
(RawBytes (length = 2 ), "YWI=" ),
87
87
(RawBytes (length = 4 ), "YWJjZA==" ),
88
88
)
89
89
cast_value_params = (
90
- (RawBytes (length = 0 ), b"" , np .void (b"" )),
90
+ (RawBytes (length = 1 ), b"\x00 " , np .void (b"\x00 " )),
91
91
(RawBytes (length = 2 ), b"ab" , np .void (b"ab" )),
92
92
(RawBytes (length = 4 ), b"abcd" , np .void (b"abcd" )),
93
93
)
94
94
item_size_params = (
95
- RawBytes (length = 0 ),
95
+ RawBytes (length = 1 ),
96
96
RawBytes (length = 4 ),
97
97
RawBytes (length = 10 ),
98
98
)
@@ -152,3 +152,14 @@ def test_unstable_dtype_warning(
152
152
"""
153
153
with pytest .raises (UnstableSpecificationWarning ):
154
154
zdtype .to_json (zarr_format = 3 )
155
+
156
+
157
+ @pytest .mark .parametrize ("zdtype_cls" , [NullTerminatedBytes , RawBytes ])
158
+ def test_invalid_size (zdtype_cls : type [NullTerminatedBytes ] | type [RawBytes ]) -> None :
159
+ """
160
+ Test that it's impossible to create a data type that has no length
161
+ """
162
+ length = 0
163
+ msg = f"length must be >= 1, got { length } ."
164
+ with pytest .raises (ValueError , match = msg ):
165
+ zdtype_cls (length = length )
0 commit comments