Skip to content
Snippets Groups Projects
Commit c49b8eec authored by interfect's avatar interfect
Browse files

Test transcoding from Opus and other formats

parent 9ac829fa
No related branches found
No related tags found
No related merge requests found
Pipeline #13160 failed
import os import os
import pathlib import pathlib
import pytest import pytest
import tempfile
from funkwhale_api.music import utils from funkwhale_api.music import utils
...@@ -28,6 +29,7 @@ def test_guess_mimetype_try_using_extension_if_fail(wrong, factories, mocker): ...@@ -28,6 +29,7 @@ def test_guess_mimetype_try_using_extension_if_fail(wrong, factories, mocker):
("sample.flac", {"bitrate": 1608000, "length": 0.001}), ("sample.flac", {"bitrate": 1608000, "length": 0.001}),
("test.mp3", {"bitrate": 8000, "length": 267.70285714285717}), ("test.mp3", {"bitrate": 8000, "length": 267.70285714285717}),
("test.ogg", {"bitrate": 112000, "length": 1}), ("test.ogg", {"bitrate": 112000, "length": 1}),
("test.opus", {"bitrate": 112000, "length": 1})
], ],
) )
def test_get_audio_file_data(name, expected): def test_get_audio_file_data(name, expected):
...@@ -109,3 +111,21 @@ def test_get_dirs_and_files(path, expected, tmpdir): ...@@ -109,3 +111,21 @@ def test_get_dirs_and_files(path, expected, tmpdir):
(root_path / "System" / "file.ogg").touch() (root_path / "System" / "file.ogg").touch()
assert utils.browse_dir(root_path, path) == expected assert utils.browse_dir(root_path, path) == expected
@pytest.mark.parametrize(
"name, expected",
[
("sample.flac", {"bitrate": 1608000, "length": 0.001}),
("test.mp3", {"bitrate": 8000, "length": 267.70285714285717}),
("test.ogg", {"bitrate": 112000, "length": 1}),
("test.opus", {"bitrate": 112000, "length": 1})
],
)
def test_transcode_file(name, expected):
path = pathlib.Path(os.path.join(DATA_DIR, name))
with tempfile.NamedTemporaryFile() as dest:
utils.transcode_file(path, pathlib.Path(dest.name))
with open(dest.name, "rb") as f:
result = utils.get_audio_file_data(f)
assert result == expected
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment