forked from deezer/spleeter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit test for audio adapter
fix: import issues
- Loading branch information
Félix Voituret
committed
Nov 8, 2019
1 parent
c4d1343
commit d19c13b
Showing
5 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env python | ||
# coding: utf8 | ||
|
||
""" TO DOCUMENT """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python | ||
# coding: utf8 | ||
|
||
""" Unit testing for audio adapter. """ | ||
|
||
__email__ = 'research@deezer.com' | ||
__author__ = 'Deezer Research' | ||
__license__ = 'MIT License' | ||
|
||
from os.path import join | ||
from tempfile import TemporaryDirectory | ||
|
||
# pylint: disable=import-error | ||
from pytest import fixture | ||
|
||
import numpy as np | ||
import ffmpeg | ||
# pylint: enable=import-error | ||
|
||
from spleeter.audio.adapter import AudioAdapter | ||
from spleeter.audio.adapter import get_default_audio_adapter | ||
from spleeter.audio.adapter import get_audio_adapter | ||
from spleeter.audio.ffmpeg import FFMPEGProcessAudioAdapter | ||
|
||
TEST_AUDIO_DESCRIPTOR = 'audio_example.mp3' | ||
TEST_OFFSET = 0 | ||
TEST_DURATION = 600. | ||
TEST_SAMPLE_RATE = 44100 | ||
|
||
|
||
@fixture(scope='session') | ||
def adapter(): | ||
""" Target test audio adapter fixture. """ | ||
return get_default_audio_adapter() | ||
|
||
|
||
@fixture(scope='session') | ||
def audio_data(adapter): | ||
""" Audio data fixture based on sample loading from adapter. """ | ||
return adapter.load( | ||
TEST_AUDIO_DESCRIPTOR, | ||
TEST_OFFSET, | ||
TEST_DURATION, | ||
TEST_SAMPLE_RATE) | ||
|
||
|
||
def test_default_adapter(adapter): | ||
""" Test adapter as default adapter. """ | ||
assert isinstance(adapter, FFMPEGProcessAudioAdapter) | ||
assert adapter is AudioAdapter.DEFAULT | ||
|
||
|
||
def test_load(audio_data): | ||
""" Test audio loading. """ | ||
waveform, sample_rate = audio_data | ||
assert sample_rate == TEST_SAMPLE_RATE | ||
assert waveform is not None | ||
assert waveform.dtype == np.dtype('float32') | ||
assert len(waveform.shape) == 2 | ||
assert waveform.shape[0] == 479832 | ||
assert waveform.shape[1] == 2 | ||
|
||
|
||
def test_save(adapter, audio_data): | ||
""" Test audio saving. """ | ||
with TemporaryDirectory() as directory: | ||
path = join(directory, 'ffmpeg-save.mp3') | ||
adapter.save( | ||
path, | ||
audio_data[0], | ||
audio_data[1]) | ||
probe = ffmpeg.probe(TEST_AUDIO_DESCRIPTOR) | ||
assert len(probe['streams']) == 1 | ||
stream = probe['streams'][0] | ||
assert stream['codec_type'] == 'audio' | ||
assert stream['channels'] == 2 | ||
assert stream['duration'] == '10.919184' |