Migrate analyzer_pipeline_test to pytest
This commit is contained in:
parent
23d02bf959
commit
d94193ce57
|
@ -1,65 +1,48 @@
|
|||
import datetime
|
||||
import multiprocessing
|
||||
import os
|
||||
import shutil
|
||||
from queue import Queue
|
||||
|
||||
from airtime_analyzer import config_file
|
||||
import pytest
|
||||
from airtime_analyzer.analyzer_pipeline import AnalyzerPipeline
|
||||
from nose.tools import *
|
||||
|
||||
DEFAULT_AUDIO_FILE = u"tests/test_data/44100Hz-16bit-mono.mp3"
|
||||
DEFAULT_IMPORT_DEST = u"Test Artist/Test Album/44100Hz-16bit-mono.mp3"
|
||||
from .conftest import AUDIO_FILENAME, AUDIO_IMPORT_DEST
|
||||
|
||||
|
||||
def setup():
|
||||
pass
|
||||
|
||||
|
||||
def teardown():
|
||||
# Move the file back
|
||||
shutil.move(DEFAULT_IMPORT_DEST, DEFAULT_AUDIO_FILE)
|
||||
assert os.path.exists(DEFAULT_AUDIO_FILE)
|
||||
|
||||
|
||||
def test_basic():
|
||||
filename = os.path.basename(DEFAULT_AUDIO_FILE)
|
||||
q = Queue()
|
||||
file_prefix = u""
|
||||
storage_backend = "file"
|
||||
# This actually imports the file into the "./Test Artist" directory.
|
||||
def test_basic(src_dir, dest_dir):
|
||||
queue = Queue()
|
||||
AnalyzerPipeline.run_analysis(
|
||||
q, DEFAULT_AUDIO_FILE, u".", filename, storage_backend, file_prefix
|
||||
queue,
|
||||
os.path.join(src_dir, AUDIO_FILENAME),
|
||||
dest_dir,
|
||||
AUDIO_FILENAME,
|
||||
"file",
|
||||
"",
|
||||
)
|
||||
metadata = q.get()
|
||||
assert metadata["track_title"] == u"Test Title"
|
||||
assert metadata["artist_name"] == u"Test Artist"
|
||||
assert metadata["album_title"] == u"Test Album"
|
||||
assert metadata["year"] == u"1999"
|
||||
assert metadata["genre"] == u"Test Genre"
|
||||
assert metadata["mime"] == "audio/mp3" # Not unicode because MIMEs aren't.
|
||||
metadata = queue.get()
|
||||
|
||||
assert metadata["track_title"] == "Test Title"
|
||||
assert metadata["artist_name"] == "Test Artist"
|
||||
assert metadata["album_title"] == "Test Album"
|
||||
assert metadata["year"] == "1999"
|
||||
assert metadata["genre"] == "Test Genre"
|
||||
assert metadata["mime"] == "audio/mp3"
|
||||
assert abs(metadata["length_seconds"] - 3.9) < 0.1
|
||||
assert metadata["length"] == str(
|
||||
datetime.timedelta(seconds=metadata["length_seconds"])
|
||||
)
|
||||
assert os.path.exists(DEFAULT_IMPORT_DEST)
|
||||
assert os.path.exists(os.path.join(dest_dir, AUDIO_IMPORT_DEST))
|
||||
|
||||
|
||||
@raises(TypeError)
|
||||
def test_wrong_type_queue_param():
|
||||
AnalyzerPipeline.run_analysis(Queue(), u"", u"", u"")
|
||||
|
||||
|
||||
@raises(TypeError)
|
||||
def test_wrong_type_string_param2():
|
||||
AnalyzerPipeline.run_analysis(Queue(), "", u"", u"")
|
||||
|
||||
|
||||
@raises(TypeError)
|
||||
def test_wrong_type_string_param3():
|
||||
AnalyzerPipeline.run_analysis(Queue(), u"", "", u"")
|
||||
|
||||
|
||||
@raises(TypeError)
|
||||
def test_wrong_type_string_param4():
|
||||
AnalyzerPipeline.run_analysis(Queue(), u"", u"", "")
|
||||
@pytest.mark.parametrize(
|
||||
"params,exception",
|
||||
[
|
||||
((Queue(), u"", u"", u""), TypeError),
|
||||
((Queue(), "", u"", u""), TypeError),
|
||||
((Queue(), u"", "", u""), TypeError),
|
||||
((Queue(), u"", u"", ""), TypeError),
|
||||
],
|
||||
)
|
||||
def test_run_analysis_wrong_params(params, exception):
|
||||
with pytest.raises(exception):
|
||||
AnalyzerPipeline.run_analysis(*params)
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import pytest
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
|
||||
AUDIO_FILE = "tests/test_data/44100Hz-16bit-mono.mp3"
|
||||
AUDIO_FILENAME = os.path.basename(AUDIO_FILE)
|
||||
AUDIO_IMPORT_DEST = "Test Artist/Test Album/44100Hz-16bit-mono.mp3"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
|
Loading…
Reference in New Issue