now tolerates space-separated release times

--HG--
extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40221
This commit is contained in:
adrian.sampson 2009-04-21 07:21:23 +00:00
parent debebc616c
commit f6b53142a9
4 changed files with 25 additions and 11 deletions

View file

@ -117,7 +117,7 @@ class Packed(object):
items = self.items items = self.items
if self.packstyle == packing.DATE: if self.packstyle == packing.DATE:
# Remove time information from dates. Usually delimited by # Remove time information from dates. Usually delimited by
# a "T". # a "T" or a space.
items = re.sub(r'[Tt ].*$', '', unicode(items)) items = re.sub(r'[Tt ].*$', '', unicode(items))
# transform from a string packing into a list we can index into # transform from a string packing into a list we can index into

BIN
test/rsrc/space_time.mp3 Executable file

Binary file not shown.

View file

@ -223,17 +223,33 @@ def suite_for_file(path, correct_dict, writing=True):
return s return s
class EdgeTest(unittest.TestCase): class EdgeTest(unittest.TestCase):
def setUp(self):
self.emptylist = beets.mediafile.MediaFile(
os.path.join('rsrc', 'emptylist.mp3'))
def test_emptylist(self): def test_emptylist(self):
# Some files have an ID3 frame that has a list with no elements. # Some files have an ID3 frame that has a list with no elements.
# This is very hard to produce, so this is just the first 8192 # This is very hard to produce, so this is just the first 8192
# bytes of a file found "in the wild". # bytes of a file found "in the wild".
genre = self.emptylist.genre emptylist = beets.mediafile.MediaFile(
os.path.join('rsrc', 'emptylist.mp3'))
genre = emptylist.genre
self.assertEqual(genre, '') self.assertEqual(genre, '')
def test_release_time_with_space(self):
# Ensures that release times delimited by spaces are ignored.
# Amie Street produces such files.
space_time = beets.mediafile.MediaFile(
os.path.join('rsrc', 'space_time.mp3'))
self.assertEqual(space_time.year, 2009)
self.assertEqual(space_time.month, 9)
self.assertEqual(space_time.day, 4)
def test_release_time_with_t(self):
# Ensures that release times delimited by Ts are ignored.
# The iTunes Store produces such files.
t_time = beets.mediafile.MediaFile(
os.path.join('rsrc', 't_time.m4a'))
self.assertEqual(t_time.year, 1987)
self.assertEqual(t_time.month, 3)
self.assertEqual(t_time.day, 31)
def suite(): def suite():
s = unittest.TestSuite() s = unittest.TestSuite()
@ -254,10 +270,6 @@ def suite():
s.addTest(suite_for_file(os.path.join('rsrc', 'date.mp3'), s.addTest(suite_for_file(os.path.join('rsrc', 'date.mp3'),
correct_dicts['date'])) correct_dicts['date']))
# Test for dates that include times (like iTunes purchases).
s.addTest(suite_for_file(os.path.join('rsrc', 'time.m4a'),
correct_dicts['date']))
# Read-only attribute tests. # Read-only attribute tests.
for fname, correct_dict in read_only_correct_dicts.iteritems(): for fname, correct_dict in read_only_correct_dicts.iteritems():
path = os.path.join('rsrc', fname) path = os.path.join('rsrc', fname)
@ -266,6 +278,8 @@ def suite():
# Edge cases. # Edge cases.
s.addTest(EdgeTest('test_emptylist')) s.addTest(EdgeTest('test_emptylist'))
s.addTest(EdgeTest('test_release_time_with_t'))
s.addTest(EdgeTest('test_release_time_with_space'))
return s return s