diff --git a/setup.cfg b/setup.cfg index cde4869ac..bdb162e1d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,3 @@ logging-clear-handlers=1 # E241 missing whitespace after ',' (used to align visually) # E221 multiple spaces before operator (used to align visually) ignore=E241,E221 - -# List of files that have not been cleand up yet. We will try to reduce -# this with each commit -exclude=test/test_config_command.py,test/test_files.py,test/test_art.py,test/test_web.py,test/test_zero.py,test/rsrc/beetsplug/test.py,test/test_template.py,test/test_echonest.py,test/test_datequery.py,test/test_mb.py,test/test_convert.py,test/testall.py,test/test_player.py,test/test_query.py,test/test_mediafile.py,test/test_keyfinder.py,test/test_the.py,test/test_lyrics.py,test/test_ihate.py,test/test_vfs.py,test/test_replaygain.py,test/__init__.py,test/_common.py,test/test_mediafile_edge.py,test/test_ui.py diff --git a/test/__init__.py b/test/__init__.py index f34357b7c..52514cb73 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,2 +1 @@ # Make python -m testall.py work. - diff --git a/test/_common.py b/test/_common.py index 25cf3a2e2..64f2f7247 100644 --- a/test/_common.py +++ b/test/_common.py @@ -36,8 +36,9 @@ import beets # Make sure the development versions of the plugins are used import beetsplug -beetsplug.__path__ = [ os.path.abspath( - os.path.join(__file__, '..', '..', 'beetsplug')) ] +beetsplug.__path__ = [os.path.abspath( + os.path.join(__file__, '..', '..', 'beetsplug') +)] # Test resources path. RSRC = os.path.join(os.path.dirname(__file__), 'rsrc') @@ -49,71 +50,77 @@ log.setLevel(logging.DEBUG) # Dummy item creation. _item_ident = 0 + + def item(lib=None): global _item_ident _item_ident += 1 i = beets.library.Item( - title = u'the title', - artist = u'the artist', - albumartist = u'the album artist', - album = u'the album', - genre = u'the genre', - composer = u'the composer', - grouping = u'the grouping', - year = 1, - month = 2, - day = 3, - track = 4, - tracktotal = 5, - disc = 6, - disctotal = 7, - lyrics = u'the lyrics', - comments = u'the comments', - bpm = 8, - comp = True, - path = 'somepath' + str(_item_ident), - length = 60.0, - bitrate = 128000, - format = 'FLAC', - mb_trackid = 'someID-1', - mb_albumid = 'someID-2', - mb_artistid = 'someID-3', - mb_albumartistid = 'someID-4', - album_id = None, + title=u'the title', + artist=u'the artist', + albumartist=u'the album artist', + album=u'the album', + genre=u'the genre', + composer=u'the composer', + grouping=u'the grouping', + year=1, + month=2, + day=3, + track=4, + tracktotal=5, + disc=6, + disctotal=7, + lyrics=u'the lyrics', + comments=u'the comments', + bpm=8, + comp=True, + path='somepath' + str(_item_ident), + length=60.0, + bitrate=128000, + format='FLAC', + mb_trackid='someID-1', + mb_albumid='someID-2', + mb_artistid='someID-3', + mb_albumartistid='someID-4', + album_id=None, ) if lib: lib.add(i) return i _album_ident = 0 + + def album(lib=None): global _item_ident _item_ident += 1 i = beets.library.Album( - artpath= None, - albumartist = 'some album artist', - albumartist_sort = 'some sort album artist', - albumartist_credit = 'some album artist credit', - album = 'the album', - genre = 'the genre', - year = 2014, - month = 2, - day = 5, - tracktotal = 0, - disctotal = 1, - comp = False, - mb_albumid = 'someID-1', - mb_albumartistid = 'someID-1' + artpath=None, + albumartist='some album artist', + albumartist_sort='some sort album artist', + albumartist_credit='some album artist credit', + album='the album', + genre='the genre', + year=2014, + month=2, + day=5, + tracktotal=0, + disctotal=1, + comp=False, + mb_albumid='someID-1', + mb_albumartistid='someID-1' ) if lib: lib.add(i) - return i - + return i + + # Dummy import session. def import_session(lib=None, logfile=None, paths=[], query=[], cli=False): cls = commands.TerminalImportSession if cli else importer.ImportSession return cls(lib, logfile, paths, query) + # A test harness for all beets tests. # Provides temporary, isolated configuration. class TestCase(unittest.TestCase): @@ -161,7 +168,8 @@ class TestCase(unittest.TestCase): def assertNotExists(self, path): self.assertFalse(os.path.exists(path), - 'file exists: %s' % path) + 'file exists: %s' % path) + class LibTestCase(TestCase): """A test case that includes an in-memory library object (`lib`) and @@ -177,7 +185,6 @@ class LibTestCase(TestCase): super(LibTestCase, self).tearDown() - # Mock timing. class Timecop(object): diff --git a/test/rsrc/beetsplug/test.py b/test/rsrc/beetsplug/test.py index 792676b51..68c08774f 100644 --- a/test/rsrc/beetsplug/test.py +++ b/test/rsrc/beetsplug/test.py @@ -1,6 +1,7 @@ from beets.plugins import BeetsPlugin from beets import ui + class TestPlugin(BeetsPlugin): def __init__(self): super(TestPlugin, self).__init__() diff --git a/test/test_art.py b/test/test_art.py index 30723ae7a..30ebb6086 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -34,7 +34,8 @@ class FetchImageTest(_common.TestCase): super(FetchImageTest, self).run(*args, **kwargs) def mock_response(self, content_type): - responses.add(responses.GET, 'http://example.com', content_type=content_type) + responses.add(responses.GET, 'http://example.com', + content_type=content_type) def test_invalid_type_returns_none(self): self.mock_response('image/watercolour') @@ -82,15 +83,20 @@ class FSArtTest(_common.TestCase): _common.touch(os.path.join(self.dpath, 'back.jpg')) _common.touch(os.path.join(self.dpath, 'front.jpg')) _common.touch(os.path.join(self.dpath, 'front-cover.jpg')) - fn = fetchart.art_in_path(self.dpath, ('cover', 'front', 'back'), False) + fn = fetchart.art_in_path(self.dpath, + ('cover', 'front', 'back'), False) self.assertEqual(fn, os.path.join(self.dpath, 'front-cover.jpg')) + class CombinedTest(_common.TestCase): ASIN = 'xxxx' MBID = 'releaseid' - AMAZON_URL = 'http://images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg'.format(ASIN) - AAO_URL = 'http://www.albumart.org/index_detail.php?asin={0}'.format(ASIN) - CAA_URL = 'http://coverartarchive.org/release/{0}/front-500.jpg'.format(MBID) + AMAZON_URL = 'http://images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ + .format(ASIN) + AAO_URL = 'http://www.albumart.org/index_detail.php?asin={0}' \ + .format(ASIN) + CAA_URL = 'http://coverartarchive.org/release/{0}/front-500.jpg' \ + .format(MBID) def setUp(self): super(CombinedTest, self).setUp() @@ -162,7 +168,8 @@ class CombinedTest(_common.TestCase): def test_local_only_gets_fs_image(self): _common.touch(os.path.join(self.dpath, 'art.jpg')) album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN) - artpath = fetchart.art_for_album(album, [self.dpath], None, local_only=True) + artpath = fetchart.art_for_album(album, [self.dpath], + None, local_only=True) self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg')) self.assertEqual(len(responses.calls), 0) @@ -182,8 +189,10 @@ class AAOTest(_common.TestCase): def test_aao_scraper_finds_image(self): body = """
- - View larger image + + View larger image """ self.mock_response(self.AAO_URL, body) res = fetchart.aao_art(self.ASIN) @@ -232,8 +241,10 @@ class ArtImporterTest(_common.TestCase): _common.touch(self.art_file) self.old_afa = fetchart.art_for_album self.afa_response = self.art_file + def art_for_album(i, p, maxwidth=None, local_only=False): return self.afa_response + fetchart.art_for_album = art_for_album # Test library. @@ -258,11 +269,11 @@ class ArtImporterTest(_common.TestCase): self.task.is_album = True self.task.album = self.album info = AlbumInfo( - album = 'some album', - album_id = 'albumid', - artist = 'some artist', - artist_id = 'artistid', - tracks = [], + album='some album', + album_id='albumid', + artist='some artist', + artist_id='artistid', + tracks=[], ) self.task.set_choice(AlbumMatch(0, info, {}, set(), set())) @@ -283,8 +294,10 @@ class ArtImporterTest(_common.TestCase): artpath = self.lib.albums()[0].artpath if should_exist: - self.assertEqual(artpath, - os.path.join(os.path.dirname(self.i.path), 'cover.jpg')) + self.assertEqual( + artpath, + os.path.join(os.path.dirname(self.i.path), 'cover.jpg') + ) self.assertExists(artpath) else: self.assertEqual(artpath, None) diff --git a/test/test_files.py b/test/test_files.py index 1dee982b7..398b6ceb8 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -25,6 +25,7 @@ from _common import item, touch import beets.library from beets import util + class MoveTest(_common.TestCase): def setUp(self): super(MoveTest, self).setUp() @@ -120,15 +121,18 @@ class MoveTest(_common.TestCase): self.assertEqual(os.path.dirname(self.i.path), os.path.dirname(dest)) + class HelperTest(_common.TestCase): def test_ancestry_works_on_file(self): p = '/a/b/c' - a = ['/','/a','/a/b'] + a = ['/', '/a', '/a/b'] self.assertEqual(util.ancestry(p), a) + def test_ancestry_works_on_dir(self): p = '/a/b/c/' a = ['/', '/a', '/a/b', '/a/b/c'] self.assertEqual(util.ancestry(p), a) + def test_ancestry_works_on_relative(self): p = 'a/b/c' a = ['a', 'a/b'] @@ -136,17 +140,20 @@ class HelperTest(_common.TestCase): def test_components_works_on_file(self): p = '/a/b/c' - a = ['/', 'a', 'b', 'c'] + a = ['/', 'a', 'b', 'c'] self.assertEqual(util.components(p), a) + def test_components_works_on_dir(self): p = '/a/b/c/' - a = ['/', 'a', 'b', 'c'] + a = ['/', 'a', 'b', 'c'] self.assertEqual(util.components(p), a) + def test_components_works_on_relative(self): p = 'a/b/c' - a = ['a', 'b', 'c'] + a = ['a', 'b', 'c'] self.assertEqual(util.components(p), a) + class AlbumFileTest(_common.TestCase): def setUp(self): super(AlbumFileTest, self).setUp() @@ -201,13 +208,14 @@ class AlbumFileTest(_common.TestCase): self.ai.store() self.assertTrue('testotherdir' in self.i.path) + class ArtFileTest(_common.TestCase): def setUp(self): super(ArtFileTest, self).setUp() # Make library and item. self.lib = beets.library.Library(':memory:') - self.libdir = os.path.abspath(os.path.join(self.temp_dir, 'testlibdir')) + self.libdir = os.path.join(self.temp_dir, 'testlibdir') self.lib.directory = self.libdir self.i = item(self.lib) self.i.path = self.i.destination() @@ -326,7 +334,7 @@ class ArtFileTest(_common.TestCase): newart = os.path.join(self.libdir, 'newart.jpg') touch(newart) - os.chmod(newart, 0400) # read-only + os.chmod(newart, 0400) # read-only try: i2 = item() @@ -367,7 +375,7 @@ class ArtFileTest(_common.TestCase): self.assertExists(oldartpath) self.i.album = 'different_album' - self.i.album_id = None # detach from album + self.i.album_id = None # detach from album self.i.move() artpath = self.lib.albums()[0].artpath @@ -375,13 +383,14 @@ class ArtFileTest(_common.TestCase): self.assertEqual(artpath, oldartpath) self.assertExists(oldartpath) + class RemoveTest(_common.TestCase): def setUp(self): super(RemoveTest, self).setUp() # Make library and item. self.lib = beets.library.Library(':memory:') - self.libdir = os.path.abspath(os.path.join(self.temp_dir, 'testlibdir')) + self.libdir = os.path.join(self.temp_dir, 'testlibdir') self.lib.directory = self.libdir self.i = item(self.lib) self.i.path = self.i.destination() @@ -419,7 +428,7 @@ class RemoveTest(_common.TestCase): self.assertExists(self.libdir) def test_removing_item_outside_of_library_deletes_nothing(self): - self.lib.directory = os.path.abspath(os.path.join(self.temp_dir, 'xxx')) + self.lib.directory = os.path.join(self.temp_dir, 'xxx') parent = os.path.dirname(self.i.path) self.i.remove(True) self.assertExists(parent) @@ -434,6 +443,7 @@ class RemoveTest(_common.TestCase): self.i.remove(True) self.assertNotExists(parent) + # Tests that we can "delete" nonexistent files. class SoftRemoveTest(_common.TestCase): def setUp(self): @@ -452,6 +462,7 @@ class SoftRemoveTest(_common.TestCase): except OSError: self.fail('OSError when removing path') + class SafeMoveCopyTest(_common.TestCase): def setUp(self): super(SafeMoveCopyTest, self).setUp() @@ -488,6 +499,7 @@ class SafeMoveCopyTest(_common.TestCase): util.copy(self.path, self.path) self.assertExists(self.path) + class PruneTest(_common.TestCase): def setUp(self): super(PruneTest, self).setUp() @@ -507,6 +519,7 @@ class PruneTest(_common.TestCase): self.assertExists(self.base) self.assertNotExists(self.sub) + class WalkTest(_common.TestCase): def setUp(self): super(WalkTest, self).setUp() @@ -546,6 +559,7 @@ class WalkTest(_common.TestCase): self.assertEqual(res[0], (self.base, [], [])) + class UniquePathTest(_common.TestCase): def setUp(self): super(UniquePathTest, self).setUp() @@ -573,6 +587,7 @@ class UniquePathTest(_common.TestCase): path = util.unique_path(os.path.join(self.base, 'x.1.mp3')) self.assertEqual(path, os.path.join(self.base, 'x.3.mp3')) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) diff --git a/test/test_ihate.py b/test/test_ihate.py index 39441f2f0..030f5649e 100644 --- a/test/test_ihate.py +++ b/test/test_ihate.py @@ -21,11 +21,11 @@ class IHatePluginTest(unittest.TestCase): self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern)) # 1 query match. - match_pattern = ["artist:bad_artist","artist:TestArtist"] + match_pattern = ["artist:bad_artist", "artist:TestArtist"] self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern)) # 2 query matches, either should trigger. - match_pattern = ["album:test","artist:testartist"] + match_pattern = ["album:test", "artist:testartist"] self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern)) # Query is blocked by AND clause. diff --git a/test/test_keyfinder.py b/test/test_keyfinder.py index ff65a014b..5795002dc 100644 --- a/test/test_keyfinder.py +++ b/test/test_keyfinder.py @@ -18,6 +18,7 @@ from helper import TestHelper from beets.library import Item + class KeyFinderTest(unittest.TestCase, TestHelper): def setUp(self): diff --git a/test/test_lyrics.py b/test/test_lyrics.py index 4750e825f..e6e140c81 100644 --- a/test/test_lyrics.py +++ b/test/test_lyrics.py @@ -112,7 +112,7 @@ class LyricsPluginTest(unittest.TestCase): "" ) text = """Look at all the shit that i done bought her - See lyrics ain't nothin + See lyrics ain't nothin if the beat aint crackin""" self.assertEqual(lyrics.remove_credits(text), text) diff --git a/test/test_mb.py b/test/test_mb.py index 645769225..c8ffceefb 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -19,6 +19,7 @@ from _common import unittest from beets.autotag import mb from beets import config + class MBAlbumInfoTest(_common.TestCase): def _make_release(self, date_str='2009', tracks=None, track_length=None, track_artist=False): @@ -311,6 +312,7 @@ class MBAlbumInfoTest(_common.TestCase): self.assertEqual(track.artist_sort, 'TRACK ARTIST SORT NAME') self.assertEqual(track.artist_credit, 'TRACK ARTIST CREDIT') + class ParseIDTest(_common.TestCase): def test_parse_id_correct(self): id_string = "28e32c71-1450-463e-92bf-e0a46446fc11" @@ -328,6 +330,7 @@ class ParseIDTest(_common.TestCase): out = mb._parse_id(id_url) self.assertEqual(out, id_string) + class ArtistFlatteningTest(_common.TestCase): def _credit_dict(self, suffix=''): return { @@ -367,7 +370,8 @@ class ArtistFlatteningTest(_common.TestCase): def test_alias(self): credit_dict = self._credit_dict() self._add_alias(credit_dict, suffix='en', locale='en', primary=True) - self._add_alias(credit_dict, suffix='en_GB', locale='en_GB', primary=True) + self._add_alias(credit_dict, suffix='en_GB', locale='en_GB', + primary=True) self._add_alias(credit_dict, suffix='fr', locale='fr') self._add_alias(credit_dict, suffix='fr_P', locale='fr', primary=True) self._add_alias(credit_dict, suffix='pt_BR', locale='pt_BR') @@ -402,6 +406,7 @@ class ArtistFlatteningTest(_common.TestCase): flat = mb._flatten_artist_credit([credit_dict]) self.assertEqual(flat, ('ALIASfr_P', 'ALIASSORTfr_P', 'CREDIT')) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) diff --git a/test/test_mediafile.py b/test/test_mediafile.py index e2c35e491..56a7bf572 100644 --- a/test/test_mediafile.py +++ b/test/test_mediafile.py @@ -24,9 +24,8 @@ import time import _common from _common import unittest from beets.mediafile import MediaFile, MediaField, Image, \ - MP3DescStorageStyle, StorageStyle, \ - MP4StorageStyle, ASFStorageStyle, \ - ImageType + MP3DescStorageStyle, StorageStyle, MP4StorageStyle, \ + ASFStorageStyle, ImageType from beets.library import Item from beets.plugins import BeetsPlugin @@ -122,17 +121,18 @@ class ImageStructureTestMixin(ArtTestMixin): self.assertEqual(len(mediafile.images), 2) image = Image(data=self.png_data, desc='the composer', - type=ImageType.composer) + type=ImageType.composer) mediafile.images += [image] mediafile.save() mediafile = MediaFile(mediafile.path) self.assertEqual(len(mediafile.images), 3) - image = next( - (i for i in mediafile.images if i.desc == 'the composer'), None) - self.assertExtendedImageAttributes(image, - desc='the composer', type=ImageType.composer) + images = (i for i in mediafile.images if i.desc == 'the composer') + image = next(images, None) + self.assertExtendedImageAttributes( + image, desc='the composer', type=ImageType.composer + ) def assertExtendedImageAttributes(self, image, **kwargs): """Ignore extended image attributes in the base tests. @@ -152,7 +152,7 @@ class ExtendedImageStructureTestMixin(ImageStructureTestMixin): self.assertEqual(len(mediafile.images), 2) image = Image(data=self.tiff_data, desc='the composer', - type=ImageType.composer) + type=ImageType.composer) mediafile.images += [image] mediafile.save() @@ -161,9 +161,9 @@ class ExtendedImageStructureTestMixin(ImageStructureTestMixin): # WMA does not preserve the order, so we have to work around this image = filter(lambda i: i.mime_type == 'image/tiff', - mediafile.images)[0] - self.assertExtendedImageAttributes(image, - desc='the composer', type=ImageType.composer) + mediafile.images)[0] + self.assertExtendedImageAttributes( + image, desc='the composer', type=ImageType.composer) class LazySaveTestMixin(object): @@ -264,6 +264,8 @@ field_extension = MediaField( StorageStyle('customtag'), ASFStorageStyle('customtag'), ) + + class ExtendedFieldTestMixin(object): def test_extended_field_write(self): @@ -326,29 +328,29 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, """ full_initial_tags = { - 'title': u'full', - 'artist': u'the artist', - 'album': u'the album', - 'genre': u'the genre', - 'composer': u'the composer', - 'grouping': u'the grouping', - 'year': 2001, - 'month': None, - 'day': None, - 'date': datetime.date(2001, 1, 1), - 'track': 2, - 'tracktotal': 3, - 'disc': 4, - 'disctotal': 5, - 'lyrics': u'the lyrics', - 'comments': u'the comments', - 'bpm': 6, - 'comp': True, - 'mb_trackid': '8b882575-08a5-4452-a7a7-cbb8a1531f9e', - 'mb_albumid': '9e873859-8aa4-4790-b985-5a953e8ef628', - 'mb_artistid':'7cf0ea9d-86b9-4dad-ba9e-2355a64899ea', - 'art': None, - 'label': u'the label', + 'title': u'full', + 'artist': u'the artist', + 'album': u'the album', + 'genre': u'the genre', + 'composer': u'the composer', + 'grouping': u'the grouping', + 'year': 2001, + 'month': None, + 'day': None, + 'date': datetime.date(2001, 1, 1), + 'track': 2, + 'tracktotal': 3, + 'disc': 4, + 'disctotal': 5, + 'lyrics': u'the lyrics', + 'comments': u'the comments', + 'bpm': 6, + 'comp': True, + 'mb_trackid': '8b882575-08a5-4452-a7a7-cbb8a1531f9e', + 'mb_albumid': '9e873859-8aa4-4790-b985-5a953e8ef628', + 'mb_artistid': '7cf0ea9d-86b9-4dad-ba9e-2355a64899ea', + 'art': None, + 'label': u'the label', } tag_fields = [ @@ -493,11 +495,11 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, self.assertEqual(mediafile.year, 2001) self.assertEqual(mediafile.month, 1) self.assertEqual(mediafile.day, 2) - self.assertEqual(mediafile.date, datetime.date(2001,1,2)) + self.assertEqual(mediafile.date, datetime.date(2001, 1, 2)) self.assertEqual(mediafile.original_year, 1999) self.assertEqual(mediafile.original_month, 12) self.assertEqual(mediafile.original_day, 30) - self.assertEqual(mediafile.original_date, datetime.date(1999,12,30)) + self.assertEqual(mediafile.original_date, datetime.date(1999, 12, 30)) def test_write_incomplete_date_components(self): mediafile = self._mediafile_fixture('empty') @@ -510,23 +512,23 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, self.assertEqual(mediafile.year, 2001) self.assertIsNone(mediafile.month) self.assertIsNone(mediafile.day) - self.assertEqual(mediafile.date, datetime.date(2001,1,1)) + self.assertEqual(mediafile.date, datetime.date(2001, 1, 1)) def test_write_dates(self): mediafile = self._mediafile_fixture('full') - mediafile.date = datetime.date(2001,1,2) - mediafile.original_date = datetime.date(1999,12,30) + mediafile.date = datetime.date(2001, 1, 2) + mediafile.original_date = datetime.date(1999, 12, 30) mediafile.save() mediafile = MediaFile(mediafile.path) self.assertEqual(mediafile.year, 2001) self.assertEqual(mediafile.month, 1) self.assertEqual(mediafile.day, 2) - self.assertEqual(mediafile.date, datetime.date(2001,1,2)) + self.assertEqual(mediafile.date, datetime.date(2001, 1, 2)) self.assertEqual(mediafile.original_year, 1999) self.assertEqual(mediafile.original_month, 12) self.assertEqual(mediafile.original_day, 30) - self.assertEqual(mediafile.original_date, datetime.date(1999,12,30)) + self.assertEqual(mediafile.original_date, datetime.date(1999, 12, 30)) def test_write_packed(self): mediafile = self._mediafile_fixture('empty') @@ -574,7 +576,6 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, self.assertIsNotNone(getattr(mediafile, key)) for key in keys: delattr(mediafile, key) - mediafile.save() mediafile = MediaFile(mediafile.path) @@ -623,7 +624,6 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, self.assertIsNone(mediafile.date) self.assertIsNone(mediafile.year) - def assertTags(self, mediafile, tags): errors = [] for key, value in tags.items(): @@ -633,8 +633,7 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, errors.append('Tag %s does not exist' % key) else: if value2 != value: - errors.append('Tag %s: %s != %s' % - (key, value2, value)) + errors.append('Tag %s: %s != %s' % (key, value2, value)) if any(errors): errors = ['Tags did not match'] + errors self.fail('\n '.join(errors)) @@ -706,6 +705,8 @@ class MP3Test(ReadWriteTestBase, PartialTestMixin, 'bitdepth': 0, 'channels': 1, } + + class MP4Test(ReadWriteTestBase, PartialTestMixin, ImageStructureTestMixin, unittest.TestCase): extension = 'm4a' @@ -734,6 +735,8 @@ class AlacTest(ReadWriteTestBase, unittest.TestCase): 'bitdepth': 0, 'channels': 0, } + + class MusepackTest(ReadWriteTestBase, unittest.TestCase): extension = 'mpc' audio_properties = { @@ -744,6 +747,8 @@ class MusepackTest(ReadWriteTestBase, unittest.TestCase): 'bitdepth': 0, 'channels': 2, } + + class WMATest(ReadWriteTestBase, ExtendedImageStructureTestMixin, unittest.TestCase): extension = 'wma' @@ -765,6 +770,7 @@ class WMATest(ReadWriteTestBase, ExtendedImageStructureTestMixin, mediafile = MediaFile(mediafile.path) self.assertIn(mediafile.genre, [u'one', u'two']) + class OggTest(ReadWriteTestBase, ExtendedImageStructureTestMixin, unittest.TestCase): extension = 'ogg' @@ -780,7 +786,7 @@ class OggTest(ReadWriteTestBase, ExtendedImageStructureTestMixin, def test_read_date_from_year_tag(self): mediafile = self._mediafile_fixture('year') self.assertEqual(mediafile.year, 2000) - self.assertEqual(mediafile.date, datetime.date(2000,1,1)) + self.assertEqual(mediafile.date, datetime.date(2000, 1, 1)) def test_write_date_to_year_tag(self): mediafile = self._mediafile_fixture('empty') diff --git a/test/test_player.py b/test/test_player.py index 8209ee7ae..966b98dac 100644 --- a/test/test_player.py +++ b/test/test_player.py @@ -17,6 +17,7 @@ from _common import unittest from beetsplug import bpd + class CommandParseTest(unittest.TestCase): def test_no_args(self): s = ur'command' @@ -58,9 +59,9 @@ class CommandParseTest(unittest.TestCase): c = bpd.Command(s) self.assertEqual(c.args, [u'hello \ there']) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) if __name__ == '__main__': unittest.main(defaultTest='suite') - diff --git a/test/test_replaygain.py b/test/test_replaygain.py index 12678f469..bad779c69 100644 --- a/test/test_replaygain.py +++ b/test/test_replaygain.py @@ -13,15 +13,9 @@ # included in all copies or substantial portions of the Software. -import os -import shutil -from glob import glob - -import _common from _common import unittest from helper import TestHelper, has_program -from beets.library import Item, Album from beets.mediafile import MediaFile try: diff --git a/test/test_template.py b/test/test_template.py index d783b28f8..f14aed019 100644 --- a/test/test_template.py +++ b/test/test_template.py @@ -17,6 +17,7 @@ from _common import unittest from beets.util import functemplate + def _normexpr(expr): """Normalize an Expression object's parts, collapsing multiple adjacent text blocks and removing empty text blocks. Generates a @@ -38,10 +39,12 @@ def _normexpr(expr): if text: yield text + def _normparse(text): """Parse a template and then normalize the resulting Expression.""" return _normexpr(functemplate._parse(text)) + class ParseTest(unittest.TestCase): def test_empty_string(self): self.assertEqual(list(_normparse(u'')), []) @@ -139,7 +142,8 @@ class ParseTest(unittest.TestCase): self.assertEqual(list(_normparse(u'foo %bar baz')), [u'foo %bar baz']) def test_call_with_unclosed_args(self): - self.assertEqual(list(_normparse(u'foo %bar{ baz')), [u'foo %bar{ baz']) + self.assertEqual(list(_normparse(u'foo %bar{ baz')), + [u'foo %bar{ baz']) def test_call_with_unclosed_multiple_args(self): self.assertEqual(list(_normparse(u'foo %bar{bar,bar baz')), @@ -203,6 +207,7 @@ class ParseTest(unittest.TestCase): self._assert_call(arg_parts[0], u"bar", 1) self.assertEqual(list(_normexpr(arg_parts[0].args[0])), [u'baz']) + class EvalTest(unittest.TestCase): def _eval(self, template): values = { @@ -255,6 +260,7 @@ class EvalTest(unittest.TestCase): def test_function_call_with_empty_arg(self): self.assertEqual(self._eval(u"%len{}"), u"0") + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) diff --git a/test/test_the.py b/test/test_the.py index 88a72dcd6..1dba1d371 100644 --- a/test/test_the.py +++ b/test/test_the.py @@ -10,34 +10,34 @@ class ThePluginTest(_common.TestCase): def test_unthe_with_default_patterns(self): self.assertEqual(ThePlugin().unthe('', PATTERN_THE), '') - self.assertEqual(ThePlugin().unthe('The Something', PATTERN_THE), + self.assertEqual(ThePlugin().unthe('The Something', PATTERN_THE), 'Something, The') - self.assertEqual(ThePlugin().unthe('The The', PATTERN_THE), + self.assertEqual(ThePlugin().unthe('The The', PATTERN_THE), 'The, The') - self.assertEqual(ThePlugin().unthe('The The', PATTERN_THE), + self.assertEqual(ThePlugin().unthe('The The', PATTERN_THE), 'The, The') - self.assertEqual(ThePlugin().unthe('The The X', PATTERN_THE), + self.assertEqual(ThePlugin().unthe('The The X', PATTERN_THE), 'The X, The') - self.assertEqual(ThePlugin().unthe('the The', PATTERN_THE), + self.assertEqual(ThePlugin().unthe('the The', PATTERN_THE), 'The, the') - self.assertEqual(ThePlugin().unthe('Protected The', PATTERN_THE), + self.assertEqual(ThePlugin().unthe('Protected The', PATTERN_THE), 'Protected The') - self.assertEqual(ThePlugin().unthe('A Boy', PATTERN_A), + self.assertEqual(ThePlugin().unthe('A Boy', PATTERN_A), 'Boy, A') - self.assertEqual(ThePlugin().unthe('a girl', PATTERN_A), + self.assertEqual(ThePlugin().unthe('a girl', PATTERN_A), 'girl, a') - self.assertEqual(ThePlugin().unthe('An Apple', PATTERN_A), + self.assertEqual(ThePlugin().unthe('An Apple', PATTERN_A), 'Apple, An') - self.assertEqual(ThePlugin().unthe('An A Thing', PATTERN_A), + self.assertEqual(ThePlugin().unthe('An A Thing', PATTERN_A), 'A Thing, An') - self.assertEqual(ThePlugin().unthe('the An Arse', PATTERN_A), + self.assertEqual(ThePlugin().unthe('the An Arse', PATTERN_A), 'the An Arse') def test_unthe_with_strip(self): config['the']['strip'] = True - self.assertEqual(ThePlugin().unthe('The Something', PATTERN_THE), - 'Something') - self.assertEqual(ThePlugin().unthe('An A', PATTERN_A), 'A') + self.assertEqual(ThePlugin().unthe('The Something', PATTERN_THE), + 'Something') + self.assertEqual(ThePlugin().unthe('An A', PATTERN_A), 'A') def test_template_function_with_defaults(self): ThePlugin().patterns = [PATTERN_THE, PATTERN_A] @@ -48,7 +48,7 @@ class ThePluginTest(_common.TestCase): def test_custom_pattern(self): config['the']['patterns'] = [u'^test\s'] config['the']['format'] = FORMAT - self.assertEqual(ThePlugin().the_template_func('test passed'), + self.assertEqual(ThePlugin().the_template_func('test passed'), 'passed, test') def test_custom_format(self): diff --git a/test/test_vfs.py b/test/test_vfs.py index 755311beb..e31640aa2 100644 --- a/test/test_vfs.py +++ b/test/test_vfs.py @@ -18,6 +18,7 @@ from _common import unittest from beets import library from beets import vfs + class VFSTest(_common.TestCase): def setUp(self): super(VFSTest, self).setUp() @@ -37,6 +38,7 @@ class VFSTest(_common.TestCase): self.assertEqual(self.tree.dirs['albums'].dirs['the album']. files['the title'], 2) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) diff --git a/test/test_web.py b/test/test_web.py index 6cc16c81a..5aae76365 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -3,7 +3,6 @@ from _common import unittest import _common import json -import beets import beetsplug from beets.library import Item, Album beetsplug.__path__ = ['./beetsplug', '../beetsplug'] @@ -101,8 +100,6 @@ class WebPluginTest(_common.LibTestCase): self.assertEqual(response.status_code, 200) self.assertEqual(len(response.json['albums']), 2) - - def suite(): return unittest.TestLoader().loadTestsFromName(__name__) diff --git a/test/testall.py b/test/testall.py index c91deba55..70bf44f87 100755 --- a/test/testall.py +++ b/test/testall.py @@ -31,6 +31,7 @@ try: except KeyError: pass + def suite(): s = unittest.TestSuite() # Get the suite() of every module in this directory beginning with