@@ -254,6 +254,7 @@ def test_analyze_with_custom_species_list(mock_analyze_file: MagicMock, mock_set
254254 _ , kwargs = mock_set_params .call_args
255255 assert kwargs ["slist" ] == species_list
256256
257+
257258@patch ("birdnet_analyzer.utils.ensure_model_exists" )
258259def test_analyze_with_negative_speed (setup_test_environment ):
259260 """Test analyzing with negative speed."""
@@ -267,6 +268,7 @@ def test_analyze_with_negative_speed(setup_test_environment):
267268 with pytest .raises (ValueError , match = "Audio speed must be a positive value." ):
268269 analyze (soundscape_path , env ["output_dir" ], audio_speed = - 1.0 , top_n = 1 , min_conf = 0 )
269270
271+
270272@patch ("birdnet_analyzer.utils.ensure_model_exists" )
271273def test_analyze_with_zero_speed (setup_test_environment ):
272274 """Test analyzing with zero speed."""
@@ -280,6 +282,7 @@ def test_analyze_with_zero_speed(setup_test_environment):
280282 with pytest .raises (ValueError , match = "Audio speed must be a positive value." ):
281283 analyze (soundscape_path , env ["output_dir" ], audio_speed = 0.0 , top_n = 1 , min_conf = 0 )
282284
285+
283286@patch ("birdnet_analyzer.utils.ensure_model_exists" )
284287def test_analyze_with_invalid_audio_speed (setup_test_environment ):
285288 """Test analyzing with invalid audio speed."""
@@ -293,6 +296,7 @@ def test_analyze_with_invalid_audio_speed(setup_test_environment):
293296 with pytest .raises (ValueError , match = "Audio speed must be a numeric value." ):
294297 analyze (soundscape_path , env ["output_dir" ], audio_speed = "fast" , top_n = 1 , min_conf = 0 )
295298
299+
296300@patch ("birdnet_analyzer.utils.ensure_model_exists" )
297301def test_analyze_with_negative_overlap (setup_test_environment ):
298302 """Test analyzing with invalid overlap."""
@@ -306,6 +310,7 @@ def test_analyze_with_negative_overlap(setup_test_environment):
306310 with pytest .raises (ValueError , match = "Overlap must be a non-negative value." ):
307311 analyze (soundscape_path , env ["output_dir" ], audio_speed = 1.0 , top_n = 1 , overlap = - 1 )
308312
313+
309314@patch ("birdnet_analyzer.utils.ensure_model_exists" )
310315def test_analyze_with_invalid_overlap (setup_test_environment ):
311316 """Test analyzing with invalid overlap."""
@@ -319,6 +324,7 @@ def test_analyze_with_invalid_overlap(setup_test_environment):
319324 with pytest .raises (ValueError , match = "Overlap must be a numeric value." ):
320325 analyze (soundscape_path , env ["output_dir" ], audio_speed = 1.0 , top_n = 1 , overlap = "high" )
321326
327+
322328@patch ("birdnet_analyzer.utils.ensure_model_exists" )
323329def test_analyze_with_too_high_overlap (setup_test_environment ):
324330 """Test analyzing with too high overlap."""
@@ -332,9 +338,10 @@ def test_analyze_with_too_high_overlap(setup_test_environment):
332338 with pytest .raises (ValueError , match = f"Overlap must be less than { cfg .SIG_LENGTH } seconds." ):
333339 analyze (soundscape_path , env ["output_dir" ], audio_speed = 1.0 , top_n = 1 , overlap = 3.0 )
334340
341+
335342@pytest .mark .parametrize (
336343 ("audio_speed" , "overlap" ),
337- [(10 , 1 ), (5 , 2 ), (5 , 0 ), (0.1 , 1 ), (0.2 , 0 )],
344+ [(10 , 1 ), (5 , 2 ), (5 , 0 ), (0.1 , 1 ), (0.2 , 0 ), ( 0.3 , 0.7 ) ],
338345)
339346def test_analyze_with_speed_up_and_overlap (setup_test_environment , audio_speed , overlap ):
340347 """Test analyzing with speed up."""
@@ -344,9 +351,10 @@ def test_analyze_with_speed_up_and_overlap(setup_test_environment, audio_speed,
344351
345352 assert os .path .exists (soundscape_path ), "Soundscape file does not exist"
346353 file_length = 120
347- step_size = round (3 * audio_speed - overlap * audio_speed , 1 )
348- expected_start_timestamps = [e / 10 for e in range (0 , int (file_length * 10 ), int (step_size * 10 ))]
349- expected_end_timestamps = [e / 10 for e in range (int (3 * audio_speed * 10 ), int (file_length ) * 10 + 1 , int (step_size * 10 ))]
354+ precision = 100
355+ step_size = round ((3 - overlap ) * audio_speed , precision // 10 )
356+ expected_start_timestamps = [e / precision for e in range (0 , int (file_length * precision ), int (step_size * precision ))]
357+ expected_end_timestamps = [e / precision for e in range (round (3 * audio_speed * precision ), int (file_length * precision ) + 1 , int (step_size * precision ))]
350358
351359 while len (expected_end_timestamps ) < len (expected_start_timestamps ):
352360 if file_length - expected_start_timestamps [- 1 ] >= 1 * audio_speed :
0 commit comments