feat: extract honors format picker + fade/normalize/gain edits
This commit is contained in:
@@ -308,3 +308,67 @@ def test_audio_toolbox_has_two_panes(win):
|
||||
assert win._btn_extract_audio in tb.findChildren(QPushButton)
|
||||
# Scan controls remain reachable.
|
||||
assert win._btn_scan in tb.findChildren(QPushButton)
|
||||
|
||||
|
||||
def test_extract_honors_format_and_edits(win, monkeypatch, tmp_path):
|
||||
import main as m
|
||||
import pytest
|
||||
win._file_path = "/x/video.mp4"
|
||||
win._cursor = 5.0
|
||||
win._spn_audio_len.setValue(4.0)
|
||||
win._cmb_audio_fmt.setCurrentIndex(win._cmb_audio_fmt.findData(".mp3"))
|
||||
win._spn_fade_in.setValue(0.5)
|
||||
win._chk_normalize.setChecked(True)
|
||||
|
||||
seen = {}
|
||||
class _Stop(Exception):
|
||||
pass
|
||||
def fake_cmd(inp, start, dur, out, filters=None):
|
||||
seen["out"] = out
|
||||
seen["filters"] = filters or []
|
||||
raise _Stop
|
||||
monkeypatch.setattr(m, "build_audio_clip_command", fake_cmd)
|
||||
|
||||
dialog = {}
|
||||
def fake_savedialog(parent, title, default_path, filt):
|
||||
dialog["default"] = default_path
|
||||
dialog["filter"] = filt
|
||||
return (str(tmp_path / "clip.mp3"), "")
|
||||
monkeypatch.setattr(m.QFileDialog, "getSaveFileName",
|
||||
staticmethod(fake_savedialog))
|
||||
|
||||
with pytest.raises(_Stop):
|
||||
win._on_extract_audio()
|
||||
|
||||
# Default filename used the picked format's extension, and that format leads the filter.
|
||||
assert dialog["default"].endswith(".mp3")
|
||||
assert dialog["filter"].startswith("MP3")
|
||||
# Output path + edit filters flowed into the command builder.
|
||||
assert seen["out"].endswith(".mp3")
|
||||
assert any("afade=t=in" in f for f in seen["filters"])
|
||||
assert "loudnorm" in seen["filters"]
|
||||
|
||||
|
||||
def test_extract_no_edits_passes_no_filters(win, monkeypatch, tmp_path):
|
||||
import main as m
|
||||
import pytest
|
||||
win._file_path = "/x/video.mp4"
|
||||
win._cursor = 5.0
|
||||
win._spn_audio_len.setValue(4.0)
|
||||
# all edit controls at default
|
||||
win._spn_fade_in.setValue(0.0)
|
||||
win._spn_fade_out.setValue(0.0)
|
||||
win._chk_normalize.setChecked(False)
|
||||
win._spn_gain.setValue(0.0)
|
||||
seen = {}
|
||||
class _Stop(Exception):
|
||||
pass
|
||||
def fake_cmd(inp, start, dur, out, filters=None):
|
||||
seen["filters"] = filters
|
||||
raise _Stop
|
||||
monkeypatch.setattr(m, "build_audio_clip_command", fake_cmd)
|
||||
monkeypatch.setattr(m.QFileDialog, "getSaveFileName",
|
||||
staticmethod(lambda *a, **k: (str(tmp_path / "c.wav"), "")))
|
||||
with pytest.raises(_Stop):
|
||||
win._on_extract_audio()
|
||||
assert seen["filters"] is None
|
||||
|
||||
Reference in New Issue
Block a user