1717import soxr
1818
1919
20- @pytest .mark .xfail (raises = ValueError , strict = True )
21- @pytest .mark .parametrize ('in_rate, out_rate' , [(100 , 0 ), (100 , - 1 ), (0 , 100 ), (- 1 , 100 )])
20+ @pytest .mark .parametrize ('in_rate, out_rate' , [(100 , 0 ), (50 , - 1 ), (0 , 100.5 ), (- 1.5 , 100 )])
2221def test_bad_sr (in_rate , out_rate ):
2322 # test invalid samplerate
2423 x = np .zeros (100 )
25- soxr .resample (x , in_rate , out_rate )
24+ with pytest .raises (ValueError ):
25+ soxr .resample (x , in_rate , out_rate )
2626
2727
2828@pytest .mark .parametrize ('dtype' , [np .float32 , np .float64 , np .int16 , np .int32 ])
@@ -35,12 +35,12 @@ def test_dtype(dtype):
3535 assert x .dtype == y .dtype
3636
3737
38- @pytest .mark .xfail (raises = (TypeError , ValueError ), strict = True )
3938@pytest .mark .parametrize ('dtype' , [np .complex64 , np .complex128 , np .int8 , np .int64 ])
4039def test_bad_dtype (dtype ):
4140 # test invalid dtype
4241 x = np .zeros (100 , dtype = dtype )
43- soxr .resample (x , 100 , 200 )
42+ with pytest .raises ((TypeError , ValueError )):
43+ soxr .resample (x , 100 , 200 )
4444
4545
4646@pytest .mark .parametrize ('in_rate, out_rate' , [(44100 , 32000 ), (32000 , 44100 )])
@@ -176,11 +176,10 @@ def test_int_sine(in_rate, out_rate, dtype):
176176 assert np .allclose (y_oneshot , y_split , atol = 2 )
177177
178178
179- @pytest .mark .parametrize ('num_task' , [2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 12 , 17 , 32 ])
180- @pytest .mark .parametrize ('dtype' , ['float32' , np .int16 ])
181- def test_multithread (num_task , dtype ):
179+ @pytest .mark .parametrize ('num_task' , [2 , 3 , 5 , 7 , 9 , 12 , 17 , 32 ])
180+ def test_multithread (num_task ):
182181 # test multi-thread operation
183- x = ( np .random .randn (75999 , 2 ) * 5000 ) .astype (dtype )
182+ x = np .random .randn (75999 , 2 ).astype (np . float32 )
184183
185184 with ThreadPoolExecutor () as p :
186185 results = p .map (
@@ -190,3 +189,23 @@ def test_multithread(num_task, dtype):
190189 results = list (results )
191190
192191 assert np .all (results [- 2 ] == results [- 1 ])
192+
193+
194+ @pytest .mark .parametrize ('num_task' , [2 , 3 , 4 , 6 , 8 , 15 , 18 , 24 ])
195+ def test_mt_dither (num_task ):
196+ # test dithering randomness and multi-thread operation
197+ x = (np .random .randn (70001 , 2 ) * 5000 ).astype (np .int16 )
198+
199+ with ThreadPoolExecutor () as p :
200+ results = p .map (
201+ partial (soxr .resample , in_rate = 32000 , out_rate = 48000 ),
202+ [x ] * num_task
203+ )
204+ results = list (results )
205+
206+ assert np .allclose (results [0 ], results [1 ], atol = 2 )
207+
208+ try :
209+ assert np .all (results [- 2 ] == results [- 1 ])
210+ except AssertionError :
211+ pytest .xfail ("Random dithering seed used. May produce slightly different result when using int I/O." )
0 commit comments