<commit_before># This file is part of beets.
# Copyright 2014, <NAME>.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

"""Tests for the 'lastgenre' plugin."""

from _common import unittest
from beetsplug import lastgenre
from beets import config

class LastGenrePluginTest(unittest.TestCase):
    def setUp(self):
        """Set up configuration"""
        lyrics.LastGenrePlugin()

    def _setup_config(self, whitelist=set(), branches=None, count=1):
        config['lastgenre']['whitelist'] = whitelist
        if branches:
            config['lastgenre']['branches'] = branches
            config['lastgenre']['c14n'] = True
        else:
            config['lastgenre']['c14n'] = False
        config['lastgenre']['count'] = count

    def test_c14n():
        _setup_config(set('blues'),
                      [['blues'],
                       ['blues', 'country blues'],
                       ['blues', 'country blues', 'delta blues']])

        self.assertEqual(lastgenre._strings_to_genre(['delta blues']),
                         'blues')

<commit_msg>lastgenre: add tests functions<commit_after># This file is part of beets.
# Copyright 2014, <NAME>.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

"""Tests for the 'lastgenre' plugin."""

from _common import unittest
from beetsplug import lastgenre
from beets import config


class LastGenrePluginTest(unittest.TestCase):
    def setUp(self):
        """Set up configuration"""
        lastgenre.LastGenrePlugin()

    def _setup_config(self, whitelist=set(), branches=None, count=1):
        lastgenre.options['whitelist'] = whitelist
        if branches:
            lastgenre.options['branches'] = branches
            lastgenre.options['c14n'] = True
        else:
            lastgenre.options['c14n'] = False

        config['lastgenre']['count'] = count

    def test_c14n(self):
        """Resolve genres that belong to a canonicalization branch.
        """
        self._setup_config(whitelist=set(['blues']),
                           branches=[['blues'], ['blues', 'country blues'],
                                     ['blues', 'country blues',
                                      'delta blues']])

        self.assertEqual(lastgenre._strings_to_genre(['delta blues']), 'Blues')
        self.assertEqual(lastgenre._strings_to_genre(['rhytm n blues']), '')

    def test_whitelist(self):
        """Keep only genres that are in the whitelist.
        """
        self._setup_config(whitelist=set(['blues', 'rock', 'jazz']),
                           count=2)
        self.assertEqual(lastgenre._strings_to_genre(['pop', 'blues']),
                         'Blues')

    def test_count(self):
        """Keep the n first genres, as we expect them to be sorted from more to
        less popular.
        """
        self._setup_config(whitelist=set(['blues', 'rock', 'jazz']),
                           count=2)
        self.assertEqual(lastgenre._strings_to_genre(
                         ['jazz', 'pop', 'rock', 'blues']),
                         'Jazz, Rock')

    def test_count_c14n(self):
        """Keep the n first genres, after having applied c14n when necessary
        """
        self._setup_config(whitelist=set(['blues', 'rock', 'jazz']),
                           branches=[['blues'], ['blues', 'country blues']],
                           count=2)
        self.assertEqual(lastgenre._strings_to_genre(
                         ['jazz', 'pop', 'country blues', 'rock']),
                         'Jazz, Blues')


def suite():
    return unittest.TestLoader().loadTestsFromName(__name__)

if __name__ == '__main__':
    unittest.main(defaultTest='suite')
{'fraction_non_alphanumeric': 0.11452159187129551, 'fraction_numerical': 0.006138865368331922, 'mean_word_length': 2.615149196633512, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2813165', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1248, 'n_words': 406}