fix test failures
This commit is contained in:
parent
5d67172dd0
commit
82042e8c69
|
@ -10,8 +10,6 @@ php:
|
|||
- 7.0
|
||||
# folks who prefer running on 5.x should be using 5.6 in most cases, 5.4 is no in the matrix since noone should use it
|
||||
- 5.6
|
||||
# this is in for centos support, it's still the default on CentOS 7.3 and there were some lang changes after 5.4
|
||||
- 5.4
|
||||
services:
|
||||
- postgresql
|
||||
- rabbitmq
|
||||
|
@ -50,6 +48,12 @@ addons:
|
|||
packages:
|
||||
- silan
|
||||
- libgirepository1.0-dev
|
||||
- gir1.2-gstreamer-1.0
|
||||
- gstreamer1.0-plugins-base
|
||||
- gstreamer1.0-plugins-good
|
||||
- gstreamer1.0-plugins-bad
|
||||
- gstreamer1.0-plugins-ugly
|
||||
- libcairo2-dev
|
||||
- liquidsoap
|
||||
- liquidsoap-plugin-mad
|
||||
- liquidsoap-plugin-taglib
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import logging
|
||||
import threading
|
||||
import multiprocessing
|
||||
import queue
|
||||
from queue import Queue
|
||||
import configparser
|
||||
from .metadata_analyzer import MetadataAnalyzer
|
||||
from .filemover_analyzer import FileMoverAnalyzer
|
||||
|
@ -46,7 +46,7 @@ class AnalyzerPipeline:
|
|||
AnalyzerPipeline.python_logger_deadlock_workaround()
|
||||
|
||||
try:
|
||||
if not isinstance(queue, queue.Queue):
|
||||
if not isinstance(queue, Queue):
|
||||
raise TypeError("queue must be a Queue.Queue()")
|
||||
if not isinstance(audio_file_path, str):
|
||||
raise TypeError("audio_file_path must be unicode. Was of type " + type(audio_file_path).__name__ + " instead.")
|
||||
|
|
|
@ -64,7 +64,7 @@ class CuePointAnalyzer(Analyzer):
|
|||
except OSError as e: # silan was not found
|
||||
logging.warn("Failed to run: %s - %s. %s" % (command[0], e.strerror, "Do you have silan installed?"))
|
||||
except subprocess.CalledProcessError as e: # silan returned an error code
|
||||
logging.warn("%s %s %s", e.cmd, e.message, e.returncode)
|
||||
logging.warn("%s %s %s", e.cmd, e.output, e.returncode)
|
||||
except Exception as e:
|
||||
logging.warn(e)
|
||||
|
||||
|
|
|
@ -30,13 +30,15 @@ class FileMoverAnalyzer(Analyzer):
|
|||
metadata: A dictionary where the "full_path" of where the file is moved to will be added.
|
||||
"""
|
||||
if not isinstance(audio_file_path, str):
|
||||
raise TypeError("audio_file_path must be unicode. Was of type " + type(audio_file_path).__name__)
|
||||
raise TypeError("audio_file_path must be string. Was of type " + type(audio_file_path).__name__)
|
||||
if not isinstance(import_directory, str):
|
||||
raise TypeError("import_directory must be unicode. Was of type " + type(import_directory).__name__)
|
||||
raise TypeError("import_directory must be string. Was of type " + type(import_directory).__name__)
|
||||
if not isinstance(original_filename, str):
|
||||
raise TypeError("original_filename must be unicode. Was of type " + type(original_filename).__name__)
|
||||
raise TypeError("original_filename must be string. Was of type " + type(original_filename).__name__)
|
||||
if not isinstance(metadata, dict):
|
||||
raise TypeError("metadata must be a dict. Was of type " + type(metadata).__name__)
|
||||
if not os.path.exists(audio_file_path):
|
||||
raise FileNotFoundError("audio file not found: {}".format(audio_file_path))
|
||||
|
||||
#Import the file over to it's final location.
|
||||
# TODO: Also, handle the case where the move fails and write some code
|
||||
|
|
|
@ -19,9 +19,11 @@ class MetadataAnalyzer(Analyzer):
|
|||
metadata: A dictionary that the extracted metadata will be added to.
|
||||
'''
|
||||
if not isinstance(filename, str):
|
||||
raise TypeError("filename must be unicode. Was of type " + type(filename).__name__)
|
||||
raise TypeError("filename must be string. Was of type " + type(filename).__name__)
|
||||
if not isinstance(metadata, dict):
|
||||
raise TypeError("metadata must be a dict. Was of type " + type(metadata).__name__)
|
||||
if not os.path.exists(filename):
|
||||
raise FileNotFoundError("audio file not found: {}".format(filename))
|
||||
|
||||
#Airtime <= 2.5.x nonsense:
|
||||
metadata["ftype"] = "audioclip"
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import subprocess
|
||||
import logging
|
||||
from .analyzer import Analyzer
|
||||
import re
|
||||
|
||||
|
||||
class ReplayGainAnalyzer(Analyzer):
|
||||
''' This class extracts the ReplayGain using a tool from the python-rgain package. '''
|
||||
|
||||
REPLAYGAIN_EXECUTABLE = 'replaygain' # From the python-rgain package
|
||||
REPLAYGAIN_EXECUTABLE = 'replaygain' # From the rgain3 python package
|
||||
|
||||
@staticmethod
|
||||
def analyze(filename, metadata):
|
||||
|
@ -19,17 +20,16 @@ class ReplayGainAnalyzer(Analyzer):
|
|||
'''
|
||||
command = [ReplayGainAnalyzer.REPLAYGAIN_EXECUTABLE, '-d', filename]
|
||||
try:
|
||||
results = subprocess.check_output(command, stderr=subprocess.STDOUT, close_fds=True)
|
||||
filename_token = "%s: " % filename
|
||||
rg_pos = results.find(filename_token, results.find("Calculating Replay Gain information")) + len(filename_token)
|
||||
db_pos = results.find(" dB", rg_pos)
|
||||
replaygain = results[rg_pos:db_pos]
|
||||
results = subprocess.check_output(command, stderr=subprocess.STDOUT,
|
||||
close_fds=True, text=True)
|
||||
gain_match = r'Calculating Replay Gain information \.\.\.(?:\n|.)*?:([\d.-]*) dB'
|
||||
replaygain = re.search(gain_match, results).group(1)
|
||||
metadata['replay_gain'] = float(replaygain)
|
||||
|
||||
except OSError as e: # replaygain was not found
|
||||
logging.warn("Failed to run: %s - %s. %s" % (command[0], e.strerror, "Do you have python-rgain installed?"))
|
||||
except subprocess.CalledProcessError as e: # replaygain returned an error code
|
||||
logging.warn("%s %s %s", e.cmd, e.message, e.returncode)
|
||||
logging.warn("%s %s %s", e.cmd, e.output, e.returncode)
|
||||
except Exception as e:
|
||||
logging.warn(e)
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from nose.tools import *
|
||||
from ConfigParser import SafeConfigParser
|
||||
import os
|
||||
import shutil
|
||||
import multiprocessing
|
||||
import Queue
|
||||
from queue import Queue
|
||||
import datetime
|
||||
from airtime_analyzer.analyzer_pipeline import AnalyzerPipeline
|
||||
from airtime_analyzer import config_file
|
||||
|
@ -21,7 +20,7 @@ def teardown():
|
|||
|
||||
def test_basic():
|
||||
filename = os.path.basename(DEFAULT_AUDIO_FILE)
|
||||
q = Queue.Queue()
|
||||
q = Queue()
|
||||
file_prefix = u''
|
||||
storage_backend = "file"
|
||||
#This actually imports the file into the "./Test Artist" directory.
|
||||
|
@ -39,17 +38,17 @@ def test_basic():
|
|||
|
||||
@raises(TypeError)
|
||||
def test_wrong_type_queue_param():
|
||||
AnalyzerPipeline.run_analysis(Queue.Queue(), u'', u'', u'')
|
||||
AnalyzerPipeline.run_analysis(Queue(), u'', u'', u'')
|
||||
|
||||
@raises(TypeError)
|
||||
def test_wrong_type_string_param2():
|
||||
AnalyzerPipeline.run_analysis(Queue.Queue(), '', u'', u'')
|
||||
AnalyzerPipeline.run_analysis(Queue(), '', u'', u'')
|
||||
|
||||
@raises(TypeError)
|
||||
def test_wrong_type_string_param3():
|
||||
AnalyzerPipeline.run_analysis(Queue.Queue(), u'', '', u'')
|
||||
AnalyzerPipeline.run_analysis(Queue(), u'', '', u'')
|
||||
|
||||
@raises(TypeError)
|
||||
def test_wrong_type_string_param4():
|
||||
AnalyzerPipeline.run_analysis(Queue.Queue(), u'', u'', '')
|
||||
AnalyzerPipeline.run_analysis(Queue(), u'', u'', '')
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ from nose.tools import *
|
|||
import os
|
||||
import shutil
|
||||
import multiprocessing
|
||||
import Queue
|
||||
import time
|
||||
import mock
|
||||
from pprint import pprint
|
||||
|
@ -23,19 +22,23 @@ def test_dont_use_analyze():
|
|||
|
||||
@raises(TypeError)
|
||||
def test_move_wrong_string_param1():
|
||||
FileMoverAnalyzer.move('', u'', u'', dict())
|
||||
FileMoverAnalyzer.move(42, '', '', dict())
|
||||
|
||||
@raises(TypeError)
|
||||
def test_move_wrong_string_param2():
|
||||
FileMoverAnalyzer.move(u'', '', u'', dict())
|
||||
FileMoverAnalyzer.move(u'', 23, u'', dict())
|
||||
|
||||
@raises(TypeError)
|
||||
def test_move_wrong_string_param3():
|
||||
FileMoverAnalyzer.move(u'', u'', '', dict())
|
||||
FileMoverAnalyzer.move('', '', 5, dict())
|
||||
|
||||
@raises(TypeError)
|
||||
def test_move_wrong_dict_param():
|
||||
FileMoverAnalyzer.move(u'', u'', u'', 12345)
|
||||
FileMoverAnalyzer.move('', '', '', 12345)
|
||||
|
||||
@raises(FileNotFoundError)
|
||||
def test_move_wrong_string_param3():
|
||||
FileMoverAnalyzer.move('', '', '', dict())
|
||||
|
||||
def test_basic():
|
||||
filename = os.path.basename(DEFAULT_AUDIO_FILE)
|
||||
|
|
|
@ -13,73 +13,73 @@ def teardown():
|
|||
pass
|
||||
|
||||
def check_default_metadata(metadata):
|
||||
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['track_number'] == u'1'
|
||||
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['track_number'] == '1'
|
||||
assert metadata["length"] == str(datetime.timedelta(seconds=metadata["length_seconds"]))
|
||||
|
||||
def test_mp3_mono():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-mono.mp3', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-mono.mp3', dict())
|
||||
check_default_metadata(metadata)
|
||||
assert metadata['channels'] == 1
|
||||
assert metadata['bit_rate'] == 63998
|
||||
assert abs(metadata['length_seconds'] - 3.9) < 0.1
|
||||
assert metadata['mime'] == 'audio/mp3' # Not unicode because MIMEs aren't.
|
||||
assert metadata['track_total'] == u'10' # MP3s can have a track_total
|
||||
assert metadata['track_total'] == '10' # MP3s can have a track_total
|
||||
#Mutagen doesn't extract comments from mp3s it seems
|
||||
|
||||
def test_mp3_jointstereo():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-jointstereo.mp3', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-jointstereo.mp3', dict())
|
||||
check_default_metadata(metadata)
|
||||
assert metadata['channels'] == 2
|
||||
assert metadata['bit_rate'] == 127998
|
||||
assert abs(metadata['length_seconds'] - 3.9) < 0.1
|
||||
assert metadata['mime'] == 'audio/mp3'
|
||||
assert metadata['track_total'] == u'10' # MP3s can have a track_total
|
||||
assert metadata['track_total'] == '10' # MP3s can have a track_total
|
||||
|
||||
def test_mp3_simplestereo():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-simplestereo.mp3', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-simplestereo.mp3', dict())
|
||||
check_default_metadata(metadata)
|
||||
assert metadata['channels'] == 2
|
||||
assert metadata['bit_rate'] == 127998
|
||||
assert abs(metadata['length_seconds'] - 3.9) < 0.1
|
||||
assert metadata['mime'] == 'audio/mp3'
|
||||
assert metadata['track_total'] == u'10' # MP3s can have a track_total
|
||||
assert metadata['track_total'] == '10' # MP3s can have a track_total
|
||||
|
||||
def test_mp3_dualmono():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-dualmono.mp3', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-dualmono.mp3', dict())
|
||||
check_default_metadata(metadata)
|
||||
assert metadata['channels'] == 2
|
||||
assert metadata['bit_rate'] == 127998
|
||||
assert abs(metadata['length_seconds'] - 3.9) < 0.1
|
||||
assert metadata['mime'] == 'audio/mp3'
|
||||
assert metadata['track_total'] == u'10' # MP3s can have a track_total
|
||||
assert metadata['track_total'] == '10' # MP3s can have a track_total
|
||||
|
||||
|
||||
def test_ogg_mono():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-mono.ogg', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-mono.ogg', dict())
|
||||
check_default_metadata(metadata)
|
||||
assert metadata['channels'] == 1
|
||||
assert metadata['bit_rate'] == 80000
|
||||
assert abs(metadata['length_seconds'] - 3.8) < 0.1
|
||||
assert metadata['mime'] == 'audio/vorbis'
|
||||
assert metadata['comment'] == u'Test Comment'
|
||||
assert metadata['comment'] == 'Test Comment'
|
||||
|
||||
def test_ogg_stereo():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo.ogg', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-stereo.ogg', dict())
|
||||
check_default_metadata(metadata)
|
||||
assert metadata['channels'] == 2
|
||||
assert metadata['bit_rate'] == 112000
|
||||
assert abs(metadata['length_seconds'] - 3.8) < 0.1
|
||||
assert metadata['mime'] == 'audio/vorbis'
|
||||
assert metadata['comment'] == u'Test Comment'
|
||||
assert metadata['comment'] == 'Test Comment'
|
||||
|
||||
''' faac and avconv can't seem to create a proper mono AAC file... ugh
|
||||
def test_aac_mono():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-mono.m4a')
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-mono.m4a')
|
||||
print("Mono AAC metadata:")
|
||||
print(metadata)
|
||||
check_default_metadata(metadata)
|
||||
|
@ -87,41 +87,41 @@ def test_aac_mono():
|
|||
assert metadata['bit_rate'] == 80000
|
||||
assert abs(metadata['length_seconds'] - 3.8) < 0.1
|
||||
assert metadata['mime'] == 'audio/mp4'
|
||||
assert metadata['comment'] == u'Test Comment'
|
||||
assert metadata['comment'] == 'Test Comment'
|
||||
'''
|
||||
|
||||
def test_aac_stereo():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo.m4a', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-stereo.m4a', dict())
|
||||
check_default_metadata(metadata)
|
||||
assert metadata['channels'] == 2
|
||||
assert metadata['bit_rate'] == 102619
|
||||
assert abs(metadata['length_seconds'] - 3.8) < 0.1
|
||||
assert metadata['mime'] == 'audio/mp4'
|
||||
assert metadata['comment'] == u'Test Comment'
|
||||
assert metadata['comment'] == 'Test Comment'
|
||||
|
||||
def test_mp3_utf8():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo-utf8.mp3', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-stereo-utf8.mp3', dict())
|
||||
# Using a bunch of different UTF-8 codepages here. Test data is from:
|
||||
# http://winrus.com/utf8-jap.htm
|
||||
assert metadata['track_title'] == u'アイウエオカキクケコサシスセソタチツテ'
|
||||
assert metadata['artist_name'] == u'てすと'
|
||||
assert metadata['album_title'] == u'Ä ä Ü ü ß'
|
||||
assert metadata['year'] == u'1999'
|
||||
assert metadata['genre'] == u'Я Б Г Д Ж Й'
|
||||
assert metadata['track_number'] == u'1'
|
||||
assert metadata['track_title'] == 'アイウエオカキクケコサシスセソタチツテ'
|
||||
assert metadata['artist_name'] == 'てすと'
|
||||
assert metadata['album_title'] == 'Ä ä Ü ü ß'
|
||||
assert metadata['year'] == '1999'
|
||||
assert metadata['genre'] == 'Я Б Г Д Ж Й'
|
||||
assert metadata['track_number'] == '1'
|
||||
assert metadata['channels'] == 2
|
||||
assert metadata['bit_rate'] < 130000
|
||||
assert metadata['bit_rate'] > 127000
|
||||
assert abs(metadata['length_seconds'] - 3.9) < 0.1
|
||||
assert metadata['mime'] == 'audio/mp3'
|
||||
assert metadata['track_total'] == u'10' # MP3s can have a track_total
|
||||
assert metadata['track_total'] == '10' # MP3s can have a track_total
|
||||
|
||||
def test_invalid_wma():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo-invalid.wma', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-stereo-invalid.wma', dict())
|
||||
assert metadata['mime'] == 'audio/x-ms-wma'
|
||||
|
||||
def test_wav_stereo():
|
||||
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo.wav', dict())
|
||||
metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-stereo.wav', dict())
|
||||
assert metadata['mime'] == 'audio/x-wav'
|
||||
assert abs(metadata['length_seconds'] - 3.9) < 0.1
|
||||
assert metadata['channels'] == 2
|
||||
|
@ -129,7 +129,7 @@ def test_wav_stereo():
|
|||
|
||||
|
||||
# Make sure the parameter checking works
|
||||
@raises(TypeError)
|
||||
@raises(FileNotFoundError)
|
||||
def test_move_wrong_string_param1():
|
||||
not_unicode = 'asdfasdf'
|
||||
MetadataAnalyzer.analyze(not_unicode, dict())
|
||||
|
@ -137,11 +137,11 @@ def test_move_wrong_string_param1():
|
|||
@raises(TypeError)
|
||||
def test_move_wrong_metadata_dict():
|
||||
not_a_dict = list()
|
||||
MetadataAnalyzer.analyze(u'asdfasdf', not_a_dict)
|
||||
MetadataAnalyzer.analyze('asdfasdf', not_a_dict)
|
||||
|
||||
# Test an mp3 file where the number of channels is invalid or missing:
|
||||
def test_mp3_bad_channels():
|
||||
filename = u'tests/test_data/44100Hz-16bit-mono.mp3'
|
||||
filename = 'tests/test_data/44100Hz-16bit-mono.mp3'
|
||||
'''
|
||||
It'd be a pain in the ass to construct a real MP3 with an invalid number
|
||||
of channels by hand because that value is stored in every MP3 frame in the file
|
||||
|
@ -158,8 +158,8 @@ def test_mp3_bad_channels():
|
|||
assert metadata['bit_rate'] == 63998
|
||||
assert abs(metadata['length_seconds'] - 3.9) < 0.1
|
||||
assert metadata['mime'] == 'audio/mp3' # Not unicode because MIMEs aren't.
|
||||
assert metadata['track_total'] == u'10' # MP3s can have a track_total
|
||||
assert metadata['track_total'] == '10' # MP3s can have a track_total
|
||||
#Mutagen doesn't extract comments from mp3s it seems
|
||||
|
||||
def test_unparsable_file():
|
||||
MetadataAnalyzer.analyze(u'README.rst', dict())
|
||||
MetadataAnalyzer.analyze('README.rst', dict())
|
||||
|
|
|
@ -2,20 +2,6 @@ from __future__ import print_function
|
|||
from nose.tools import *
|
||||
from airtime_analyzer.replaygain_analyzer import ReplayGainAnalyzer
|
||||
|
||||
'''
|
||||
The tests in here were all tagged with the 'rgain' tag so the can be exluded from being run
|
||||
with nosetest -a '!rgain'. This was needed due to the fact that it is not readily possible
|
||||
to install replaygain on a containerized travis instance.
|
||||
|
||||
We can either give running replaygain test on travis another shot after ubuntu getsan updated
|
||||
gi instrospection allowing us to install gi and gobject into the virtualenv, or we can switch
|
||||
to a full machine and stop using 'sudo: false' on travis.
|
||||
|
||||
Deactivating these tests is a bad fix for now and I plan on looking into it again after
|
||||
most everything else is up and running. For those interesed the tests seem to work locally
|
||||
albeit my results not being up to the given tolerance of 0.30 (which I'm assuming is my rig's
|
||||
problem and would work on travis if replaygain was available).
|
||||
'''
|
||||
|
||||
def check_default_metadata(metadata):
|
||||
''' Check that the values extract by Silan/CuePointAnalyzer on our test audio files match what we expect.
|
||||
|
|
Loading…
Reference in New Issue