<commit_before>from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase

from cms.exceptions import ToolbarAlreadyRegistered, ToolbarNotRegistered
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import ToolbarPool


class TestToolbar(CMSToolbar):
    pass


class ToolbarPoolTests(TestCase):

    def setUp(self):
        self.pool = ToolbarPool()

    def test_register(self):
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)
        self.assertEqual(self.pool.toolbars, {
            'cms.toolbar_base.CMSToolbar': CMSToolbar,
            'cms.tests.toolbar_pool.TestToolbar': TestToolbar})

        self.assertRaises(ToolbarAlreadyRegistered,
                self.pool.register, TestToolbar)

    def test_register_type(self):
        self.assertRaises(ImproperlyConfigured, self.pool.register, str)
        self.assertRaises(ImproperlyConfigured, self.pool.register, object)

    def test_unregister(self):
        self.pool.register(TestToolbar)
        self.pool.unregister(TestToolbar)
        self.assertEqual(self.pool.toolbars, {})

        self.assertRaises(ToolbarNotRegistered,
                self.pool.unregister, TestToolbar)<commit_msg>Add test for toolbar_pool.toolbars sort order<commit_after>from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.utils.datastructures import SortedDict

from cms.exceptions import ToolbarAlreadyRegistered, ToolbarNotRegistered
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import ToolbarPool


class TestToolbar(CMSToolbar):
    pass


class ToolbarPoolTests(TestCase):

    def setUp(self):
        self.pool = ToolbarPool()

    def test_register(self):
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)
        self.assertEqual(self.pool.toolbars, {
            'cms.toolbar_base.CMSToolbar': CMSToolbar,
            'cms.tests.toolbar_pool.TestToolbar': TestToolbar})

        self.assertRaises(ToolbarAlreadyRegistered,
                          self.pool.register, TestToolbar)

    def test_register_type(self):
        self.assertRaises(ImproperlyConfigured, self.pool.register, str)
        self.assertRaises(ImproperlyConfigured, self.pool.register, object)

    def test_register_order(self):
        print(self.pool.toolbars)
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)

        test_toolbar = SortedDict()
        test_toolbar['cms.tests.toolbar_pool.TestToolbar'] = TestToolbar
        test_toolbar['cms.toolbar_base.CMSToolbar'] = CMSToolbar
        self.assertEqual(list(test_toolbar.keys()), list(self.pool.toolbars.keys()))

    def test_unregister(self):
        self.pool.register(TestToolbar)
        self.pool.unregister(TestToolbar)
        self.assertEqual(self.pool.toolbars, {})

        self.assertRaises(ToolbarNotRegistered,
                          self.pool.unregister, TestToolbar)
{'fraction_non_alphanumeric': 0.08754208754208755, 'fraction_numerical': 0.0, 'mean_word_length': 3.414561664190193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6927073', 'n_tokens_mistral': 873, 'n_tokens_neox': 872, 'n_words': 137}