Migrate replaygain_analyzer_test to pytest
This commit is contained in:
parent
5ff923887d
commit
efcbd26447
|
@ -1,138 +1,45 @@
|
||||||
from __future__ import print_function
|
import pytest
|
||||||
|
|
||||||
from airtime_analyzer.replaygain_analyzer import ReplayGainAnalyzer
|
from airtime_analyzer.replaygain_analyzer import ReplayGainAnalyzer
|
||||||
from nose.tools import *
|
|
||||||
|
|
||||||
|
|
||||||
def check_default_metadata(metadata):
|
@pytest.mark.parametrize(
|
||||||
"""Check that the values extract by Silan/CuePointAnalyzer on our test audio files match what we expect.
|
"filepath",
|
||||||
:param metadata: a metadata dictionary
|
[
|
||||||
:return: Nothing
|
("tests/test_data/44100Hz-16bit-mono.mp3"),
|
||||||
"""
|
("tests/test_data/44100Hz-16bit-dualmono.mp3"),
|
||||||
"""
|
("tests/test_data/44100Hz-16bit-stereo.mp3"),
|
||||||
# We give python-rgain some leeway here by specifying a tolerance. It's not perfectly consistent across codecs...
|
("tests/test_data/44100Hz-16bit-stereo-utf8.mp3"),
|
||||||
assert abs(metadata['cuein']) < tolerance_seconds
|
("tests/test_data/44100Hz-16bit-simplestereo.mp3"),
|
||||||
assert abs(metadata['cueout'] - length_seconds) < tolerance_seconds
|
("tests/test_data/44100Hz-16bit-jointstereo.mp3"),
|
||||||
"""
|
# ("tests/test_data/44100Hz-16bit-mp3-missingid3header.mp3"),
|
||||||
|
("tests/test_data/44100Hz-16bit-mono.ogg"),
|
||||||
|
("tests/test_data/44100Hz-16bit-stereo.ogg"),
|
||||||
|
# ("tests/test_data/44100Hz-16bit-stereo-invalid.wma"),
|
||||||
|
("tests/test_data/44100Hz-16bit-stereo.m4a"),
|
||||||
|
# ("tests/test_data/44100Hz-16bit-stereo.wav"), # WAV is not supported by rgain3
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_analyze(filepath):
|
||||||
|
metadata = ReplayGainAnalyzer.analyze(filepath, dict())
|
||||||
|
|
||||||
|
# We give rgain3 some leeway here by specifying a tolerance
|
||||||
tolerance = 0.60
|
tolerance = 0.60
|
||||||
expected_replaygain = 5.2
|
expected_replaygain = 5.2
|
||||||
print(metadata["replay_gain"])
|
|
||||||
assert abs(metadata["replay_gain"] - expected_replaygain) < tolerance
|
assert abs(metadata["replay_gain"] - expected_replaygain) < tolerance
|
||||||
|
|
||||||
|
|
||||||
def test_missing_replaygain():
|
def test_missing_replaygain():
|
||||||
old_rg = ReplayGainAnalyzer.REPLAYGAIN_EXECUTABLE
|
old = ReplayGainAnalyzer.REPLAYGAIN_EXECUTABLE
|
||||||
ReplayGainAnalyzer.REPLAYGAIN_EXECUTABLE = "foosdaf"
|
ReplayGainAnalyzer.REPLAYGAIN_EXECUTABLE = "foobar"
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
ReplayGainAnalyzer.analyze("tests/test_data/44100Hz-16bit-mono.mp3", dict())
|
||||||
u"tests/test_data/44100Hz-16bit-stereo-utf8.mp3", dict()
|
ReplayGainAnalyzer.REPLAYGAIN_EXECUTABLE = old
|
||||||
)
|
|
||||||
ReplayGainAnalyzer.REPLAYGAIN_EXECUTABLE = old_rg # Need to put this back
|
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_filepath():
|
def test_invalid_filepath():
|
||||||
metadata = ReplayGainAnalyzer.analyze(u"non-existent-file", dict())
|
with pytest.raises(KeyError):
|
||||||
|
test_analyze("non-existent-file")
|
||||||
|
|
||||||
def test_mp3_utf8():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-stereo-utf8.mp3", dict()
|
|
||||||
)
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
|
|
||||||
|
|
||||||
test_mp3_utf8.rgain = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_mp3_dualmono():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-dualmono.mp3", dict()
|
|
||||||
)
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
|
|
||||||
|
|
||||||
test_mp3_dualmono.rgain = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_mp3_jointstereo():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-jointstereo.mp3", dict()
|
|
||||||
)
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
|
|
||||||
|
|
||||||
test_mp3_jointstereo.rgain = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_mp3_simplestereo():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-simplestereo.mp3", dict()
|
|
||||||
)
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
|
|
||||||
|
|
||||||
test_mp3_simplestereo.rgain = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_mp3_stereo():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-stereo.mp3", dict()
|
|
||||||
)
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
|
|
||||||
|
|
||||||
test_mp3_stereo.rgain = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_mp3_mono():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-mono.mp3", dict()
|
|
||||||
)
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
|
|
||||||
|
|
||||||
test_mp3_mono.rgain = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_ogg_stereo():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-stereo.ogg", dict()
|
|
||||||
)
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
|
|
||||||
|
|
||||||
test_ogg_stereo = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_wma():
|
def test_invalid_wma():
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
with pytest.raises(KeyError):
|
||||||
u"tests/test_data/44100Hz-16bit-stereo-invalid.wma", dict()
|
test_analyze("tests/test_data/44100Hz-16bit-stereo-invalid.wma")
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
test_invalid_wma.rgain = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_mp3_missing_id3_header():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-mp3-missingid3header.mp3", dict()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
test_mp3_missing_id3_header.rgain = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_m4a_stereo():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(
|
|
||||||
u"tests/test_data/44100Hz-16bit-stereo.m4a", dict()
|
|
||||||
)
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
|
|
||||||
|
|
||||||
test_m4a_stereo.rgain = True
|
|
||||||
|
|
||||||
""" WAVE is not supported by python-rgain yet
|
|
||||||
def test_wav_stereo():
|
|
||||||
metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo.wav', dict())
|
|
||||||
check_default_metadata(metadata)
|
|
||||||
test_wav_stereo.rgain = True
|
|
||||||
"""
|
|
||||||
|
|
Loading…
Reference in New Issue