diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000..e9ec787 --- /dev/null +++ b/test/conftest.py @@ -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') diff --git a/test/test_playlist.py b/test/test_playlist.py index 7277530..83c1c20 100644 --- a/test/test_playlist.py +++ b/test/test_playlist.py @@ -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') diff --git a/test/test_transcoder.py b/test/test_transcoder.py new file mode 100644 index 0000000..a098c11 --- /dev/null +++ b/test/test_transcoder.py @@ -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