fix test failures
This commit is contained in:
parent
5d67172dd0
commit
82042e8c69
10 changed files with 125 additions and 129 deletions
|
@ -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,30 +22,34 @@ 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)
|
||||
FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename, dict())
|
||||
FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename, dict())
|
||||
#Move the file back
|
||||
shutil.move("./" + filename, DEFAULT_AUDIO_FILE)
|
||||
assert os.path.exists(DEFAULT_AUDIO_FILE)
|
||||
|
||||
def test_basic_samefile():
|
||||
filename = os.path.basename(DEFAULT_AUDIO_FILE)
|
||||
FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'tests/test_data', filename, dict())
|
||||
FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'tests/test_data', filename, dict())
|
||||
assert os.path.exists(DEFAULT_AUDIO_FILE)
|
||||
|
||||
def test_duplicate_file():
|
||||
|
@ -55,9 +58,9 @@ def test_duplicate_file():
|
|||
FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename, dict())
|
||||
#Copy it back to the original location
|
||||
shutil.copy("./" + filename, DEFAULT_AUDIO_FILE)
|
||||
#Import it again. It shouldn't overwrite the old file and instead create a new
|
||||
#Import it again. It shouldn't overwrite the old file and instead create a new
|
||||
metadata = dict()
|
||||
metadata = FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename, metadata)
|
||||
metadata = FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename, metadata)
|
||||
#Cleanup: move the file (eg. 44100Hz-16bit-mono.mp3) back
|
||||
shutil.move("./" + filename, DEFAULT_AUDIO_FILE)
|
||||
#Remove the renamed duplicate, eg. 44100Hz-16bit-mono_03-26-2014-11-58.mp3
|
||||
|
@ -71,7 +74,7 @@ def test_duplicate_file():
|
|||
it's imported within 1 second of the second file (ie. if the timestamp is the same).
|
||||
'''
|
||||
def test_double_duplicate_files():
|
||||
# Here we use mock to patch out the time.localtime() function so that it
|
||||
# Here we use mock to patch out the time.localtime() function so that it
|
||||
# always returns the same value. This allows us to consistently simulate this test cases
|
||||
# where the last two of the three files are imported at the same time as the timestamp.
|
||||
with mock.patch('airtime_analyzer.filemover_analyzer.time') as mock_time:
|
||||
|
@ -83,17 +86,17 @@ def test_double_duplicate_files():
|
|||
FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename, dict())
|
||||
#Copy it back to the original location
|
||||
shutil.copy("./" + filename, DEFAULT_AUDIO_FILE)
|
||||
#Import it again. It shouldn't overwrite the old file and instead create a new
|
||||
#Import it again. It shouldn't overwrite the old file and instead create a new
|
||||
first_dup_metadata = dict()
|
||||
first_dup_metadata = FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename,
|
||||
first_dup_metadata)
|
||||
first_dup_metadata = FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename,
|
||||
first_dup_metadata)
|
||||
#Copy it back again!
|
||||
shutil.copy("./" + filename, DEFAULT_AUDIO_FILE)
|
||||
#Reimport for the third time, which should have the same timestamp as the second one
|
||||
#thanks to us mocking out time.localtime()
|
||||
second_dup_metadata = dict()
|
||||
second_dup_metadata = FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename,
|
||||
second_dup_metadata)
|
||||
second_dup_metadata = FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, u'.', filename,
|
||||
second_dup_metadata)
|
||||
#Cleanup: move the file (eg. 44100Hz-16bit-mono.mp3) back
|
||||
shutil.move("./" + filename, DEFAULT_AUDIO_FILE)
|
||||
#Remove the renamed duplicate, eg. 44100Hz-16bit-mono_03-26-2014-11-58.mp3
|
||||
|
@ -105,7 +108,7 @@ def test_double_duplicate_files():
|
|||
def test_bad_permissions_destination_dir():
|
||||
filename = os.path.basename(DEFAULT_AUDIO_FILE)
|
||||
dest_dir = u'/sys/foobar' # /sys is using sysfs on Linux, which is unwritable
|
||||
FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, dest_dir, filename, dict())
|
||||
FileMoverAnalyzer.move(DEFAULT_AUDIO_FILE, dest_dir, filename, dict())
|
||||
#Move the file back
|
||||
shutil.move(os.path.join(dest_dir, filename), DEFAULT_AUDIO_FILE)
|
||||
assert os.path.exists(DEFAULT_AUDIO_FILE)
|
||||
|
|
|
@ -4,7 +4,7 @@ import datetime
|
|||
import mutagen
|
||||
import mock
|
||||
from nose.tools import *
|
||||
from airtime_analyzer.metadata_analyzer import MetadataAnalyzer
|
||||
from airtime_analyzer.metadata_analyzer import MetadataAnalyzer
|
||||
|
||||
def setup():
|
||||
pass
|
||||
|
@ -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,12 +137,12 @@ 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…
Add table
Add a link
Reference in a new issue