From 151c2a7b9318e43a71ec5534498ebd623289ce29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Voituret?= Date: Wed, 20 Nov 2019 15:18:53 +0100 Subject: [PATCH] test: add filename format tests --- tests/test_separator.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/test_separator.py b/tests/test_separator.py index a95128b..d231987 100644 --- a/tests/test_separator.py +++ b/tests/test_separator.py @@ -9,15 +9,17 @@ __license__ = 'MIT License' import filecmp -from os.path import exists, join +from os.path import basename, exists, join from tempfile import TemporaryDirectory import pytest +from spleeter import SpleeterError from spleeter.audio.adapter import get_default_audio_adapter from spleeter.separator import Separator TEST_AUDIO_DESCRIPTOR = 'audio_example.mp3' +TEST_AUDIO_BASENAME = basename(TEST_AUDIO_DESCRIPTOR) TEST_CONFIGURATIONS = [ ('spleeter:2stems', ('vocals', 'accompaniment')), ('spleeter:4stems', ('vocals', 'drums', 'bass', 'other')), @@ -52,4 +54,32 @@ def test_separate_to_file(configuration, instruments): TEST_AUDIO_DESCRIPTOR, directory) for instrument in instruments: - assert exists(join(directory, '{}.wav'.format(instrument))) + assert exists(join( + directory, + '{}/{}.wav'.format(TEST_AUDIO_BASENAME, instrument))) + + +@pytest.mark.parametrize('configuration, instruments', TEST_CONFIGURATIONS) +def test_filename_format(configuration, instruments): + """ Test custom filename format. """ + separator = Separator(configuration) + with TemporaryDirectory() as directory: + separator.separate_to_file( + TEST_AUDIO_DESCRIPTOR, + directory, + filename_format='export/{filename}/{instrument}.{codec}') + for instrument in instruments: + assert exists(join( + directory, + 'export/{}/{}.wav'.format(TEST_AUDIO_BASENAME, instrument))) + + +def test_filename_confilct(): + """ Test error handling with static pattern. """ + separator = Separator(TEST_CONFIGURATIONS[0][0]) + with TemporaryDirectory() as directory: + with pytest.raises(SpleeterError): + separator.separate_to_file( + TEST_AUDIO_DESCRIPTOR, + directory, + filename_format='I wanna be your lover')