dnd-music-console/test/test_transcoder.py

44 lines
1.1 KiB
Python
Raw Normal View History

2024-03-10 11:45:24 -07:00
from unittest.mock import MagicMock
import ffmpeg
import pytest
2024-03-26 00:51:16 -07:00
from croaker import playlist, transcoder
2024-03-10 11:45:24 -07:00
2024-06-02 22:37:14 -07:00
@pytest.fixture
def mock_mp3decoder(monkeypatch):
def read(stream):
return stream.read()
2024-06-02 23:57:37 -07:00
monkeypatch.setattr(transcoder, "MP3Decoder", MagicMock(**{"__enter__.return_value.read": read}))
2024-06-02 22:37:14 -07:00
@pytest.mark.xfail
2024-03-26 00:51:16 -07:00
@pytest.mark.parametrize(
"suffix, expected",
[
(".mp3", b"_theme.mp3\n"),
(".foo", b"transcoding!\n"),
],
)
2024-06-02 22:37:14 -07:00
def test_transcoder_open(monkeypatch, mock_mp3decoder, suffix, expected):
2024-03-26 00:51:16 -07:00
monkeypatch.setattr(
transcoder,
"ffmpeg",
MagicMock(
spec=ffmpeg,
**{
"input.return_value."
"output.return_value."
"global_args.return_value."
"compile.return_value": ["echo", "transcoding!"],
},
),
)
2024-03-10 11:45:24 -07:00
2024-03-26 00:51:16 -07:00
pl = playlist.Playlist(name="test_playlist")
2024-03-10 11:45:24 -07:00
track = [t for t in pl.tracks if t.suffix == suffix][0]
with transcoder.open(track) as handle:
assert handle.read() == expected