Пример #1
0
 def setUp(self):
     conf = get_config()
     # use some default config options for these tests
     for sec, opt, val in Config.conf:
         if sec in ['genres', 'scores']:
             conf.set(sec, opt, val)
     self.taglib = TagLib(conf, WHITELIST, TAGSFILE)
Пример #2
0
 def setUp(self):
     conf = get_config()
     # use some default config options for these tests
     for sec, opt, val in Config.conf:
         if sec in ['genres', 'scores']:
             conf.set(sec, opt, val)
     self.taglib = TagLib(conf, WHITELIST, TAGSFILE)
Пример #3
0
class TestTagLib(unittest.TestCase):
    def setUp(self):
        conf = get_config()
        # use some default config options for these tests
        for sec, opt, val in Config.conf:
            if sec in ['genres', 'scores']:
                conf.set(sec, opt, val)
        self.taglib = TagLib(conf, WHITELIST, TAGSFILE)

    def test_add(self):
        tags = {
            'blues': 1,
            'pop': 1,
            'rock': 1,
            'shit': 1,
        }
        whitelisted = sum(x in WHITELIST for x in tags.iterkeys())
        good = self.taglib.add(tags, 'artist')
        self.assertEquals(whitelisted, good)

    def test_score_with_counts(self):
        tags = {'tag%s' % i: randint(1, 10) for i in range(5)}
        for score_mod in [0.5, 1, 2]:
            scored_tags = self.taglib.score(tags, score_mod)
            max_score = max(scored_tags.itervalues())
            self.assertEquals(max_score, score_mod)

    def test_score_without_counts(self):
        tags = {'tag%s' % i: 0 for i in range(5)}
        scored_tags = self.taglib.score(tags, 1)
        len_scores = len(set(scored_tags.itervalues()))
        self.assertEquals(len_scores, 1)

    def test_score_negative(self):
        """issue #7"""
        tags = {'tag%s' % i: randint(1, 10) for i in range(5)}
        tags.update({'tag5': -1})
        scored_tags = self.taglib.score(tags, 1)
        pos_scores = [x for x in scored_tags.itervalues() if x > 0]
        self.assertEquals(len(tags) - 1, len(pos_scores))

    def test_difflib_matching(self):
        tags = {
            'blues': 1,
            'klassikal': 1,
            'elektronik': 1,
            'shit': 1,
        }
        for key, match in self.taglib.difflib_matching(tags):
            print(key, match)
            self.assertIsNone(key)
            self.assertIsNone(match)

    def test_split(self):
        tags = [
            'pop/country',
            'jazz-blues',
            'alternative rock',
            'progressive rock',
            'punk-folk',
            'classical electronic reggae',
        ]
        tags_split = [
            'alternative',
            'blues',
            'classical',
            'country',
            'electronic',
            'folk',
            'jazz',
            'pop',
            'progressive',
            'reggae',
            'rock',
        ]
        for tag in tags:
            self.taglib.split(tag, 1, 'artist')
        for tag in tags_split:
            self.assertIn(tag, self.taglib.taggrps['artist'].iterkeys())

    def test_merge(self):
        self.taglib.add({'pop': 0.6}, 'artist')
        self.taglib.add({'rock': 0.3}, 'album')
        merged_tags = self.taglib.merge(False)
        self.assertIn('pop', merged_tags.iterkeys())
        self.assertIn('rock', merged_tags.iterkeys())
        self.assertEqual(2, len(merged_tags))
        # check normalized score
        self.assertEqual(1, max(merged_tags.itervalues()))

    def test_format(self):
        test_data = [
            ('nu jazz', 'Nu Jazz'),
            ('the test tag', 'The Test Tag'),
            ('edm', 'EDM'),
        ]
        for raw, done in test_data:
            self.assertEquals(done, self.taglib.format(raw))

    def test_get_genres(self):
        self.taglib.add({'pop': 1, 'rock': 0.5}, 'artist')
        self.taglib.add({'rock': 0.8, 'jazz': 0.1}, 'album')
        genres = self.taglib.get_genres(False)
        self.assertEqual(['Rock', 'Pop'], genres)

    def test_get_genres_limit(self):
        limit = 1
        self.taglib.conf.args.tag_limit = limit
        self.taglib.add({'rock': 1, 'pop': 1, 'jazz': 1}, 'album')
        self.assertEqual(limit, len(self.taglib.get_genres(False)))
