From b37a095414ae478f786ceb51f1e6426099795de5 Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 4 Jun 2021 14:04:32 +0200 Subject: [PATCH] Migrate playability_analyzer_test to pytest --- .../tests/playability_analyzer_test.py | 119 ++++++------------ 1 file changed, 35 insertions(+), 84 deletions(-) diff --git a/python_apps/airtime_analyzer/tests/playability_analyzer_test.py b/python_apps/airtime_analyzer/tests/playability_analyzer_test.py index f0e4377d4..2f71b2d27 100644 --- a/python_apps/airtime_analyzer/tests/playability_analyzer_test.py +++ b/python_apps/airtime_analyzer/tests/playability_analyzer_test.py @@ -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")