Files
spleeter/tests/test_separator.py

56 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# coding: utf8
""" Unit testing for Separator class. """
__email__ = 'research@deezer.com'
__author__ = 'Deezer Research'
__license__ = 'MIT License'
import filecmp
from os.path import exists, join
from tempfile import TemporaryDirectory
2019-11-08 20:03:16 -05:00
import pytest
from spleeter.audio.adapter import get_default_audio_adapter
from spleeter.separator import Separator
TEST_AUDIO_DESCRIPTOR = 'audio_example.mp3'
2019-11-08 20:03:16 -05:00
TEST_CONFIGURATIONS = [
('spleeter:2stems', ('vocals', 'accompaniment')),
('spleeter:4stems', ('vocals', 'drums', 'bass', 'other')),
('spleeter:5stems', ('vocals', 'drums', 'bass', 'piano', 'other'))
]
2019-11-08 20:03:16 -05:00
@pytest.mark.parametrize('configuration, instruments', TEST_CONFIGURATIONS)
2019-11-08 20:04:44 -05:00
def test_separate(configuration, instruments):
""" Test separation from raw data. """
adapter = get_default_audio_adapter()
waveform, _ = adapter.load(TEST_AUDIO_DESCRIPTOR)
2019-11-08 20:03:16 -05:00
separator = Separator(configuration)
prediction = separator.separate(waveform)
2019-11-08 20:21:37 -05:00
assert len(prediction) == len(instruments)
2019-11-08 20:03:16 -05:00
for instrument in instruments:
assert instrument in prediction
for instrument in instruments:
track = prediction[instrument]
assert not (waveform == track).all()
for compared in instruments:
if instrument != compared:
assert not (track == prediction[compared]).all()
2019-11-08 20:03:16 -05:00
@pytest.mark.parametrize('configuration, instruments', TEST_CONFIGURATIONS)
def test_separate_to_file(configuration, instruments):
""" Test file based separation. """
2019-11-08 20:03:16 -05:00
separator = Separator(configuration)
with TemporaryDirectory() as directory:
separator.separate_to_file(
TEST_AUDIO_DESCRIPTOR,
directory)
for instrument in instruments:
assert exists(join(directory, '{}.wav'.format(instrument)))