Migrate playability_analyzer_test to pytest

This commit is contained in:
jo 2021-06-04 14:04:32 +02:00
parent efcbd26447
commit b37a095414
1 changed files with 35 additions and 84 deletions

View File

@ -1,97 +1,48 @@
from airtime_analyzer.playability_analyzer import *
from nose.tools import *
import pytest
from airtime_analyzer.playability_analyzer import (
PlayabilityAnalyzer,
UnplayableFileError,
)
def check_default_metadata(metadata):
"""Stub function for now in case we need it later."""
pass
@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):
PlayabilityAnalyzer.analyze(filepath, dict())
def test_missing_liquidsoap():
old_ls = PlayabilityAnalyzer.LIQUIDSOAP_EXECUTABLE
PlayabilityAnalyzer.LIQUIDSOAP_EXECUTABLE = "foosdaf"
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-stereo-utf8.mp3", dict()
)
PlayabilityAnalyzer.LIQUIDSOAP_EXECUTABLE = old_ls # Need to put this back
old = PlayabilityAnalyzer.LIQUIDSOAP_EXECUTABLE
PlayabilityAnalyzer.LIQUIDSOAP_EXECUTABLE = "foobar"
PlayabilityAnalyzer.analyze("tests/test_data/44100Hz-16bit-mono.mp3", dict())
PlayabilityAnalyzer.LIQUIDSOAP_EXECUTABLE = old
@raises(UnplayableFileError)
def test_invalid_filepath():
metadata = PlayabilityAnalyzer.analyze(u"non-existent-file", dict())
with pytest.raises(UnplayableFileError):
test_analyze("non-existent-file")
def test_mp3_utf8():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-stereo-utf8.mp3", dict()
)
check_default_metadata(metadata)
# def test_invalid_wma():
# with pytest.raises(UnplayableFileError):
# test_analyze("tests/test_data/44100Hz-16bit-stereo-invalid.wma")
def test_mp3_dualmono():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-dualmono.mp3", dict()
)
check_default_metadata(metadata)
def test_mp3_jointstereo():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-jointstereo.mp3", dict()
)
check_default_metadata(metadata)
def test_mp3_simplestereo():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-simplestereo.mp3", dict()
)
check_default_metadata(metadata)
def test_mp3_stereo():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-stereo.mp3", dict()
)
check_default_metadata(metadata)
def test_mp3_mono():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-mono.mp3", dict()
)
check_default_metadata(metadata)
def test_ogg_stereo():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-stereo.ogg", dict()
)
check_default_metadata(metadata)
@raises(UnplayableFileError)
def test_invalid_wma():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-stereo-invalid.wma", dict()
)
def test_m4a_stereo():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-stereo.m4a", dict()
)
check_default_metadata(metadata)
def test_wav_stereo():
metadata = PlayabilityAnalyzer.analyze(
u"tests/test_data/44100Hz-16bit-stereo.wav", dict()
)
check_default_metadata(metadata)
@raises(UnplayableFileError)
def test_unknown():
metadata = PlayabilityAnalyzer.analyze(u"http://www.google.com", dict())
check_default_metadata(metadata)
with pytest.raises(UnplayableFileError):
test_analyze("https://www.google.com")