2021-06-04 14:03:41 +02:00
|
|
|
import pytest
|
2014-12-11 00:44:35 +01:00
|
|
|
from airtime_analyzer.cuepoint_analyzer import CuePointAnalyzer
|
|
|
|
|
2021-05-27 16:23:02 +02:00
|
|
|
|
2021-06-04 14:03:41 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"filepath",
|
|
|
|
[
|
|
|
|
("tests/test_data/44100Hz-16bit-mono.mp3"),
|
|
|
|
("tests/test_data/44100Hz-16bit-dualmono.mp3"),
|
|
|
|
("tests/test_data/44100Hz-16bit-stereo.mp3"),
|
|
|
|
("tests/test_data/44100Hz-16bit-stereo-utf8.mp3"),
|
|
|
|
("tests/test_data/44100Hz-16bit-simplestereo.mp3"),
|
|
|
|
("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"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_analyze(filepath):
|
|
|
|
metadata = CuePointAnalyzer.analyze(filepath, dict())
|
|
|
|
|
2014-12-11 00:44:35 +01:00
|
|
|
# We give silan some leeway here by specifying a tolerance
|
|
|
|
tolerance_seconds = 0.1
|
|
|
|
length_seconds = 3.9
|
2021-05-27 16:23:02 +02:00
|
|
|
assert abs(metadata["length_seconds"] - length_seconds) < tolerance_seconds
|
|
|
|
assert abs(float(metadata["cuein"])) < tolerance_seconds
|
|
|
|
assert abs(float(metadata["cueout"]) - length_seconds) < tolerance_seconds
|
|
|
|
|
2014-12-11 00:44:35 +01:00
|
|
|
|
2021-05-29 18:39:10 +02:00
|
|
|
def test_analyze_missing_silan():
|
2021-06-04 14:03:41 +02:00
|
|
|
old = CuePointAnalyzer.SILAN_EXECUTABLE
|
|
|
|
CuePointAnalyzer.SILAN_EXECUTABLE = "foobar"
|
|
|
|
CuePointAnalyzer.analyze("tests/test_data/44100Hz-16bit-mono.mp3", dict())
|
|
|
|
CuePointAnalyzer.SILAN_EXECUTABLE = old
|
2021-05-27 16:23:02 +02:00
|
|
|
|
2014-12-11 00:44:35 +01:00
|
|
|
|
2021-05-29 18:39:10 +02:00
|
|
|
def test_analyze_invalid_filepath():
|
2021-06-04 14:03:41 +02:00
|
|
|
with pytest.raises(KeyError):
|
|
|
|
test_analyze("non-existent-file")
|
2014-12-11 00:44:35 +01:00
|
|
|
|
2021-05-27 16:23:02 +02:00
|
|
|
|
2021-05-29 18:39:10 +02:00
|
|
|
def test_analyze_invalid_wma():
|
2021-06-04 14:03:41 +02:00
|
|
|
with pytest.raises(KeyError):
|
|
|
|
test_analyze("tests/test_data/44100Hz-16bit-stereo-invalid.wma")
|