@@ -15,7 +15,7 @@ class TestNullTerminatedBytes(BaseTestZDType):
1515 np .dtype ("|U10" ),
1616 )
1717 valid_json_v2 = (
18- {"name" : "|S0 " , "object_codec_id" : None },
18+ {"name" : "|S1 " , "object_codec_id" : None },
1919 {"name" : "|S2" , "object_codec_id" : None },
2020 {"name" : "|S4" , "object_codec_id" : None },
2121 )
@@ -31,22 +31,22 @@ class TestNullTerminatedBytes(BaseTestZDType):
3131 )
3232
3333 scalar_v2_params = (
34- (NullTerminatedBytes (length = 0 ), "" ),
34+ (NullTerminatedBytes (length = 1 ), "MA== " ),
3535 (NullTerminatedBytes (length = 2 ), "YWI=" ),
3636 (NullTerminatedBytes (length = 4 ), "YWJjZA==" ),
3737 )
3838 scalar_v3_params = (
39- (NullTerminatedBytes (length = 0 ), "" ),
39+ (NullTerminatedBytes (length = 1 ), "MA== " ),
4040 (NullTerminatedBytes (length = 2 ), "YWI=" ),
4141 (NullTerminatedBytes (length = 4 ), "YWJjZA==" ),
4242 )
4343 cast_value_params = (
44- (NullTerminatedBytes (length = 0 ), "" , np .bytes_ ("" )),
44+ (NullTerminatedBytes (length = 1 ), "" , np .bytes_ ("" )),
4545 (NullTerminatedBytes (length = 2 ), "ab" , np .bytes_ ("ab" )),
4646 (NullTerminatedBytes (length = 4 ), "abcdefg" , np .bytes_ ("abcd" )),
4747 )
4848 item_size_params = (
49- NullTerminatedBytes (length = 0 ),
49+ NullTerminatedBytes (length = 1 ),
5050 NullTerminatedBytes (length = 4 ),
5151 NullTerminatedBytes (length = 10 ),
5252 )
@@ -62,7 +62,7 @@ class TestRawBytes(BaseTestZDType):
6262 )
6363 valid_json_v2 = ({"name" : "|V10" , "object_codec_id" : None },)
6464 valid_json_v3 = (
65- {"name" : "raw_bytes" , "configuration" : {"length_bytes" : 0 }},
65+ {"name" : "raw_bytes" , "configuration" : {"length_bytes" : 1 }},
6666 {"name" : "raw_bytes" , "configuration" : {"length_bytes" : 8 }},
6767 )
6868
@@ -77,22 +77,22 @@ class TestRawBytes(BaseTestZDType):
7777 )
7878
7979 scalar_v2_params = (
80- (RawBytes (length = 0 ), "" ),
80+ (RawBytes (length = 1 ), "AA== " ),
8181 (RawBytes (length = 2 ), "YWI=" ),
8282 (RawBytes (length = 4 ), "YWJjZA==" ),
8383 )
8484 scalar_v3_params = (
85- (RawBytes (length = 0 ), "" ),
85+ (RawBytes (length = 1 ), "AA== " ),
8686 (RawBytes (length = 2 ), "YWI=" ),
8787 (RawBytes (length = 4 ), "YWJjZA==" ),
8888 )
8989 cast_value_params = (
90- (RawBytes (length = 0 ), b"" , np .void (b"" )),
90+ (RawBytes (length = 1 ), b"\x00 " , np .void (b"\x00 " )),
9191 (RawBytes (length = 2 ), b"ab" , np .void (b"ab" )),
9292 (RawBytes (length = 4 ), b"abcd" , np .void (b"abcd" )),
9393 )
9494 item_size_params = (
95- RawBytes (length = 0 ),
95+ RawBytes (length = 1 ),
9696 RawBytes (length = 4 ),
9797 RawBytes (length = 10 ),
9898 )
@@ -152,3 +152,14 @@ def test_unstable_dtype_warning(
152152 """
153153 with pytest .raises (UnstableSpecificationWarning ):
154154 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