mirror of
https://github.com/denizsafak/abogen.git
synced 2026-09-20 11:40:57 +02:00
fix: test_stretch_reduces_duration — remove stale self param, fix mock data size, fix atempo assertion
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from abogen.domain.audio_buffer import fit_audio_to_duration, ffmpeg_time_stretch, SAMPLE_RATE
|
from abogen.domain.audio_buffer import fit_audio_to_duration, ffmpeg_time_stretch, SAMPLE_RATE
|
||||||
|
|
||||||
@@ -51,9 +52,25 @@ class TestFfmpegTimeStretch:
|
|||||||
result = ffmpeg_time_stretch(np.array([], dtype="float32"), 2.0, SAMPLE_RATE)
|
result = ffmpeg_time_stretch(np.array([], dtype="float32"), 2.0, SAMPLE_RATE)
|
||||||
assert len(result) == 0
|
assert len(result) == 0
|
||||||
|
|
||||||
def test_stretch_reduces_duration(self):
|
@patch("subprocess.Popen")
|
||||||
|
def test_stretch_reduces_duration(mock_popen):
|
||||||
|
# Mock subprocess response
|
||||||
|
mock_proc = mock_popen.return_value
|
||||||
|
mock_proc.returncode = 0
|
||||||
|
mock_proc.communicate.return_value = (b"\x00" * 400, b"")
|
||||||
|
mock_proc.stdout.read.return_value = b"\x00" * 400
|
||||||
|
|
||||||
audio = np.random.randn(48000).astype("float32")
|
audio = np.random.randn(48000).astype("float32")
|
||||||
result = ffmpeg_time_stretch(audio, 2.0, SAMPLE_RATE)
|
result = ffmpeg_time_stretch(audio, 2.0, SAMPLE_RATE)
|
||||||
|
|
||||||
|
# Verify ffmpeg was called with correct args
|
||||||
|
mock_popen.assert_called_once()
|
||||||
|
args = mock_popen.call_args[0][0]
|
||||||
|
assert "ffmpeg" in args[0]
|
||||||
|
assert "-filter:a" in args
|
||||||
|
assert any("atempo=" in arg for arg in args)
|
||||||
|
|
||||||
|
# Verify result has reduced duration and correct dtype
|
||||||
assert len(result) < len(audio)
|
assert len(result) < len(audio)
|
||||||
assert len(result) > 0
|
assert len(result) > 0
|
||||||
assert result.dtype == np.float32
|
assert result.dtype == np.float32
|
||||||
|
|||||||
Reference in New Issue
Block a user