Пример #4
0
class TestTagLib(unittest.TestCase):
    def setUp(self):
        conf = get_config()
        # use some default config options for these tests
        for sec, opt, val in Config.conf:
            if sec in ['genres', 'scores']:
                conf.set(sec, opt, val)
        self.taglib = TagLib(conf, WHITELIST, TAGSFILE)

    def test_add(self):
        tags = {
            'blues': 1,
            'pop': 1,
            'rock': 1,
            'shit': 1,
        }
        whitelisted = sum(x in WHITELIST for x in tags.iterkeys())
        good = self.taglib.add(tags, 'artist')
        self.assertEquals(whitelisted, good)

    def test_score_with_counts(self):
        tags = {'tag%s' % i: randint(1, 10) for i in range(5)}
        for score_mod in [0.5, 1, 2]:
            scored_tags = self.taglib.score(tags, score_mod)
            max_score = max(scored_tags.itervalues())
            self.assertEquals(max_score, score_mod)

    def test_score_without_counts(self):
        tags = {'tag%s' % i: 0 for i in range(5)}
        scored_tags = self.taglib.score(tags, 1)
        len_scores = len(set(scored_tags.itervalues()))
        self.assertEquals(len_scores, 1)

    def test_score_negative(self):
        """issue #7"""
        tags = {'tag%s' % i: randint(1, 10) for i in range(5)}
        tags.update({'tag5': -1})
        scored_tags = self.taglib.score(tags, 1)
        pos_scores = [x for x in scored_tags.itervalues() if x > 0]
        self.assertEquals(len(tags) - 1, len(pos_scores))

    def test_difflib_matching(self):
        tags = {
            'blues': 1,
            'klassikal': 1,
            'elektronik': 1,
            'shit': 1,
        }
        for key, match in self.taglib.difflib_matching(tags):
            print(key, match)
            self.assertIsNone(key)
            self.assertIsNone(match)

    def test_split(self):
        tags = [
            'pop/country',
            'jazz-blues',
            'alternative rock',
            'progressive rock',
            'punk-folk',
            'classical electronic reggae',
        ]
        tags_split = [
            'alternative',
            'blues',
            'classical',
            'country',
            'electronic',
            'folk',
            'jazz',
            'pop',
            'progressive',
            'reggae',
            'rock',
        ]
        for tag in tags:
            self.taglib.split(tag, 1, 'artist')
        for tag in tags_split:
            self.assertIn(tag, self.taglib.taggrps['artist'].iterkeys())

    def test_merge(self):
        self.taglib.add({'pop': 0.6}, 'artist')
        self.taglib.add({'rock': 0.3}, 'album')
        merged_tags = self.taglib.merge(False)
        self.assertIn('pop', merged_tags.iterkeys())
        self.assertIn('rock', merged_tags.iterkeys())
        self.assertEqual(2, len(merged_tags))
        # check normalized score
        self.assertEqual(1, max(merged_tags.itervalues()))

    def test_format(self):
        test_data = [
            ('nu jazz', 'Nu Jazz'),
            ('the test tag', 'The Test Tag'),
            ('edm', 'EDM'),
        ]
        for raw, done in test_data:
            self.assertEquals(done, self.taglib.format(raw))

    def test_get_genres(self):
        self.taglib.add({'pop': 1, 'rock': 0.5}, 'artist')
        self.taglib.add({'rock': 0.8, 'jazz': 0.1}, 'album')
        genres = self.taglib.get_genres(False)
        self.assertEqual(['Rock', 'Pop'], genres)

    def test_get_genres_limit(self):
        limit = 1
        self.taglib.conf.args.tag_limit = limit
        self.taglib.add({'rock': 1, 'pop': 1, 'jazz': 1}, 'album')
        self.assertEqual(limit, len(self.taglib.get_genres(False)))