Commits

Adrian Sampson committed 9b554ff Merge

Merge pull request #105 from samdoshi/aliases

Unit tests and bug fix for aliases (#102)

  • Participants
  • Parent commits 31b57a0, e7fa61e

Comments (0)

Files changed (2)

File beets/autotag/mb.py

     for locale in config['import']['languages'].as_str_seq():
         # Find matching aliases for this locale.
         matches = [a for a in aliases if a['locale'] == locale]
+        # Skip to the next locale if we have no matches
         if not matches:
-            return
+            continue
 
         # Find the aliases that have the primary flag set.
         primaries = [a for a in matches if 'primary' in a]

File test/test_mb.py

 """
 from _common import unittest
 from beets.autotag import mb
+from beets import config
 
 class MBAlbumInfoTest(unittest.TestCase):
     def _make_release(self, date_str='2009', tracks=None):
             'name': 'CREDIT' + suffix,
         }
 
+    def _add_alias(self, credit_dict, suffix='', locale='', primary=False):
+        alias = {
+            'alias': 'ALIAS' + suffix,
+            'locale': locale,
+            'sort-name': 'ALIASSORT' + suffix
+        }
+        if primary:
+            alias['primary'] = 'primary'
+        if 'alias-list' not in credit_dict['artist']:
+            credit_dict['artist']['alias-list'] = []
+        credit_dict['artist']['alias-list'].append(alias)
+
     def test_single_artist(self):
         a, s, c = mb._flatten_artist_credit([self._credit_dict()])
         self.assertEqual(a, 'NAME')
         self.assertEqual(s, 'SORTa AND SORTb')
         self.assertEqual(c, 'CREDITa AND CREDITb')
 
+    def test_alias(self):
+        credit_dict = self._credit_dict()
+        self._add_alias(credit_dict, suffix='en', locale='en')
+        self._add_alias(credit_dict, suffix='en_GB', locale='en_GB')
+        self._add_alias(credit_dict, suffix='fr', locale='fr')
+        self._add_alias(credit_dict, suffix='fr_P', locale='fr', primary=True)
+
+        # test no alias
+        config['import']['languages'] = ['']
+        flat = mb._flatten_artist_credit([credit_dict])
+        self.assertEqual(flat, ('NAME', 'SORT', 'CREDIT'))
+
+        # test en
+        config['import']['languages'] = ['en']
+        flat = mb._flatten_artist_credit([credit_dict])
+        self.assertEqual(flat, ('ALIASen', 'ALIASSORTen', 'CREDIT'))
+
+        # test en_GB en
+        config['import']['languages'] = ['en_GB', 'en']
+        flat = mb._flatten_artist_credit([credit_dict])
+        self.assertEqual(flat, ('ALIASen_GB', 'ALIASSORTen_GB', 'CREDIT'))
+
+        # test en en_GB
+        config['import']['languages'] = ['en', 'en_GB']
+        flat = mb._flatten_artist_credit([credit_dict])
+        self.assertEqual(flat, ('ALIASen', 'ALIASSORTen', 'CREDIT'))
+
+        # test fr primary
+        config['import']['languages'] = ['fr']
+        flat = mb._flatten_artist_credit([credit_dict])
+        self.assertEqual(flat, ('ALIASfr_P', 'ALIASSORTfr_P', 'CREDIT'))
+
 def suite():
     return unittest.TestLoader().loadTestsFromName(__name__)