adding transcoder test coverage

This commit is contained in:
evilchili 2024-03-10 11:45:24 -07:00
parent d97faca0f7
commit 205177dca3
3 changed files with 35 additions and 7 deletions

10
test/conftest.py Normal file
View File

@ -0,0 +1,10 @@
from pathlib import Path
import pytest
@pytest.fixture(autouse=True)
def mock_env(monkeypatch):
fixtures = Path(__file__).parent / 'fixtures'
monkeypatch.setenv('CROAKER_ROOT', str(fixtures))
monkeypatch.setenv('MEDIA_GLOB', '*.mp3,*.foo,*.bar')

View File

@ -1,4 +1,3 @@
from pathlib import Path
from unittest.mock import MagicMock
import pytest
@ -6,12 +5,6 @@ import pytest
import croaker.playlist
import croaker.path
@pytest.fixture(autouse=True)
def mock_env(monkeypatch):
fixtures = Path(__file__).parent / 'fixtures'
monkeypatch.setenv('CROAKER_ROOT', str(fixtures))
monkeypatch.setenv('MEDIA_GLOB', '*.mp3,*.foo,*.bar')
def test_playlist_loading():
pl = croaker.playlist.Playlist(name='test_playlist')

25
test/test_transcoder.py Normal file
View File

@ -0,0 +1,25 @@
from unittest.mock import MagicMock
import ffmpeg
import pytest
from croaker import playlist
from croaker import transcoder
@pytest.mark.parametrize('suffix, expected', [
('.mp3', b''),
('.foo', b'transcoding!\n'),
])
def test_transcoder_open(monkeypatch, suffix, expected):
monkeypatch.setattr(transcoder, 'ffmpeg', MagicMock(spec=ffmpeg, **{
'input.return_value.'
'output.return_value.'
'global_args.return_value.'
'compile.return_value': ['echo', 'transcoding!'],
}))
pl = playlist.Playlist(name='test_playlist')
track = [t for t in pl.tracks if t.suffix == suffix][0]
with transcoder.open(track) as handle:
assert handle.read() == expected