558fa23da4
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
96 lines
2.8 KiB
Python
96 lines
2.8 KiB
Python
import tempfile, os
|
|
from main import build_export_path, format_time, build_ffmpeg_command
|
|
from main import _normalize_filename, ProcessedDB
|
|
|
|
|
|
def test_build_export_path_first():
|
|
assert build_export_path("/out", "clip", 1) == "/out/clip_001.mp4"
|
|
|
|
def test_build_export_path_counter():
|
|
assert build_export_path("/out", "clip", 42) == "/out/clip_042.mp4"
|
|
|
|
def test_build_export_path_deep_counter():
|
|
assert build_export_path("/out", "shot", 999) == "/out/shot_999.mp4"
|
|
|
|
def test_format_time_seconds():
|
|
assert format_time(0.0) == "0:00.0"
|
|
|
|
def test_format_time_minutes():
|
|
assert format_time(75.3) == "1:15.2"
|
|
|
|
def test_format_time_rounding():
|
|
assert format_time(61.05) == "1:01.0"
|
|
|
|
def test_format_time_no_sixty_rollover():
|
|
assert format_time(59.95) == "0:59.9"
|
|
|
|
|
|
def test_ffmpeg_command():
|
|
cmd = build_ffmpeg_command("/in/video.mp4", 12.5, "/out/clip_001.mp4")
|
|
assert cmd[0] == "ffmpeg"
|
|
assert "-y" in cmd
|
|
assert "-ss" in cmd
|
|
assert str(12.5) in cmd
|
|
assert "-t" in cmd
|
|
assert "8" in cmd
|
|
assert cmd[-1] == "/out/clip_001.mp4"
|
|
|
|
|
|
# --- _normalize_filename ---
|
|
|
|
def test_normalize_strips_extension():
|
|
assert _normalize_filename("clip.mp4") == "clip"
|
|
|
|
def test_normalize_strips_resolution():
|
|
assert _normalize_filename("clip_2160p.mp4") == "clip"
|
|
|
|
def test_normalize_strips_1080p():
|
|
assert _normalize_filename("clip_1080p.mkv") == "clip"
|
|
|
|
def test_normalize_strips_multiple_tags():
|
|
assert _normalize_filename("show_1080p_HDR.mkv") == "show"
|
|
|
|
def test_normalize_lowercases():
|
|
assert _normalize_filename("MyVideo_4K.mp4") == "myvideo"
|
|
|
|
def test_normalize_collapses_separators():
|
|
assert _normalize_filename("my__video--2160p.mp4") == "my_video"
|
|
|
|
|
|
# --- ProcessedDB ---
|
|
|
|
def test_db_add_and_find_exact():
|
|
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
|
|
path = f.name
|
|
try:
|
|
db = ProcessedDB(path)
|
|
db.add("video.mp4")
|
|
assert db.find_similar("video.mp4") == "video.mp4"
|
|
finally:
|
|
os.unlink(path)
|
|
|
|
def test_db_find_similar_resolution_variant():
|
|
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
|
|
path = f.name
|
|
try:
|
|
db = ProcessedDB(path)
|
|
db.add("episode_s01e01_2160p.mkv")
|
|
assert db.find_similar("episode_s01e01_1080p.mkv") == "episode_s01e01_2160p.mkv"
|
|
finally:
|
|
os.unlink(path)
|
|
|
|
def test_db_find_similar_no_match():
|
|
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
|
|
path = f.name
|
|
try:
|
|
db = ProcessedDB(path)
|
|
db.add("alpha.mp4")
|
|
assert db.find_similar("completely_different_zzzz.mp4") is None
|
|
finally:
|
|
os.unlink(path)
|
|
|
|
def test_db_disabled_survives_bad_path():
|
|
db = ProcessedDB("/no/such/directory/8cut.db")
|
|
db.add("x.mp4") # must not raise
|
|
assert db.find_similar("x.mp4") is None # gracefully returns None
|