@@ -83,3 +83,72 @@ def decoder1(input, output, meta, schunk):
8383 assert np .array_equal (data , out )
8484
8585 blosc2 .remove_urlpath (urlpath )
86+
87+
88+ @pytest .mark .parametrize (
89+ "cparams, dparams" ,
90+ [
91+ ({"codec" : 163 , "nthreads" : 1 }, {"nthreads" : 4 }),
92+ ({"codec" : 163 , "nthreads" : 4 }, {"nthreads" : 1 }),
93+ ],
94+ )
95+ def test_pyucodecs_error (cparams , dparams ):
96+ chunk_len = 20 * 1000
97+ dtype = np .dtype (np .int32 )
98+
99+ def encoder1 (input , output , meta , schunk ):
100+ nd_input = input .view (dtype )
101+ if np .max (nd_input ) == np .min (nd_input ):
102+ output [0 : schunk .typesize ] = input [0 : schunk .typesize ]
103+ n = nd_input .size .to_bytes (4 , sys .byteorder )
104+ output [schunk .typesize : schunk .typesize + 4 ] = [n [i ] for i in range (4 )]
105+ return schunk .typesize + 4
106+ else :
107+ # memcpy
108+ return 0
109+
110+ def decoder1 (input , output , meta , schunk ):
111+ nd_input = input .view (np .int32 )
112+ nd_output = output .view (dtype )
113+ nd_output [0 : nd_input [1 ]] = [nd_input [0 ]] * nd_input [1 ]
114+ return nd_input [1 ] * schunk .typesize
115+
116+ if cparams ["codec" ] not in blosc2 .ucodecs_registry :
117+ blosc2 .register_codec ("codec3" , cparams ["codec" ], encoder1 , decoder1 )
118+
119+ nchunks = 2
120+ fill_value = 341
121+ data = np .full (chunk_len * nchunks , fill_value , dtype = dtype )
122+
123+ with pytest .raises (ValueError ):
124+ _ = blosc2 .SChunk (
125+ chunksize = chunk_len * dtype .itemsize ,
126+ data = data ,
127+ cparams = cparams ,
128+ dparams = dparams ,
129+ )
130+
131+
132+ @pytest .mark .parametrize (
133+ "cparams, dparams" ,
134+ [
135+ ({"codec" : 254 , "nthreads" : 1 }, {"nthreads" : 4 }),
136+ ({"codec" : 254 , "nthreads" : 4 }, {"nthreads" : 1 }),
137+ ],
138+ )
139+ def test_dynamic_ucodecs_error (cparams , dparams ):
140+ blosc2 .register_codec ("codec4" , cparams ["codec" ], None , None )
141+
142+ chunk_len = 100
143+ dtype = np .dtype (np .int32 )
144+ nchunks = 1
145+ fill_value = 341
146+ data = np .arange (chunk_len * nchunks , dtype = dtype )
147+
148+ with pytest .raises (RuntimeError ):
149+ schunk = blosc2 .SChunk (
150+ chunksize = chunk_len * dtype .itemsize ,
151+ data = data ,
152+ cparams = cparams ,
153+ dparams = dparams ,
154+ )
0 commit comments