|
14 | 14 | get_cached_file_path, |
15 | 15 | get_temp_directory, |
16 | 16 | get_url_hash, |
17 | | - paths_with_offsets, |
18 | 17 | ) |
19 | 18 |
|
20 | 19 |
|
@@ -287,119 +286,3 @@ def test_works_with_none_url(self): |
287 | 286 | temp_dir = os.path.dirname(file_path) |
288 | 287 | if os.path.exists(temp_dir): |
289 | 288 | os.rmdir(temp_dir) |
290 | | - |
291 | | - |
292 | | -class TestPathsWithOffsets: |
293 | | - """Tests for paths_with_offsets function.""" |
294 | | - |
295 | | - def test_returns_empty_list_for_empty_directory(self, tmp_path): |
296 | | - """Test that returns empty list when no matching files.""" |
297 | | - result = paths_with_offsets("prefix", "mp3", str(tmp_path)) |
298 | | - assert result == [] |
299 | | - |
300 | | - def test_finds_files_with_offsets(self, tmp_path): |
301 | | - """Test that finds files with numeric offsets.""" |
302 | | - # Create test files |
303 | | - (tmp_path / "audio_0.mp3").touch() |
304 | | - (tmp_path / "audio_5000.mp3").touch() |
305 | | - (tmp_path / "audio_10000.mp3").touch() |
306 | | - |
307 | | - result = paths_with_offsets("audio", "mp3", str(tmp_path)) |
308 | | - |
309 | | - assert len(result) == 3 |
310 | | - assert ("audio_0.mp3", 0) in result |
311 | | - assert ("audio_5000.mp3", 5000) in result |
312 | | - assert ("audio_10000.mp3", 10000) in result |
313 | | - |
314 | | - def test_returns_sorted_list(self, tmp_path): |
315 | | - """Test that returns files in sorted order by numeric offset.""" |
316 | | - # Create files in random order |
317 | | - (tmp_path / "seg_10000.wav").touch() |
318 | | - (tmp_path / "seg_0.wav").touch() |
319 | | - (tmp_path / "seg_5000.wav").touch() |
320 | | - |
321 | | - result = paths_with_offsets("seg", "wav", str(tmp_path)) |
322 | | - |
323 | | - # Should be sorted numerically by offset, not alphabetically |
324 | | - assert result[0] == ("seg_0.wav", 0) |
325 | | - assert result[1] == ("seg_5000.wav", 5000) |
326 | | - assert result[2] == ("seg_10000.wav", 10000) |
327 | | - |
328 | | - def test_ignores_non_matching_files(self, tmp_path): |
329 | | - """Test that ignores files that don't match pattern.""" |
330 | | - (tmp_path / "audio_0.mp3").touch() |
331 | | - (tmp_path / "audio_5000.mp3").touch() |
332 | | - (tmp_path / "other_file.mp3").touch() |
333 | | - (tmp_path / "audio.mp3").touch() |
334 | | - (tmp_path / "audio_abc.mp3").touch() |
335 | | - |
336 | | - result = paths_with_offsets("audio", "mp3", str(tmp_path)) |
337 | | - |
338 | | - assert len(result) == 2 |
339 | | - assert all("audio_" in path for path, _ in result) |
340 | | - |
341 | | - def test_matches_different_prefixes(self, tmp_path): |
342 | | - """Test matching with different prefixes.""" |
343 | | - (tmp_path / "video_0.mp4").touch() |
344 | | - (tmp_path / "audio_0.mp3").touch() |
345 | | - |
346 | | - video_result = paths_with_offsets("video", "mp4", str(tmp_path)) |
347 | | - audio_result = paths_with_offsets("audio", "mp3", str(tmp_path)) |
348 | | - |
349 | | - assert len(video_result) == 1 |
350 | | - assert len(audio_result) == 1 |
351 | | - assert video_result[0][0] == "video_0.mp4" |
352 | | - assert audio_result[0][0] == "audio_0.mp3" |
353 | | - |
354 | | - def test_matches_different_formats(self, tmp_path): |
355 | | - """Test matching with different file formats.""" |
356 | | - (tmp_path / "seg_0.mp3").touch() |
357 | | - (tmp_path / "seg_0.wav").touch() |
358 | | - (tmp_path / "seg_0.srt").touch() |
359 | | - |
360 | | - mp3_result = paths_with_offsets("seg", "mp3", str(tmp_path)) |
361 | | - wav_result = paths_with_offsets("seg", "wav", str(tmp_path)) |
362 | | - srt_result = paths_with_offsets("seg", "srt", str(tmp_path)) |
363 | | - |
364 | | - assert len(mp3_result) == 1 |
365 | | - assert len(wav_result) == 1 |
366 | | - assert len(srt_result) == 1 |
367 | | - |
368 | | - def test_handles_large_offsets(self, tmp_path): |
369 | | - """Test handling of large offset numbers.""" |
370 | | - (tmp_path / "seg_999999999.mp3").touch() |
371 | | - |
372 | | - result = paths_with_offsets("seg", "mp3", str(tmp_path)) |
373 | | - |
374 | | - assert len(result) == 1 |
375 | | - assert result[0][1] == 999999999 |
376 | | - |
377 | | - def test_uses_current_directory_by_default(self): |
378 | | - """Test that uses current directory when no directory specified.""" |
379 | | - original_dir = os.getcwd() |
380 | | - temp_dir = tempfile.mkdtemp() |
381 | | - |
382 | | - try: |
383 | | - os.chdir(temp_dir) |
384 | | - # Create test file |
385 | | - with open("test_0.txt", "w") as f: |
386 | | - f.write("test") |
387 | | - |
388 | | - result = paths_with_offsets("test", "txt") |
389 | | - assert len(result) == 1 |
390 | | - assert result[0][0] == "test_0.txt" |
391 | | - |
392 | | - finally: |
393 | | - os.chdir(original_dir) |
394 | | - shutil.rmtree(temp_dir) |
395 | | - |
396 | | - def test_offset_as_int(self, tmp_path): |
397 | | - """Test that offset is returned as int for proper numeric sorting.""" |
398 | | - (tmp_path / "audio_12345.mp3").touch() |
399 | | - |
400 | | - result = paths_with_offsets("audio", "mp3", str(tmp_path)) |
401 | | - |
402 | | - assert len(result) == 1 |
403 | | - path, offset = result[0] |
404 | | - assert isinstance(offset, int) |
405 | | - assert offset == 12345 |
0 commit comments